在 Pester 中测试集合的相等性或等价性

Cub*_*anX 5 powershell pester

在 nUnit 中,我们可以这样做:

Expect(actualColleciton, EquivalentTo(expectedCollection));
Run Code Online (Sandbox Code Playgroud)

Expect(actualCollection, EqualTo(expectedCollection));
Run Code Online (Sandbox Code Playgroud)

在 Pester 中是否有等价物?

我知道我能做到

$actualCollection | Should Be $expectedCollection
Run Code Online (Sandbox Code Playgroud)

但它的行为并不像您期望的那样。

我使用正确的语法吗?

Kor*_*ill 4

我猜测您想要 \xc2\xa0 比较集合的内容,而不是集合的指针/地址。

\n\n

我认为您可以从以下内容中获得启发:

\n\n
$a1=@(1,2,3,4,5)\n$b1=@(1,2,3,4,5,6)\n$ret = (Compare-Object $a1 $b1).InputObject\n\nif ($ret)\n{\n"different"\n}\nelse\n{\n"same"\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

做类似的事情:

\n\n
$ret = (Compare-Object $actualCollection $expectedCollection).InputObject\n$ret | Should Be\xc2\xa0$null \n
Run Code Online (Sandbox Code Playgroud)\n\n

其中 $null 表示列表是相同的。

\n