10
我知道如何检查集合是通过一些属性下令:在NUnit的断言一个集合在同一顺序作为预期集合
Assert.That(actual, Is.Ordered.By("Foo"));
我怎么能断言实际包含的元素(1,2,5,3,4)按照特定顺序(无需编写自定义比较器)。
我知道如何检查集合是通过一些属性下令:在NUnit的断言一个集合在同一顺序作为预期集合
Assert.That(actual, Is.Ordered.By("Foo"));
我怎么能断言实际包含的元素(1,2,5,3,4)按照特定顺序(无需编写自定义比较器)。
使用
CollectionAssert.AreEqual(expectedIEnumerable, actualIEnumerable);
这将检查的项目是相同的,以相同的顺序。
我很确定,当你使用集合上的Assert.That时,你会得到集合断言功能。所以,你可以说这样的东西
Assert.That(collection, Is.EqualTo(expectedCollection)); // Same order
或
Assert.That(collection, Is.EquivalentTo(expectedCollection)); // Same item count
以及类似的东西
Assert.That(collection, Has.Count.EqualTo(expectedSize));
关键字打开你到这是特定于收集断言的东西了,而真的很有用。
谢谢,忘了CollectionAssert – ripper234 2009-06-09 16:04:42
因为有了搜索引擎,所以在Google上搜索引起我更懒惰。 – ripper234 2009-06-09 16:05:18
没问题,只是显示它是多么有用:) – 2009-06-10 08:51:24