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