Do you know how I can Assert two dictionaries of type
Dictionary<string,List<string>>
in my Unit test project?
I tried with CollectionsAssert but it didn' work for me.I guess that it takes to simple Dictionaries as parameters(e.g. Dictionary<string,string>
).I guess that the problem for me comes from the second parameter of the dictionary.Do you know how I can assert those two dictionaries?
to state with assurance, confidence, or force; state strongly or positively; affirm; aver: He asserted his innocence of the crime. to maintain or defend (claims, rights, etc.). to state as having existence; affirm; postulate: to assert a first cause as necessary.
Assertions replace us humans in checking that the software does what it should. They express the requirements that the unit under test is expected to meet. Assert the exact desired behavior; avoid overly precise or overly loose conditions.
The Assert section verifies that the action of the method under test behaves as expected. For . NET, methods in the Assert class are often used for verification.
One of the ways that would give you a good error message:
public string ToAssertableString(IDictionary<string,List<string>> dictionary) {
var pairStrings = dictionary.OrderBy(p => p.Key)
.Select(p => p.Key + ": " + string.Join(", ", p.Value));
return string.Join("; ", pairStrings);
}
// ...
Assert.AreEqual(ToAssertableString(dictionary1), ToAssertableString(dictionary2));
using Linq:
Dictionary.All(e => AnotherDictionary.Contains(e))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With