Mik*_*att 9 c# collections nunit dictionary assert
是否有类似于CollectionAssert.AreEquivalent()的东西,它适用于嵌套集合?
以下代码......
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" } } }
} );
Run Code Online (Sandbox Code Playgroud)
抛出这个异常......
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]] >
Run Code Online (Sandbox Code Playgroud)
以下断言传递:
CollectionAssert.AreEquivalent (
new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } },
new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } );
Run Code Online (Sandbox Code Playgroud)
如果我对预期集合进行了更改,则assert会在消息中抛出两个集合的全部内容的异常:
Expected: equivalent to < [10, foo], [11, bar], [12, spam] >
But was: < [10, foo], [11, bar], [12, eggs] >
Run Code Online (Sandbox Code Playgroud)
我正在使用NUnit 2.4.7.0.