0

For example;

results.Errors.Count.Should().Be(0, $"because {results.Errors[0]}");

produces the Result Message:

Expected value to be 0 because 'Name' should not be empty., but found 2.

But what I really want, in this particular instance (invocation of the assertion) is just the value of results.Errors[0], that is I would like the message to be just: 'Name' should not be empty.

(As an aside what I really want is to pass a concatenated string representation of the entire results.Errors array, but my linq/lambda skills aren't there yet)!

So how can I get FA to just use what I supply as the message string?

davegi
  • 1
  • Are you using FA in production rather than from within unit tests? – Dennis Doomen Nov 14 '16 at 07:10
  • I am trying to use [FluentAssertions](http://www.fluentassertions.com/) in my unit tests, which use [nunit](http://www.nunit.com/) to test my [FluentValidations](https://github.com/JeremySkinner/FluentValidation) `validators`, which are in production code. – davegi Nov 14 '16 at 23:01
  • Just give "descreptive" name for the test method and test only one thing per test(almost as one assert per test). Then you don't need message anymore. Name of the failed test will provide enough information – Fabio Jan 12 '17 at 13:38

1 Answers1

0

You can't do that. The because part is baked into the language to promote failure messages that are as natural as possible.

Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44
  • This is just an example. The message text is being set by another component ([FluentValidations](https://github.com/JeremySkinner/FluentValidation)) which is where I'd like to extract the assertion message text. – davegi Nov 13 '16 at 18:52