Skip to content

Ordering assertions in CollectionAssertions should use IComparer, not IComparer<object> #998

@m-ringler

Description

@m-ringler

Description

The ordering assertions in CollectionAssertions expect an IComparer<object>, although the declared type of the items in the collection does not need to be object. This makes it hard to use standard comparers such as StringComparer and comparers derived from Comparer<T>.

Complete minimal example reproducing the issue

The following does not compile:

string[] actual = { "a", "b", "c" };
actual.Should().BeInAscendingOrder(StringComparer.CurrentCultureIgnoreCase);

Expected behavior:

  • You should be able to use a comparer that implements IComparer<T> for a generic collection with items of type T.
  • You should be able to use a comparer that implements IComparer for a non-generic collection.

Actual behavior:

Does not compile.

Versions

  • Which version of Fluent Assertions are you using? v5.6.0
  • Which .NET runtime and version are you targeting? .NET framework 4.6.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions