Add support for IImmutableDictionary and IReadOnlyDictionary#1298
Merged
jnyrup merged 1 commit intofluentassertions:developfrom Apr 5, 2020
Merged
Add support for IImmutableDictionary and IReadOnlyDictionary#1298jnyrup merged 1 commit intofluentassertions:developfrom
jnyrup merged 1 commit intofluentassertions:developfrom
Conversation
dennisdoomen
approved these changes
Apr 4, 2020
Member
dennisdoomen
left a comment
There was a problem hiding this comment.
Impressive work and lots of kudos for all the folks that contributed to this topic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR enables using
GenericDictionaryAssertionsonIReadOnlyDictionary.More precisely it enables support for any
Shouldanalysis:Added two new overloads:
The first one is picked by both:
IEnumerable<KeyValuePair<TKey, TValue>>IReadOnlyDictionary<TKey, TValue>The second overload is not picked up by anything and probably never will(?), as being an interface is regarded a better match than being generic in an interface.
Related article
Thus not sure if having the second one is better/worse that not having it.
As noted in previous discussions we cannot add
because that leads to ambiguity when writing
as it cannot tie-break picking
IReadOnlyDictionaryorIDictionary.GenericCollectionAssertionsinheritanceGenericDictionaryAssertionsnow inherits fromGenericCollectionAssertionswhere it previously inherited fromReferenceTypeAssertions.This has at least two benefits:
All
Count/Emptyassertions now comes for free.Their failure messages were slightly different, which are the changes to
GenericCollectionAssertionsand failure message assertions in existing tests.The only assertions for
IEnumerable<kvp>.Should()that might be differentare
[Not]Contain(KeyValuePair<TKey, TValue>as they are marked withnewmodifier.[Not]EqualI've made
EqualandNotEqualsuch that they do not require the subject and expectation to be the sameTCollection.So an
IDictionarycan be compared against anIReadOnlyDictionaryand vice versa.What's up with all the helper methods?
I wanted to avoid littering the calls to e.g.
GetValuein assertion bodies with type parameters.I.e. I wanted to be able to write
GetValues(Subject)instead ofGetValues<TCollection, TKey, TValue>(Subject).This way compiled and worked.
If there is a nicer way to accomplish this, I'm all eager to know.
Tests
I've added a set of tests to verify that all cases in all helper methods are hit.
I attached a debugger to verify that the expected cases were hit.
For a proper testing of this I would normally use a mock.
If we allowed to expose
internalmembers to the test project it could also be tested with the existingTrackingTestDictionaryclass.Any opinion/concerns?
A huge thanks to everyone who participated in the discussions over the years(!) on how to solve this.
@Evangelink @krajek @somewhatabstract
This fixes #568
This fixes #357
This closes #1132
This closes #963