NUnit:字典Assert [英] NUnit: Dictionary Assert

查看:117
本文介绍了NUnit:字典Assert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个一个线程,在NUnit中,断言两个字典是否相同。即,我想要一个简洁的版本的代码:

I want a one liner, in NUnit, that asserts whether two dictionary are the same. i.e., I want a concise version of the below code:

public static void DictionaryAssert<T, U>(Dictionary<T, U> dictionaryResult, Dictionary<T, U> expectedResult)
{
    Assert.AreEqual(dictionaryResult.Count, expectedResult.Count);
    foreach (var aKey in expectedResult.Keys)
    {
        Assert.AreEqual(expectedResult[aKey], dictionaryResult[aKey]);
    }
}

当然不是那么困难,但我可以没有找到参考,任何想法?

Surely it isn't so difficult, but I can't find the reference, any idea?

推荐答案

看看 CollectionAssert.AreEquivalent 。这将表明两个词典具有相同的内容,但不一定相同。

Have a look at CollectionAssert.AreEquivalent. This will assert that the two dictionaries have the same contents, but are not necessarily the same instance.

这篇关于NUnit:字典Assert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆