Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit: Dictionary Assert

Tags:

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?

like image 351
Graviton Avatar asked Oct 30 '09 10:10

Graviton


1 Answers

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

like image 122
adrianbanks Avatar answered Oct 31 '22 08:10

adrianbanks