-
Notifications
You must be signed in to change notification settings - Fork 731
Add For/Exclude to allow exclusion of members inside a collection
#1782
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
Conversation
…ested in collections.
ThenExcluding to allow exclusion of members inside a collection
|
@dennisdoomen I still have to do the release notes, however, you can already have a look at the |
dennisdoomen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend waiting with the rebase until #1789 is merged because it requires moving the tests to a new file.
Src/FluentAssertions/Equivalency/EquivalencyAssertionOptions.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Equivalency/EquivalencyAssertionOptionsBuilder.cs
Outdated
Show resolved
Hide resolved
|
|
||
| public void ExtendPath(MemberPath nextPath) | ||
| { | ||
| memberToExclude = memberToExclude.Extend(nextPath, "[*]"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 To align with the new WithMapping options, I think we should use [] for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see this comment #1782 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 🙂
Tests/FluentAssertions.Specs/Equivalency/CollectionEquivalencySpecs.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Specs/Equivalency/CollectionEquivalencySpecs.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Specs/Equivalency/CollectionEquivalencySpecs.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Specs/Equivalency/CollectionEquivalencySpecs.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Specs/Equivalency/CollectionEquivalencySpecs.cs
Outdated
Show resolved
Hide resolved
|
Hi, sorry I was offline for a few days, looking forward to fix the issues next week :) |
|
Updated the documentation and release notes, ran AcceptApiChanges.ps1 :) |
Src/FluentAssertions/Equivalency/EquivalencyAssertionOptions.cs
Outdated
Show resolved
Hide resolved
Made MemberPath and ExcludeMemberByPathSelectionRule extendible, added * as index qualifier, added MemberPathSegmentEqualityComparer to match MemberPath segments and respect * as index qualifier
* Added a function SetSelectedPath * Rename EquivalencyAssertionOptionsBuilder to NestedExclusionOptionBuilder * Renamed Extend* methods to Combine* * Nested ThenExcluding test cases in a nested class * Added Act/Assert comments * Renamed tests * Removed not important property Text from test data * Drop Action and NotThrow
f198efd to
6fffb89
Compare
jnyrup
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to play a bit with this, but encountered something that seems a bit non-intuitive to me.
This passes as Collection is excluded from the equivalence
var subject = new { Member = "1", Collection = new[] { new { First = "A", Second = "B" } } };
var expected = new { Member = "1", Collection = new[] { new { First = "C", Second = "D" } } };
subject.Should().BeEquivalentTo(expected, opt => opt
.Excluding(e => e.Collection));Adding .ThenExcluding(e => e.Second) makes it fail as now only Collection.Second is excluded.
var subject = new { Member = "1", Collection = new[] { new { First = "A", Second = "B" } } };
var expected = new { Member = "1", Collection = new[] { new { First = "C", Second = "D" } } };
subject.Should().BeEquivalentTo(expected, opt => opt
.Excluding(e => e.Collection).ThenExcluding(e => e.Second));So the equivalency engine in fact includes Collection except its property Second.
I don't think the analogy of Include and ThenInclude from EF is completely translatable and invertible to Exclude and ThenExclude.
With ThenInclude you include something extra in addition to what's being included by Include.
If you have excluded something with Exclude, there's nothing left for ThenExclude to exclude.
I think e.g. combining Including with ThenExcluding comes closer to what's happening.
subject.Should().BeEquivalentTo(expected, opt => opt
.Including(e => e.Collection).ThenExcluding(e => e.Second));
Src/FluentAssertions/Equivalency/NestedExclusionOptionBuilder.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Common/MemberPathSegmentEqualityComparer.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Common/MemberPathSegmentEqualityComparer.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Equivalency/NestedExclusionOptionBuilder.cs
Outdated
Show resolved
Hide resolved
|
I see that |
Co-authored-by: Jonas Nyrup <jnyrup@users.noreply.github.com>
Co-authored-by: Jonas Nyrup <jnyrup@users.noreply.github.com>
Closes #1771
IMPORTANT
AcceptApiChanges.ps1/AcceptApiChanges.sh.