FluentAssertions: match each object of a collection
Asked Answered
H

1

7

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?

Habit answered 29/4, 2014 at 13:25 Comment(0)
H
12

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

collection.Should().OnlyContain(predicate)
Habit answered 29/4, 2014 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.