Condition Constraints (NUnit 2.4)

ConditionConstraints test a specific condition and are named for the condition they test. They verify that the actual value satisfies the condition. The following condition helpers are provided.

NullConstraint

Action

Tests that a value is Null.

Constructor

NullConstraint()

Syntax

Is.Null

Examples of Use

Assert.That( anObject, Is.Null );
Assert.That( anObject, Is.Not.Null );

TrueConstraint

Action

Tests that a value is true.

Constructor

TrueConstraint()

Syntax

Is.True

Example of Use

Assert.That( condition, Is.True );

FalseConstraint

Action

Tests that a value is false.

Constructor

FalseConstraint()

Syntax

Is.False

Example of Use

Assert.That( condition, Is.False );

NaNConstraint

Action

Tests that a value is floating-point NaN.

Constructor

NaNConstraint()

Syntax

Is.NaN

Examples of Use

Assert.That( aDouble, Is.NaN );
Assert.That( aDouble, Is.Not.NaN );

EmptyConstraint

Action

Tests that an object is an empty string or collection.

Constructor

EmptyConstraint()

Syntax

Is.Empty

Examples of Use

Assert.That( aString, Is.Empty );
Assert.That( collection, Is.Empty );

Notes

  1. EmptyConstraint creates and uses either an EmptyStringConstraint or an EmptyCollectionConstraint depending on the argument tested.

UniqueItemsConstraint

Action

Tests that an array, collection or other IEnumerable is composed of unique items with no duplicates.

Constructor

UniqueItemsConstraint()

Syntax

Is.Unique

Example of Use

Assert.That( collection, Is.Unique );