Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test a collection for equality or equivalence in Pester

Tags:

In nUnit, we can do something like this:

Expect(actualColleciton, EquivalentTo(expectedCollection));

and

Expect(actualCollection, EqualTo(expectedCollection));

Is there an equivalent in Pester?

I know I can do

$actualCollection | Should Be $expectedCollection

but it does NOT behave as you would expect.

Am I using the right syntax?

like image 996
CubanX Avatar asked Jan 04 '17 16:01

CubanX


1 Answers

I am guessing that you want to compare the contents of your collection, not the pointer/address to the collection.

I think you could inspire from something like:

$a1=@(1,2,3,4,5)
$b1=@(1,2,3,4,5,6)
$ret = (Compare-Object $a1 $b1).InputObject

if ($ret)
{
"different"
}
else
{
"same"
}

to do something like:

$ret = (Compare-Object $actualCollection $expectedCollection).InputObject
$ret | Should Be $null 

where $null indicates the lists are the same.

like image 102
Kory Gill Avatar answered Sep 24 '22 10:09

Kory Gill