2010-10-30 116 views

回答

6

你可以使用ShouldContainOnly(IEnumerable<T>)扩展方法。

所以,如果你有2个清单,listAlistB使用:

listA.ShouldContainOnly(listB) 
+0

...但检查你的对象实现'Equals' appr opriately。 Machine.Specifications查找'IComparable ','IComparable','IEquatable ',然后使用'Comparer .Default'。 – 2011-11-28 15:28:53

+0

将包括项目检查的顺序吗? – Sly 2015-11-12 09:18:30

3

如果在列表中的项目的顺序并不重要,你可以使用

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);