I'm trying to write unit tests for Powershell function which use Write-Host function.
I mocked Write-Host and trying to assert that mock has been called with a valid argument.
Mock Write-Host -Verifiable
It "Open Db connection" {
Open-Db-Connection -connectionString 'test'
Assert-MockCalled Write-Host -ParameterFilter {
$Object | Should Be "Connection to $dataSourceName-$databaseName established"
}
Assert-MockCalled Write-Host -ParameterFilter {
$Object -eq "Connection to $dataSourceName-$databaseName established"
}
}
When I'm using -eq operator id works fine, but without a good message when actual argument not matches expected. I'm trying to use Should Be construction which prints a good error message. But for me, it only works in case if actually does not match expected. and in case if they match it says that Write-Host was not called at all.
I start thinking that Should Be for some reason cannot be used inside ParameterFilter block, because outside of it it works perfectly.