Skip to content

NFluent's assertions structure

Cyrille DUPUYDAUBY edited this page Jan 31, 2018 · 7 revisions

Generalities

  • NFluent assertions are referred to as checks.
  • An assertion can combine one or more checks using And or Which keywords.
  • Writing an assertion To write an assertion you need to capture what needs to be evaluated (referred to as system under test or sut for short).

Capturing the sut

A few capturing methods are provided.

Check.That

This is the most used one. You shoud use it by default and use a specialized one when needed. Example

var myItem = new Myclass();
...
Check.That(myItem).IsInstanceOf<MyClass>();

Check.ThatCode

This one must be used to test portion of code or a delegate. Example:

Check.ThatCode ( () =>
    {
      ...
      throw new ApplicationException();
    }
   ).Throws<ApplicationException>();

Check.ThatAsyncCode

This one must be used to test asynchronous code/delegate lambda.

Check.ThatDynamic

This one must be used to capture dynamics type, otherwise you will have compilation errors due to how dynamic types are implemented in .Net.

Check.ThatEnum

This one can be used on value types, such as structs or enums. While those types can be checked with Check.That, Check.ThatEnum offers some enum/struct specific checks.

Clone this wiki locally