-
Notifications
You must be signed in to change notification settings - Fork 32
Implemented ExcludingMembersNamed #183
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
base: main
Are you sure you want to change the base?
Implemented ExcludingMembersNamed #183
Conversation
4784764
to
e9af95a
Compare
Thank you for your contribution! 🎉 Out of curiosity: The same as proposed as in FA? |
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.
Nice work
Just one small suggestion from my side
Src/AwesomeAssertions/Equivalency/Selection/ExcludeMemberByNameSelectionRule.cs
Outdated
Show resolved
Hide resolved
Ah yes.. just forgot: also please take care of the release notes, api snapshots and (if applicable) the docs for this change. |
Src/AwesomeAssertions/Equivalency/SelfReferenceEquivalencyOptions.cs
Outdated
Show resolved
Hide resolved
Src/AwesomeAssertions/Equivalency/SelfReferenceEquivalencyOptions.cs
Outdated
Show resolved
Hide resolved
Add
followed by the changes to
I would add an example here: AwesomeAssertions/docs/_pages/objectgraphs.md Line 168 in aaa75a2
|
/// <summary> | ||
/// Selection rule that removes a particular member from the structural comparison if its name matches the specified criteria. | ||
/// </summary> | ||
internal class ExcludeMemberByNameSelectionRule : IMemberSelectionRule |
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.
e9af95a
to
4bc0f8d
Compare
4bc0f8d
to
fc2c7a5
Compare
fc2c7a5
to
4c1e44e
Compare
Tests/AwesomeAssertions.Equivalency.Specs/SelectionRulesSpecs.Excluding.cs
Show resolved
Hide resolved
Src/AwesomeAssertions/Equivalency/Selection/ExcludeMemberByNameSelectionRule.cs
Show resolved
Hide resolved
Tests/AwesomeAssertions.Equivalency.Specs/SelectionRulesSpecs.Excluding.cs
Show resolved
Hide resolved
4c1e44e
to
27c9a7d
Compare
27c9a7d
to
56580c8
Compare
Src/AwesomeAssertions/Equivalency/Selection/ExcludeMemberByNameSelectionRule.cs
Show resolved
Hide resolved
The discussion about |
|
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.
Just a few notes which I had missed previously
.ExcludingMembersNamed("Name")); | ||
|
||
// Assert | ||
act.Should().NotThrow(); |
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.
We usually don't assert that something which shouldn't throw to NotThrow
, because when it fails it fails anyways
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.
So this test would become
[Fact]
public void A_member_excluded_by_name_is_ignored()
{
// Arrange
var subject = new
{
Id = 1,
Name = "John",
Age = 13
};
var customer = new
{
Id = 1,
Name = "Jack",
Age = 13
};
// Act / Assert
subject.Should().BeEquivalentTo(customer, options => options
.ExcludingMembersNamed("Name"));
}
But this test isn't necessary at all, because it is a duplicate of When_excluding_member_names_it_should_pass_if_only_the_excluded_members_are_different
.
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.
Correct
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.
@IT-VBFK We actually have tests which use Should().NotThrow()
. I guess those are older ones. Since we agree here, I'll change those tests to match our preferences.
// Assert | ||
act.Should().Throw<ArgumentException>() | ||
.WithParameterName("memberNames") | ||
.WithMessage("At least one member name must be specified.\nParameter name: memberNames"); |
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.
Just assert the shape of the message will do, like:
.WithMessage("At least one member name must be specified.\nParameter name: memberNames"); | |
.WithMessage("*one member*must be specified*memberNames*"); |
// Assert | ||
act.Should().Throw<ArgumentException>() | ||
.WithParameterName("memberNames") | ||
.WithMessage("Collection contains a null or empty value\nParameter name: memberNames"); |
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.
Same as above
@@ -130,6 +130,12 @@ orderDto.Should().BeEquivalentTo(order, options => | |||
options.Excluding(o => o.Products[1].Status)); | |||
``` | |||
|
|||
You can also exclude all members with of a specific name: |
There was a problem hiding this comment.
Choose a reas F438 on for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also exclude all members with of a specific name: | |
You can also exclude all members with of a specific name anywhere in the object graph: |
.ExcludingMembersNamed("Name")); | ||
|
||
// Assert | ||
act.Should().NotThrow(); |
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.
So this test would become
[Fact]
public void A_member_excluded_by_name_is_ignored()
{
// Arrange
var subject = new
{
Id = 1,
Name = "John",
Age = 13
};
var customer = new
{
Id = 1,
Name = "Jack",
Age = 13
};
// Act / Assert
subject.Should().BeEquivalentTo(customer, options => options
.ExcludingMembersNamed("Name"));
}
But this test isn't necessary at all, because it is a duplicate of When_excluding_member_names_it_should_pass_if_only_the_excluded_members_are_different
.
} | ||
|
||
[Fact] | ||
public void When_an_empty_or_null_member_name_is_passed_in_memeber_names_parameter_it_should_throw() |
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.
typo: _member_names_
(same in other method names)
Field2 = "ipsum" | ||
}; | ||
|
||
// Act |
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.
// Act / Assert
class1.Should().BeEquivalentTo(class2,
opts => opts.ExcludingMembersNamed("Field3", "Property1"));
## Unreleased | ||
|
||
### What's new | ||
* Add new assertions for strings: `[Not]BeParsableInto` - [#185](https://github.com/AwesomeAssertions/AwesomeAssertions/pull/185) | ||
|
||
### Improvements | ||
* Add `ExcludingMembersNamed` to `BeEquivalentTo` which enables excluding members with specified name - [#183](https://github.com/AwesomeAssertions/AwesomeAssertions/pull/183) |
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 would move that to What's new
, sorry for the wrong proposal.
Tests/AwesomeAssertions.Equivalency.Specs/SelectionRulesSpecs.Excluding.cs
Show resolved
Hide resolved
@weitzhandler @cbersch Are there any undiscussed things left, or can we move on? |
For me only the unresolved conversations, with minor changes in tests. |
Fixes #182
IMPORTANT
./build.sh --target spellcheck
or.\build.ps1 --target spellcheck
before pushing and check the good outcome