We're struggling to have Pester tests fail or pass depending on the equality of objects
within an array
.
Test.ps1
#require Assert
#require Pester
$Expected = @(
[PSCustomObject]@{Name1 = 'Text1';Name2 = 'Text2'}
[PSCustomObject]@{Name1 = 'Text1';Name2 = 'Text2'}
)
$Actual = @(
[PSCustomObject]@{Name1 = 'Text1';Name2 = 'Text2'}
[PSCustomObject]@{Name1 = 'Text1';Name2 = 'Text2'}
)
Describe 'comparing arrays' {
Context 'Assert-Equivalent' {
it 'should be green' {
Assert-Equivalent -Actual $Expected -Expected $Expected
}
it 'should be green' {
Assert-Equivalent -Actual $Actual -Expected $Expected
}
it 'should be red' {
$Wrong = @(
[PSCustomObject]@{Name1 = 'Text1';Name2 = 'Text2'}
[PSCustomObject]@{Name1 = 'WROMG';Name2 = 'Text2'}
)
Assert-Equivalent -Actual $Wrong -Expected $Expected
}
}
Context 'Should be' {
it 'should be green' {
$Expected | Should -Be $Expected
}
it 'should be green' {
$Actual | Should -Be $Expected
}
it 'should be red' {
$Wrong = @(
[PSCustomObject]@{Name1 = 'Text1';Name2 = 'Text2'}
[PSCustomObject]@{Name1 = 'WROMG';Name2 = 'Text2'}
)
$Wrong | Should -Be $Expected
}
}
}
We can't seem to get this right. Are we using the wrong CmdLets? Or is there another way of checking this? Sometimes the array
is also just a property of another object. So an in depth compare would be needed.