question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dennisdoomencommented, Feb 6, 2019

True, but technically that would be a breaking change.

0reactions
jnyrupcommented, Feb 7, 2019

No worries, I’ve been confused about that before as well.

For some future major release I hope we can overhaul the collection assertions more.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When to use IComparable<T> Vs. IComparer<T>
I tend to use IComparable<T> for times when I need to know how another instance relates to this instance. IComparer<T> is useful for...
Read more >
Comparisons and Sorts Within Collections
Collections typically utilize an equality comparer and/or an ordering comparer. Two constructs are used for comparisons.
Read more >
List<T>.Sort Method (System.Collections.Generic)
A List<T> of strings is created and populated with four strings, in no particular order. The list is displayed, sorted using the alternate...
Read more >
Assert Two Lists for Equality Ignoring Order in Java
In this test, although we have the same elements, the size of both lists is not equal, but the assertion will still be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found