题
我应该使用断言哪种方法与两个列表包含相同的对象用MSpec?
解决方案
您可以使用ShouldContainOnly(IEnumerable<T>)
扩展方法。
所以,如果你有2个清单,listA
和listB
使用:
listA.ShouldContainOnly(listB)
其他提示
如果该项目在列表中的顺序并不重要,你可以使用
listA.ShouldContainOnly(listB); // both lists must have exactly the same items
listA.ShouldContain(listB); // listA must at least contain the items of listB
如果该项目有关的事项的顺序,你可以使用
listA.ShouldEqual(listB);
不隶属于 StackOverflow