I have 2 dictionaries and I would expect the contents not to be equivalent as the dictionary contains values of different types. However the following test passes
[Scenario]
public void DictionariesWithDifferentTypesShouldBeEquivalent(
Dictionary<string, object> firstDictionary,
Dictionary<string, object> secondDictionary)
{
"Given a dictionary"
.f(() => firstDictionary = new Dictionary<string, object>
{
{ "latency", 0 },
{ "errorMessages", new string[0] },
{ "lastChanged", new DateTime(635272310930829706) },
{ "query", new string[0] },
{ "items", new string[] { "foo", "bar" } },
{ "name", "Bob" },
{ "number", 3 },
{ "updateInterval", 10 },
});
"And a second dictionary with same values but of differing types"
.f(() => secondDictionary = new Dictionary<string, object>
{
{ "latency", 0L },
{ "errorMessages", new object[0] },
{ "lastChanged", new DateTime(635272310930829706) },
{ "query", new string[0] },
{ "items", new string[] { "bar", "foo" } },
{ "name", "Bob" },
{ "number", 3 },
{ "updateInterval", "10" },
});
"When I check for equivalency"
.f(() => { });
"Then the dictionaries should be equivalent"
.f(() => firstDictionary.ShouldBeEquivalentTo(secondDictionary));
}
If this is the expected behaviour how can I set up a fluent assertions rule to check that the type matches?
I have investigated using both a MatchingRule and an AssertionRule but in both cases I dont seem to have access to the original types of the subject and expected. It appears the the subject has already been converted to the type of the expected. I.e in the exapmle above updateInterval in the first dictionary would already have been converted to a string for comparison with the second dictionary.
Thanks for the help,
Rachael