I'm trying to compare 2 objects expectedItems and resultItems of type IEnumerable<IDictionary<string, object>>
but haven't been able to do much with it.
Also, one dictionary is initialised in the code, and the other one is built from a JSON response from an external API. Since, JSON doesn't really care about the order of the properties within the object, a SequenceEquals
is ruled out.
I do have two equal objects and all of these understated methods are failing,
First,
CollectionAssert.AreEqual(expectedItems, resultItems)
Second,
var expectedItems = entries.Select(e => e.Serialize()).ToList();
resultItems.Zip(expectedItems,(objects, dictionary) =>
objects.OrderBy(pair =>pair.Key).SequenceEqual(dictionary.OrderBy(pair => pair.Key)))
.Should()
.NotContain(false);
The objects (as far as I see) are equal.
Any thing that I can try, or anything that I am currently doing wrong?
EDIT
The API trims the tick count from the timestamp that's why the failure. How can I trim the timestamp in the expectedItems dictionary and then compare? So, the collections have to be same and the comparison for timestamp needs to be overridden. Anyone?