Skip to content

Conversation

@rubenrorije
Copy link
Contributor

@rubenrorije rubenrorije commented Jan 12, 2020

See #1232.

I noticed in the source code that GenericDictionaryAssertions uses intersect to compare the keys from the dictionary and the unexpected keys, which does not use the equality comparer of the dictionary. The dual ContainKeys implementation as well as the other methods all use the ContainsKey on the dictionary which is correct.

To illustrate the issue I added two unit tests and changed the implementation in the pull request.

I also updated the xml documentation of all (Not)ContainKey(s) to reflect the code. The documentation was saying that the keys were compared using object.Equals which is not the case in the code.

@rubenrorije rubenrorije changed the title Dictionary assertions does not use dictionary comparer in NotContainKeys #1232 Dictionary assertions does not use dictionary comparer in NotContainKeys Jan 12, 2020
@dennisdoomen dennisdoomen changed the title Dictionary assertions does not use dictionary comparer in NotContainKeys Dictionary assertions do not always use the dictionary's comparer Jan 12, 2020
@dennisdoomen dennisdoomen added this to the 6.0 milestone Jan 12, 2020
@jnyrup
Copy link
Member

jnyrup commented Jan 13, 2020

Looks good!
Could I ask you to update the documentation for the other methods that still mention Keys being compared using object.Equals?

}

IEnumerable<TKey> foundKeys = unexpectedKeys.Intersect(Subject.Keys);
IEnumerable<TKey> foundKeys = unexpected.Where(key => Subject.ContainsKey(key));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this "bug" also affect the other methods in this class?

@dennisdoomen
Copy link
Member

@rubenrorije are you still around?

@rubenrorije
Copy link
Contributor Author

Sorry, I had other priorities so did not have time/mental bandwith to look at this earlier. I updated the xml documentation to reflect the code better.

As far as I can see the only other method that does not use the keycomparer of the dictionary is the Equal method. I did not change the implementation because I am not sure what the intended behaviour should be in some situations.
When you for instance want to check a case insensitive dictionary but as expected give a case sensitive dictionary, what should be the expected behaviour?

Copy link
Member

@jnyrup jnyrup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with leaving Equal untouched.

@dennisdoomen
Copy link
Member

One more thing. Could you also add a row to the https://github.com/fluentassertions/fluentassertions/blob/develop/docs/_pages/releases.md#600?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dictionary assertions do not use the equality comparer of the dictionary involved

3 participants