You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Contains.Key no longer working for IDictionary #3331
I had some tests that were checking for a key in the exception data property that have stopped working since updating the version of nunit.
Narrowing it down I believe it's because it only implements the non generic IDictionary and maybe a change has been made that hasn't taken that into account. This has stopped working since 3.11
It can be replicated fairly easily. Assert.That(new Exception().Data, Contains.Key("hello"));
Previously this would return
Expected: dictionary containing key "hello"
But was: <empty>
but now returns
System.ArgumentException : The ListDictionaryInternal value must have a ContainsKey or Contains(TKey) method.
Thanks, it is odd that this was working before. We did make changes to include Exception data in messages, but knowing the nature of that change I don't think it is related.
@stevenaw I think it makes sense to fix it, and had actually planned to look at it, but I've not had much time the last month or so. So great that you took a look at it.
Activity
rprouse commentedon Jul 30, 2019
Thanks, it is odd that this was working before. We did make changes to include Exception data in messages, but knowing the nature of that change I don't think it is related.
mikkelbu commentedon Aug 1, 2019
The regression was introduced in version 3.11, I guess in #2837 / #2994
The check only matches
ContainsKeymethod or aContainsmethod in a generic class where the type parameter is calledTKeyand where the sole parameter ofContainshave the type asTKey- see e.g. https://github.com/DaiMichael/nunit/blob/70b5915bd844cf1f08c558452e2427c66c3c68dc/src/NUnitFramework/framework/Constraints/DictionaryContainsKeyConstraint.cs#L227. There are some discussion about this choice in the issues and associated PRs.So https://referencesource.microsoft.com/#mscorlib/system/collections/listdictionaryinternal.cs,184 does not match the current implementation.
stevenaw commentedon Oct 14, 2019
Since this seems to be a regression, I figured we would want to fix it. I've made an attempt at fixing it in the linked PR.
mikkelbu commentedon Oct 14, 2019
@stevenaw I think it makes sense to fix it, and had actually planned to look at it, but I've not had much time the last month or so. So great that you took a look at it.