Search code examples
unit-testingtestingfluent-assertions

Fluent Assertions how to Exclude parameters with generic object


I have this generic method for a test class that I want to exclude some common parameters between few entities.

private static bool IsEquivalentTo(object request, object expectedRequest)
{
    request.Should().BeEquivalentTo(expectedRequest, config => config.Excluding(c => c.SelectedMemberPath.EndsWith("Id"))
        .Excluding(c => c.SelectedMemberPath.EndsWith("Date"))
        .Excluding(c => c.SelectedMemberPath.EndsWith("Equipment"))
        .Excluding(c => c.SelectedMemberPath.EndsWith("Partners"))
        .Excluding(c => c.SelectedMemberPath.StartsWith("Warranty"))
    );
    return true;
}

Since the last versions, this SelectedMemberPath is deprecated. Did someone find a solution for generic objects with the latest version?

Thanks!


Solution

  • SelectedMemberPath has been replaced by Path in version 6.0:

    request.Should().BeEquivalentTo(expectedRequest, config => config
        .Excluding(c => c.Path.EndsWith("Id"))
        .Excluding(c => c.Path.EndsWith("Date"))
        .Excluding(c => c.Path.EndsWith("Equipment"))
        .Excluding(c => c.Path.EndsWith("Partners"))
        .Excluding(c => c.Path.StartsWith("Warranty")));