Skip to content

Fluent Syntax for WithoutMatchingRules and WithoutSelectionRules #2455

@vbreuss

Description

@vbreuss

Background and motivation

In SelfReferenceEquivalencyOptions almost all public methods return TSelf to allow for fluent syntax. The two exceptions are WithoutMatchingRules and WithoutSelectionRules which return void.

I would suggest to alter the methods to also return TSelf so that they can be combined with other methods.

API Proposal

Replace the two methods

public class SelfReferenceEquivalencyOptions<TSelf>
{
    public void WithoutSelectionRules();

    public void WithoutMatchingRules();
}

with

public class SelfReferenceEquivalencyOptions<TSelf>
{
    public TSelf WithoutSelectionRules();

    public TSelf WithoutMatchingRules();
}

API Usage

subject.Should().BeEquivalentTo(expected,
  options => options
    .AllowingInfiniteRecursion()
    .ComparingByMembers(typeof(Root))
    .ComparingByMembers<RootDto>()
    .ComparingByValue(typeof(Customer))
    .ComparingByValue<CustomerDto>()
    .ComparingEnumsByName()
    .ComparingEnumsByValue()
    .ComparingRecordsByMembers()
    .ComparingRecordsByValue()
    .Excluding(r => r.Level)
    .ExcludingFields()
    .ExcludingMissingMembers()
    .ExcludingNestedObjects()
    .ExcludingNonBrowsableMembers()
    .ExcludingProperties()
    .IgnoringCyclicReferences()
    .IgnoringNonBrowsableMembersOnSubject()
    .Including(r => r.Level)
    .IncludingAllDeclaredProperties()
    .IncludingAllRuntimeProperties()
    .IncludingFields()
    .IncludingInternalFields()
    .IncludingInternalProperties()
    .IncludingNestedObjects()
    .IncludingProperties()
    .RespectingDeclaredTypes()
    .RespectingRuntimeTypes()
    .ThrowingOnMissingMembers()
    .Using(new ExtensibilitySpecs.DoEquivalencyStep(() => { }))
    .Using(new MustMatchByNameRule())
    .Using(new AllFieldsSelectionRule())
    .Using(new ByteArrayOrderingRule())
    .Using(StringComparer.OrdinalIgnoreCase)
    .WithAutoConversion()
    .WithAutoConversionFor(_ => false)
    .WithoutAutoConversionFor(_ => true)
    .WithoutMatchingRules()                // This method can currently not be used in fluent syntax!
    .WithoutSelectionRules()               // This method can currently not be used in fluent syntax!
    .WithoutStrictOrdering()
    .WithoutStrictOrderingFor(r => r.Level)
    .WithStrictOrdering()
    .WithStrictOrderingFor(r => r.Level)
    .WithTracing()
  );

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?

Yes, please assign this issue to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions