是否有類似於CollectionAssert.AreEquivalent()與嵌套集合一起工作?NUnit嵌套收集比較
下面的代碼...
CollectionAssert.AreEquivalent (
new Dictionary<int, Dictionary<int, string>>
{
{ 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } },
{ 2, new Dictionary < int, string > { { 20, "eggs" }, { 21, "eels" } } },
{ 3, new Dictionary < int, string > { { 30, "hovercraft" } } }
},
new Dictionary<int, Dictionary<int, string>>
{
{ 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } },
{ 2, new Dictionary < int, string > { { 20, "eggs" }, { 21, "eels" } } },
{ 3, new Dictionary < int, string > { { 30, "hovercraft" } } }
});
拋出該異常...
Expected: equivalent to
< [1, System.Collections.Generic.Dictionary`2[System.Int32,System.String]],
[2, System.Collections.Generic.Dictionary`2[System.Int32,System.String]],
[3, System.Collections.Generic.Dictionary`2[System.Int32,System.String]] >
But was:
< [1, System.Collections.Generic.Dictionary`2[System.Int32,System.String]],
[2, System.Collections.Generic.Dictionary`2[System.Int32,System.String]],
[3, System.Collections.Generic.Dictionary`2[System.Int32,System.String]] >
下斷言通行證:
CollectionAssert.AreEquivalent (
new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } },
new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } });
如果我更改了預期的集合,assert會在消息中引發兩個集合的全部內容的異常:
Expected: equivalent to < [10, foo], [11, bar], [12, spam] >
But was: < [10, foo], [11, bar], [12, eggs] >
我正在使用NUnit 2.4.7.0。
類似的問題:http://stackoverflow.com/questions/4185164/recursive-assert-on-collection – 2013-11-21 22:07:07