Skip to content

ExcludingMissingMembers overwrites WithMapping #1828

@jnyrup

Description

@jnyrup

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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions