Legacy Documentation. View NUnit 3 Documentation

Compound Constraints (NUnit 2.4)

Compound constraints are used to combine other constraints in various ways.

Syntax HelperConstructorOperation
Is.Not...NotConstraint( Constraint )Negates or reverses the effect of a constraint
Is.All...AllItemsConstraint( Constraint )Tests that all members of a collection match the constraint
Constraint & ConstraintAndConstraint( Constraint, Constraint )Tests that both of the constraints are met
Constraint | ConstraintOrConstraint( Constraint, Constraint )Tests that at least one of the constraints is met

Examples of Use

Assert.That( 2 + 2, Is.Not.EqualTo( 5 );
Assert.That( new int[] { 1, 2, 3 }, Is.All.GreaterThan( 0 ) );
Assert.That( 2.3, Is.GreaterThan( 2.0 ) & Is.LessThan( 3.0 ) );
Assert.That( 3, Is.LessThan( 5 ) | Is.GreaterThan( 10 ) );

// Using inheritance
Expect( 2 + 2, Not.EqualTo( 5 ) );
Expect( 2.3, GreaterThan( 2.0 ) & LessThan( 3.0 ) );