NUnit的:字典断言 [英] NUnit: Dictionary Assert

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

问题描述

我要的单行,在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的:字典断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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