D.R.
D.R.

Reputation: 21194

FluentAssertions: match each object of a collection

How to check that each object of a collection conforms to a given predicate? E.g.: check for each item (from a given collection) that it matches a given predicate (MyPredicate). Code should probably look something like this:

collection.Should().AllMatch(item => MyPredicate(item));

Is something like that available or do I have to write it myself?

Upvotes: 7

Views: 2894

Answers (1)

D.R.
D.R.

Reputation: 21194

It looks like Fluent Assertions 2.x does not support this scenario. Using Fluent Assertions 3.x one can use:

collection.Should().OnlyContain(predicate)

Upvotes: 12

Related Questions