Skip to content

[API Proposal]: ExcludingMemberNames shortcut for BeEquivalentTo #3052

@weitzhandler

Description

@weitzhandler

Background and motivation

To globally exclude member names from an equivalency assertion of a complex graph, one can use the IMemberInfo overload as follows:

var ignoredPropertyNames = new[] { "Parent", "Children" };
actual.Should().BeEquivalentTo(expected, config => config
    .Excluding((IMemberInfo member) => ignoredPropertyNames.Contains(member.Name)));

Please add a shortcut method that enables easily adding a list of properties to be excluded throughout the graph regardless of the type they belong to.

API Proposal

public abstract class SelfReferenceEquivalencyOptions<TSelf> : IEquivalencyOptions
{
    public TSelf ExcludingMemberNames(params IEnumerable<string> excludedMemberNames) =>
        Excluding((IMemberInfo member) => excludedMemberNames.Contains(member.Name));
}

API Usage

actual.Should().BeEquivalentTo(expected, options => options.ExcludingMemberNames("Parent", "Children"));

Alternative Designs

No response

Risks

No response

Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?

No

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions