Reputation: 24052
So I generate an empty Dictionary<string,string>
to compare to my test result, and then I do this:
Assert.AreEqual(retval, temp);
And it fails even though they contain the same exact data. I've also tried using IsTrue
like this: Assert.IsTrue(retval.Equals(temp));
and that fails too even if they are the same.
How can I compare just the elements, not the same memory location which I'm assuming it's doing?
Thanks.
Upvotes: 0
Views: 2237
Reputation: 552
Have you looked at
.NET Dictionaries have same keys and values, but aren't "equal"
Looks like a pretty complete answer.
Upvotes: 1
Reputation: 57783
You could do Assert.IsTrue(retval.SequenceEqual(temp))
, although this will also require the order of elements in the dictionaries to be the same. I'm not sure if you want your test for equality to be that strict.
See this question and its answers for ways to compare the contents of the dictionaries regardless of sequence.
Upvotes: 1