Skip to content

Allow to configure custom IOrderingRule #1336

@philippdolder

Description

@philippdolder

Description

The extension documentation claims that I can implement a custom IOrderingRule for Should().BeEquivalentTo(). But it's impossible to hook it into the the options. Neither for the global AssertionOptions nor explicitly for a particular invocation of BeEquivalentTo().

Complete minimal example reproducing the issue

namespace XbrlPlus
{
    using System.Collections.Generic;
    using FluentAssertions.Common;
    using FluentAssertions.Equivalency;

    public class ReadOnlyListOrderingRule : IOrderingRule
    {
        public OrderStrictness Evaluate(IMemberInfo memberInfo) =>
            memberInfo.CompileTimeType.IsSameOrInherits(typeof(IReadOnlyList<>))
                ? OrderStrictness.Strict
                : OrderStrictness.Irrelevant;

        public override string ToString() => "Be strict about the order of items in read-only lists";
    }
}

AssertionOptions.AssertEquivalencyUsing(options => options.Using(new ReadOnlyListOrderingRule()));

object x = "";
x.Should().BeEquivalentTo("", options => options.Using(new ReadOnlyListOrderingRule()));

Expected behavior:

Respect the custom rule.

Actual behavior:

Compiler error.

Versions

  • Which version of Fluent Assertions are you using?
    5.10.3
  • Which .NET runtime and version are you targeting?
    netstandard2.1

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions