How to assert all items in a collection using fluent-assertions?

The recommended way is to use OnlyContain:

items.Should().OnlyContain(x => x.IsActive, "because I said so!");

These will also work:

items.All(x => x.IsActive).Should().BeTrue("because I said so!");

items.Select(x => x.IsActive.Should().BeTrue("because I said so!"))
     .All(x => true); 

Note that the last line (.All(x => true)) forces the previous Select to execute for each item.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)