Skip to content

Commit

Permalink
Add ContainSingle.Where to collection examples (#1917)
Browse files Browse the repository at this point in the history
This if very useful and not at all obvious from the docs that this is possible.
  • Loading branch information
timabell committed Apr 28, 2022
1 parent 2dc899c commit 7895517
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/_pages/collections.md
Expand Up @@ -80,6 +80,10 @@ IEnumerable<int> otherCollection = new[] { 1, 2, 5, 8, 1 };
IEnumerable<int> anotherCollection = new[] { 10, 20, 50, 80, 10 };
collection.Should().IntersectWith(otherCollection);
collection.Should().NotIntersectWith(anotherCollection);

var singleEquivalent = new[] { new { Size = 42 } };
singleEquivalent.Should().ContainSingle()
.Which.Should().BeEquivalentTo(new { Size = 42 });
```

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 `IComparer<T>` implementations.
Expand Down

0 comments on commit 7895517

Please sign in to comment.