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, directory or collection.
Constructor
EmptyConstraint()
Syntax
Is.Empty
Examples of Use
Assert.That( aString, Is.Empty ); Assert.Thst( dirInfo, Is.Empty ); Assert.That( collection, Is.Empty );
Notes
- EmptyConstraint creates and uses either an EmptyStringConstraint, EmptyDirectoryConstraint or EmptyCollectionConstraint depending on the argument tested.
- A DirectoryInfo argument is required in order to test for an empty directory. To test whether a string represents a directory path, you must first construct a DirectoryInfo.
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 );