Add For/Exclude to allow exclusion of members inside a collection#1782
Add For/Exclude to allow exclusion of members inside a collection#1782dennisdoomen merged 25 commits intofluentassertions:developfrom
For/Exclude to allow exclusion of members inside a collection#1782Conversation
…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.
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.
🤔 To align with the new WithMapping options, I think we should use [] for that.
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.
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.