I would like to pass the key/values of a PowerShell hash to a Pester unit test, via the TestCases parameter:
BeforeAll {
$Expected = @{
Address1='Address1'
Address2='Address2'
City='City'
RegionCode='RegionCode'
PostalCode='PostalCode'
}
}
BeforeEach {
Mock Invoke-SqlCmd
Invoke-MyFunction @Expected
}
It "sets the column '<Name>' with the value '<Value>'" -TestCases ( $Optional.GetEnumerator() | ForEach-Object { @{Name=$_.Key; Value=$_.Value} } ) {
param($Name, $Value)
$Test = "*{0}='{1}'*" -f $Name, $Value
Assert-MockCalled Invoke-Sqlcmd -ParameterFilter {
$Query -like $Test
}
}
But can't seem to get the hash's properties 'shaped' correctly to get the tests to work correctly.