How can I write a unit test such that the following two objects are considered equal? And in general how can I ensure collections nested arbitrarily deeply are compared against counterpart via their matching index location (Lists) and matching key (Dictionaries)? I attempted the following with the Fluent Assertions library but received the following error.
List<Dictionary<List<string>, string>> list1 = new(){
new (){{new (){"a"}, "aaa"}, {new (){"z"}, "zzz"}},
new (){{new (){"b"}, "bbb"}},
new (){{new (){"c"}, "ccc"}}
};
List<Dictionary<List<string>, string>> list2 = new(){
new (){{new (){"a"}, "aaa"}, {new (){"z"}, "zzz"}},
new (){{new (){"b"}, "bbb"}},
new (){{new (){"c"}, "ccc"}}
};
list1.Should().BeEquivalentTo(list2);
Unhandled exception. FluentAssertions.Execution.AssertionFailedException: Expected list1[0] to be a dictionary with 2 item(s), but it misses key(s) {{"a"}, {"z"}} and has additional key(s) {{"b"}}
Expected list1[1] to contain key {"b"}.
Expected list1[2] to contain key {"c"}.
With configuration:
- Use declared types and members
- Compare enums by value
- Compare tuples by their properties
- Compare anonymous types by their properties
- Compare records by their members
- Include non-browsable members
- Include all non-private properties
- Include all non-private fields
- Match member by name (or throw)
- Be strict about the order of items in byte arrays
- Without automatic conversion.