Skip to content
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

ExcludingMissingMembers overwrites WithMapping #1828

Closed
jnyrup opened this issue Feb 28, 2022 · 0 comments · Fixed by #1838
Closed

ExcludingMissingMembers overwrites WithMapping #1828

jnyrup opened this issue Feb 28, 2022 · 0 comments · Fixed by #1838
Assignees
Labels

Comments

@jnyrup
Copy link
Member

jnyrup commented Feb 28, 2022

Description

Calling ExcludingMissingMembers/ThrowingOnMissingMembers calls ClearMatchingRules() and potentially removes an instance of MappedMemberMatchingRule.

Complete minimal example reproducing the issue

[Fact]
public void Exclusion_of_missing_members_works_with_mapping()
{
    // Arrange
    var subject = new { Property1 = 1 };

    var expectation = new { Property2 = 2, Ignore = 3 };

    // Act / Assert
    subject.Should()
        .NotBeEquivalentTo(expectation, opt => opt
            .WithMapping("Property2", "Property1")
            .ExcludingMissingMembers()
        );
}

[Fact]
public void Mapping_works_with_exclusion_of_missing_members()
{
    // Arrange
    var subject = new { Property1 = 1 };

    var expectation = new { Property2 = 2, Ignore = 3 };

    // Act / Assert
    subject.Should()
        .NotBeEquivalentTo(expectation, opt => opt
            .ExcludingMissingMembers()
            .WithMapping("Property2", "Property1")
        );
}

Expected behavior:

Both should pass

Actual behavior:

Exclusion_of_missing_members_works_with_mapping fails with

Expected subject not to be equivalent to { Property2 = 2, Ignore = 3 }, but they are.

Versions

  • Which version of Fluent Assertions are you using?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants