-
Notifications
You must be signed in to change notification settings - Fork 53
Chaining checks
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.
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");
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);
- Welcome
- How to start
- Customising error messages
-
Check.That
- All (Equality, Type)
- Reference types
- Members based
- IEnumerable (Properties, Content, Elements)
- String (Properties, Content, RegExp )
- Numeric Type(Properties, Comparisons, Floating)
- Dictionary
- Char (Properties, Value)
- IComparable
- DateTime
- DateTimeOffset
- Misc: Boolean, TimeSpan, Stream, Enum, EventWaitHandle
- Check.ThatCode
- Check.ThatDynamic
- Extensibility
- Auxiliary types (TimeUnit)
- Mocks