Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two lists with MSpec

Tags:

c#

tdd

bdd

mspec

Which method should I use to assert that two lists contains the same objects with MSpec?

like image 627
W3Max Avatar asked Oct 30 '10 00:10

W3Max


2 Answers

You could use the ShouldContainOnly(IEnumerable<T>) extension method.

So if you have 2 lists, listA and listB use:

listA.ShouldContainOnly(listB)
like image 186
Sergi Papaseit Avatar answered Oct 04 '22 06:10

Sergi Papaseit


If the order of the items in the list doesn't matter, you would use

listA.ShouldContainOnly(listB); // both lists must have exactly the same items
listA.ShouldContain(listB);     // listA must at least contain the items of listB

If the order of the items matters, you can use

listA.ShouldEqual(listB);
like image 44
bitbonk Avatar answered Oct 04 '22 07:10

bitbonk