Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 551
D.R. Avatar asked Apr 29 '14 13:04

D.R.


1 Answers

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

collection.Should().OnlyContain(predicate)
like image 143
D.R. Avatar answered Sep 18 '22 17:09

D.R.