Skip to content
Cyrille DUPUYDAUBY edited this page Feb 1, 2019 · 4 revisions

Foreword

Fully customised error messages is long running request. And while significant efforts have been made to refactor NFluent such as this could become a reality, it did not happen yet. Two reasons for that:

  1. This feature is a risk: what happens if the error messages is disconnected with the actual check. Or reversed by accident?
  2. Pleasant API construct not identified (yet).

I am please to report an API has been designed and is available since V2.4.0. It is worth repeating that you should rely has much as possible on the generated error messages and use custom error messages sparingly (see item 1 above).

As(...)

As allows you to customise the name of the sut. It can be used anytime a check can be expressed. Example:

Check.That(42).As("answer").IsAfter(100)

Will raise this message:


The checked [answer] is not after the reference value.
The checked [answer]:
    [42]
The expected [answer]: after
    [100]

WithCustomMessage(...)

Adds a custom message on the first line of the generated error message. Example:

Check.WithCustomMessage("Cool, arithmetic still works.").That(42).IsAfter(100)

Will raise this message:

Cool, arithmetic still works.
The checked [answer] is not after the reference value.
The checked [answer]:
    [42]
The expected [answer]: after
    [100]