Add AllSatisfyOrEmpty for GenericCollection
dtila opened this issue · comments
Background and motivation
Currently if you want to assert all items or none satisfy a condition, there is no way. AllSatisfy throws exception when collection is empty,
API Proposal
public AndConstraint<CustomCollectionAssertions<T>> AllSatisfyOrEmpty(Action<T> action, string because = "", params object[] becauseArgs)
API Usage
collection.Should()
.HaveCount(2)
.And
.AllSatisfyOrEmpty(li => li.item.Should().HaveCount(0))
Alternative Designs
No response
Risks
No response
Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?
No
I propose that we name this one BeEmptyOrAllSatisfy
. What do you think @jnyrup @arocheleau ?
Hmm.. Why do we need an extra method for this? With #2321 (in v7) an empty collection does not fail anymore.
I crap, you're right. Now I remember the previous discussion.
@dtila It's already there in the upcoming v7 release. If you can't wait, consider using the latest alpha version.
I see better consistency with the .NET environment if #2321 is fixed
Actually when I discovered this behavior I was surprised and look into the code since I wasn't expecting like using All to throw exceptions.
Bug indeed can be closed. Thanks guys!