Skip to content

Conversation

@dennisdoomen
Copy link
Member

@dennisdoomen dennisdoomen commented Apr 18, 2021

Added BeInAscendingOrder and BeInDescendingOrder to string collections taking either an IComparer<string> or a lambda expression

Fixes #998

@dennisdoomen dennisdoomen force-pushed the Feature/StringOrderingAssertions branch from a194f92 to e71037a Compare April 18, 2021 17:48
@dennisdoomen dennisdoomen force-pushed the Feature/StringOrderingAssertions branch 2 times, most recently from 3d004ba to 9967997 Compare April 26, 2021 09:47
@dennisdoomen dennisdoomen force-pushed the Feature/StringOrderingAssertions branch from 9967997 to 514ae50 Compare April 26, 2021 12:06
@dennisdoomen dennisdoomen changed the title [WIP] Support using IComparer and lambdas for asserting the order of strings in collections Allow using IComparer and lambdas for asserting the order of strings in collections Apr 26, 2021
@dennisdoomen dennisdoomen requested a review from jnyrup April 26, 2021 12:08
@dennisdoomen dennisdoomen force-pushed the Feature/StringOrderingAssertions branch from 514ae50 to 40f22da Compare April 27, 2021 09:30
@dennisdoomen
Copy link
Member Author

Rebased on #1529

@dennisdoomen dennisdoomen requested review from jnyrup and removed request for jnyrup April 27, 2021 09:31
Copy link
Member

@jnyrup jnyrup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never get tired of seeing the capabilities of this library, where you can add a new functionality by adding two one-liners.

For completeness NotBeInAscendingOrder and NotBeInDescendingOrder should also be augmented with the new overloads.

@jnyrup jnyrup changed the title Allow using IComparer and lambdas for asserting the order of strings in collections Allow using lambdas for asserting the order of strings in collections Apr 27, 2021
@dennisdoomen dennisdoomen force-pushed the Feature/StringOrderingAssertions branch from 40f22da to 493248a Compare April 27, 2021 17:17
@dennisdoomen dennisdoomen requested a review from jnyrup April 27, 2021 17:17
@jnyrup
Copy link
Member

jnyrup commented Apr 27, 2021

Now I think of it...

Why don't we just add BeInAscendingOrder(Func<T, T, int>, string, params object[]) and friends to GenericCollectionAssertions instead?
Then StringCollectionAssertions gets it for free through inheritance.

@dennisdoomen
Copy link
Member Author

Why don't we just add BeInAscendingOrder(Func<T, T, int>, string, params object[]) and friends to GenericCollectionAssertions instead?

Why didn't I think of this myself...

@dennisdoomen dennisdoomen force-pushed the Feature/StringOrderingAssertions branch from 493248a to d26a4c5 Compare April 28, 2021 07:42
@dennisdoomen dennisdoomen force-pushed the Feature/StringOrderingAssertions branch 2 times, most recently from 30b8ff3 to 08f0d51 Compare April 28, 2021 12:46
collection.Should().NotIntersectWith(anotherCollection);
```

Asserting that a collection contains items in a certain order is as easy as using one of the several overloads of `BeInAscendingOrder` or `BeInDescendingOrder`. The default overload will use the default `Comparer` for the specified type, but overloads also exist that take an `IComparer<T>`, a property expression to sort by an object's property, or a lambda expression to avoid the need for `ICompare<T>` implementations.
Copy link
Member

@jnyrup jnyrup Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ICompare<T> -> IComparer<T>

@jnyrup jnyrup changed the title Allow using lambdas for asserting the order of strings in collections Allow using lambdas for asserting the order of elements in collections Apr 28, 2021
@dennisdoomen dennisdoomen force-pushed the Feature/StringOrderingAssertions branch from 08f0d51 to 99f46f2 Compare April 28, 2021 14:19
Copy link
Member

@jnyrup jnyrup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@dennisdoomen dennisdoomen merged commit 1cdd4b1 into fluentassertions:develop Apr 28, 2021
@dennisdoomen dennisdoomen deleted the Feature/StringOrderingAssertions branch April 28, 2021 15:05
@m-ringler
Copy link

Thanks for improving this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants