-
-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IDictionary.ContainsKey assertion case sensitivity issue. #60
Comments
Hmm, it seems we're not relying on the dictionary's own equality algorithms then... |
I took a quick look at the code and it seems that indeed the dictionary's EqualityComparer is not used. |
I'm trying to fix it myself, but it's not possible to retrieve the Comparer from an IDictionary<K,V>. GenericDictionaryAssertions.cs line 334. var missingKeys = expectedKeys.Except(Subject.Keys); could become var missingKeys = expectedKeys.Except(Subject.Keys); var dictionarySubject = Subject as Dictionary<TKey, TValue>; But this solves only the Dictionary problem. |
Reflection on Subject.GetType() and check for a public property of type IEqualityComparer of TKey ? |
GenericDictionaryAssertions.cs line 334. var missingKeys = expectedKeys.Except(Subject.Keys); becomes: var missingKeys = expectedKeys.Except(Subject.Keys); var comparerPropertyInfo = Subject.GetType().GetProperties(BindingFlags.Public) if(comparerPropertyInfo != null) Do you agree? |
Still no good for ConcurrentDictionary because that one does not expose the IEqualityComparer publicly. Would need to look for private fields of that type also. Pfiu.... |
Maybe we should just rewrite that code to use the ContainsKey() method of the dictionary. That'll use whatever the dictionary uses internally. |
Ahaaa, indeed. var missingKeys = expectedKeys.Except(Subject.Keys); This is the obvious way. What was I thinking!?! |
Don't worry. I'm looking at it from a large distance so my mind is not clouded by the interiors of a dictionary :-) |
Fixed by pull request #61. |
[TestMethod]
public void ReproTest()
{
IDictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{"name", "name description"}
};
The text was updated successfully, but these errors were encountered: