Skip to content
Cyrille DUPUYDAUBY edited this page Jan 31, 2018 · 1 revision

Overview

NFluent supports chaining multiple assertions in a single statement. Checks are always executed in a sequencial fashion, so the first check to fail in a chain will raise an exception and remaining checks are not performed.

And keyword

Checks can be chained using the And keyword. Example

  Check.That(2).IsPositive().And.IsStrictlyGreaterThat(1);

There is no limit to the number of checks that can be chained. Exemple:

  var sut = "Lost Highway";
  Check.That(sut).IsAnInstanceOf<String>().
        And.HasContent().
        And.Contains("Lost").
        And.IsNotEqualTo("Raiders of the Lost Arch");

Not keyword

Checks can be negated using the Not keyword. In other words, when using Not,a check fails when it succeeds without Not and succeeds when it fails (without Not). For example, this check succeeds:

 Check.That(4).Not.IsNegative();

Specific error messages are generated. Not impacts only the following check. If this checks is chained to another one with And, the second check logic will be normal (unless Not is added there too). For example, this check succeeds:

 Check.That(4).Not.IsNegative().And.IsEqualTo(4);