Ordering assertions in CollectionAssertions should use IComparer, not IComparer<object>
See original GitHub issueDescription
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 typeT
. - 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:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
True, but technically that would be a breaking change.
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.