NUnit嵌套集合比较

是否有类似于CollectionAssert.AreEquivalent()的东西适用于嵌套集合?

以下代码……

CollectionAssert.AreEquivalent ( new Dictionary<int, Dictionary> { { 1, new Dictionary  { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, { 2, new Dictionary  { { 20, "eggs" }, { 21, "eels" } } }, { 3, new Dictionary  { { 30, "hovercraft" } } } }, new Dictionary<int, Dictionary> { { 1, new Dictionary  { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, { 2, new Dictionary  { { 20, "eggs" }, { 21, "eels" } } }, { 3, new Dictionary  { { 30, "hovercraft" } } } } ); 

抛出这个exception……

 Expected: equivalent to  But was:  

以下断言传递:

 CollectionAssert.AreEquivalent ( new Dictionary  { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } }, new Dictionary  { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } ); 

如果我对预期的集合进行了更改,则assert会在消息中抛出两个集合的全部内容的exception:

 Expected: equivalent to  But was:  

我正在使用NUnit 2.4.7.0。

你需要自己编写。 但是,如果是我,我会尝试以不同的方式编写我的断言,这样如果两个列表中存在差异,则更明显的原因/错误。

一个老问题,但是有人刚刚在nunit-discuss上发布了一个链接…

失败的原因是所使用的NUnit版本不支持两个字典之间的相等比较,而是支持对象比较。 最近的版本不会有这个问题。