Add Should().All() feature
See original GitHub issueI very often want to make an assertion about every member of a collection.
You can use .Should().OnlyContain()
but I’d like to be able to use your lovely library of helper assertions.
e.g. I’d like to be able to write:
myStrings.Should().All().StartWith("Hello");
It feels like it ought to be relatively achievable?
Roughly speaking .All() would need to return an object that looked the same as a .Should()
of the Collection contents but which passes all of its implementations down to an inner .Should()
against each of the elements.
First Question: Would you be happy with this functionality existing?
Second Question: Is this something that you’d be likely to implement any time soon? If not, would you accept a PR for it? And do you think such a change would be tractable to an experienced .NET programmer who’s never looked inside your codebase before?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:16 (6 by maintainers)
Top GitHub Comments
Some other viable-but-a-bit-dissappointing solutions exist here:
https://stackoverflow.com/questions/18899755/how-to-assert-all-items-in-a-collection-using-fluent-assertions
The
.Select()
and.ForEach()
forms even give access to the assertion helpers. But I think the above proposal is much more inline with the “Fluent” goal of this library, is a LOT more discoverable, and would be much more pleasant all-round.No worries. Life of an open-source developers is unpredictable at best.
I don’t think we should go in that direction. It will create quite a maintenance burden for the future. Maybe a
Should().AllSatisfy
is a better alternative.