Table of Contents

Class Constraint

Namespace
NUnit.Framework.Constraints
Assembly
nunit.framework.dll

The Constraint class is the base of all built-in constraints within NUnit. It provides the operator overloads used to combine constraints.

public abstract class Constraint : IConstraint, IResolveConstraint
Inheritance
Constraint
Implements
Derived
Inherited Members

Constructors

Constraint(params object[])

Construct a constraint with optional arguments

protected Constraint(params object[] args)

Parameters

args object[]

Arguments to be saved

Properties

And

Returns a ConstraintExpression by appending And to the current constraint.

public ConstraintExpression And { get; }

Property Value

ConstraintExpression

Arguments

Arguments provided to this Constraint, for use in formatting the description.

public object[] Arguments { get; }

Property Value

object[]

Builder

The ConstraintBuilder holding this constraint

public ConstraintBuilder Builder { get; set; }

Property Value

ConstraintBuilder

Description

The Description of what this constraint tests, for use in messages and in the ConstraintResult.

public virtual string Description { get; protected set; }

Property Value

string

DisplayName

The display name of this Constraint for use by ToString(). The default value is the name of the constraint with trailing "Constraint" removed. Derived classes may set this to another name in their constructors.

public string DisplayName { get; protected set; }

Property Value

string

Or

Returns a ConstraintExpression by appending Or to the current constraint.

public ConstraintExpression Or { get; }

Property Value

ConstraintExpression

With

Returns a ConstraintExpression by appending And to the current constraint.

public ConstraintExpression With { get; }

Property Value

ConstraintExpression

Methods

After(int)

Returns a DelayedConstraint with the specified delay time.

public DelayedConstraint After(int delayInMilliseconds)

Parameters

delayInMilliseconds int

The delay in milliseconds.

Returns

DelayedConstraint

After(int, int)

Returns a DelayedConstraint with the specified delay time and polling interval.

public DelayedConstraint After(int delayInMilliseconds, int pollingInterval)

Parameters

delayInMilliseconds int

The delay in milliseconds.

pollingInterval int

The interval at which to test the constraint.

Returns

DelayedConstraint

ApplyTo<TActual>(ActualValueDelegate<TActual>)

Applies the constraint to an ActualValueDelegate that returns the value to be tested. The default implementation simply evaluates the delegate but derived classes may override it to provide for delayed processing.

public virtual ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)

Parameters

del ActualValueDelegate<TActual>

An ActualValueDelegate

Returns

ConstraintResult

A ConstraintResult

Type Parameters

TActual

ApplyTo<TActual>(TActual)

Applies the constraint to an actual value, returning a ConstraintResult.

public abstract ConstraintResult ApplyTo<TActual>(TActual actual)

Parameters

actual TActual

The value to be tested

Returns

ConstraintResult

A ConstraintResult

Type Parameters

TActual

ApplyTo<TActual>(ref TActual)

Test whether the constraint is satisfied by a given reference. The default implementation simply dereferences the value but derived classes may override it to provide for delayed processing.

public virtual ConstraintResult ApplyTo<TActual>(ref TActual actual)

Parameters

actual TActual

A reference to the value to be tested

Returns

ConstraintResult

A ConstraintResult

Type Parameters

TActual

GetStringRepresentation()

Returns the string representation of this constraint

protected virtual string GetStringRepresentation()

Returns

string

ToString()

Default override of ToString returns the constraint DisplayName followed by any arguments within angle brackets.

public override string ToString()

Returns

string

Operators

operator &(Constraint, Constraint)

This operator creates a constraint that is satisfied only if both argument constraints are satisfied.

public static Constraint operator &(Constraint left, Constraint right)

Parameters

left Constraint
right Constraint

Returns

Constraint

operator |(Constraint, Constraint)

This operator creates a constraint that is satisfied if either of the argument constraints is satisfied.

public static Constraint operator |(Constraint left, Constraint right)

Parameters

left Constraint
right Constraint

Returns

Constraint

operator !(Constraint)

This operator creates a constraint that is satisfied if the argument constraint is not satisfied.

public static Constraint operator !(Constraint constraint)

Parameters

constraint Constraint

Returns

Constraint