Multiple assertions using Fluent Assertions library

Sorry, short answer is that you can't currently get the same results with Fluent assertions. The NUnit assertions have special logic in them that knows they are in a multiple assertion block. In that case, they don't throw an exception on failure, but instead register the failure with the parent multiple assert which will report the error when it is complete.

Fluent assertions will need to do the same thing internally. That could be as simple as chaining to the NUnit assertions, or even just calling Assert.Fail. I would recommend filing an issue with the Fluent assertions project. Feel free to point them to me on GitHub (@rprouse) if they need help on how the NUnit internals work.


You may either:

1: Use AssertionScope (as pointed by @RonaldMcdonald):

using (new AssertionScope())
{
  (2 + 2).Should().Be(5);
  (2 + 2).Should().Be(6);
}

Or:

2. Use FluentAssertions.AssertMultiple NuGet package (the tiny package created by myself):

AssertMultiple.Multiple(() =>
{
    (2 + 2).Should().Be(5);
    (2 + 2).Should().Be(6);
});

And, when you import static member:

using static FluentAssertions.AssertMultiple.AssertMultiple;

//...

Multiple(() =>
{
    (2 + 2).Should().Be(5);
    (2 + 2).Should().Be(6);
});

You can do this with assertion scopes like this:

using (new AssertionScope())
{
    5.Should().Be(10);
    "Actual".Should().Be("Expected");
}