Skip to content

Be().Equal() for Dictionary with List<> as value fails #1734

Answered by dennisdoomen
Ed-Pavlov asked this question in Q&A
Discussion options

You must be logged in to vote

This is by design. Equal on a collection will ensure all items in one collection appear in the same order as the other collection. It uses the item's Equals implementation for the comparison.

Equal on a dictionary will ensure that each key exists in the other dictionary and that their value match. A List<T> is a reference type, so by definition, they will never by "equal". If you want to do a deep comparison, use BeEquivalentTo.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Ed-Pavlov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1733 on November 06, 2021 14:19.