objects
我们正在努力让 Pester 测试失败或通过,具体取决于array
.
测试.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
}
}
}
我们似乎无法做到这一点。我们是否使用了错误的 CmdLets?还是有另一种检查方法?有时array
也只是另一个对象的属性。因此需要进行深入比较。