Class Constraint
The Constraint class is the base of all built-in constraints
within NUnit. It provides the operator overloads used to combine
constraints.
Assembly: nunit.framework.dll
Syntax
public abstract class Constraint : IConstraint, IResolveConstraint
Constructors
View Source
Constraint(params object?[])
Construct a constraint with optional arguments
Declaration
protected Constraint(params object?[] args)
Parameters
Type |
Name |
Description |
object[] |
args |
Arguments to be saved
|
Properties
View Source
And
Returns a ConstraintExpression by appending And
to the current constraint.
Declaration
public ConstraintExpression And { get; }
Property Value
View Source
Arguments
Arguments provided to this Constraint, for use in
formatting the description.
Declaration
public object?[] Arguments { get; }
Property Value
View Source
Builder
The ConstraintBuilder holding this constraint
Declaration
public ConstraintBuilder? Builder { get; set; }
Property Value
View Source
Description
The Description of what this constraint tests, for
use in messages and in the ConstraintResult.
Declaration
public abstract string Description { get; }
Property Value
View Source
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.
Declaration
public virtual string DisplayName { get; }
Property Value
View Source
Or
Returns a ConstraintExpression by appending Or
to the current constraint.
Declaration
public ConstraintExpression Or { get; }
Property Value
View Source
With
Returns a ConstraintExpression by appending And
to the current constraint.
Declaration
public ConstraintExpression With { get; }
Property Value
Methods
View Source
After(int)
Returns a DelayedConstraint.WithRawDelayInterval with the specified delay time.
Declaration
public DelayedConstraint.WithRawDelayInterval After(int delay)
Parameters
Type |
Name |
Description |
int |
delay |
The delay, which defaults to milliseconds.
|
Returns
View Source
After(int, int)
Returns a DelayedConstraint with the specified delay time
and polling interval.
Declaration
public DelayedConstraint After(int delayInMilliseconds, int pollingInterval)
Parameters
Type |
Name |
Description |
int |
delayInMilliseconds |
The delay in milliseconds.
|
int |
pollingInterval |
The interval at which to test the constraint, in milliseconds.
|
Returns
View Source
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.
Declaration
public virtual ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)
Parameters
Returns
Type Parameters
View Source
ApplyTo<TActual>(TActual)
Applies the constraint to an actual value, returning a ConstraintResult.
Declaration
public abstract ConstraintResult ApplyTo<TActual>(TActual actual)
Parameters
Type |
Name |
Description |
TActual |
actual |
The value to be tested
|
Returns
Type Parameters
View Source
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.
Declaration
public virtual ConstraintResult ApplyTo<TActual>(ref TActual actual)
Parameters
Type |
Name |
Description |
TActual |
actual |
A reference to the value to be tested
|
Returns
Type Parameters
View Source
GetStringRepresentation()
Returns the string representation of this constraint
Declaration
protected virtual string GetStringRepresentation()
Returns
View Source
GetStringRepresentation(IEnumerable)
Returns the string representation of this constraint and the passed in arguments
Declaration
protected string GetStringRepresentation(IEnumerable arguments)
Parameters
Returns
View Source
GetTestObject<TActual>(ActualValueDelegate<TActual>)
Retrieves the value to be tested from an ActualValueDelegate.
The default implementation simply evaluates the delegate but derived
classes may override it to provide for delayed processing.
Declaration
protected virtual object? GetTestObject<TActual>(ActualValueDelegate<TActual> del)
Parameters
Returns
Type |
Description |
object |
Delegate evaluation result
|
Type Parameters
View Source
ToString()
Default override of ToString returns the constraint DisplayName
followed by any arguments within angle brackets.
Declaration
public override string ToString()
Returns
Overrides
Operators
View Source
operator &(Constraint, Constraint)
This operator creates a constraint that is satisfied only if both
argument constraints are satisfied.
Declaration
public static Constraint operator &(Constraint left, Constraint right)
Parameters
Returns
View Source
operator |(Constraint, Constraint)
This operator creates a constraint that is satisfied if either
of the argument constraints is satisfied.
Declaration
public static Constraint operator |(Constraint left, Constraint right)
Parameters
Returns
View Source
operator !(Constraint)
This operator creates a constraint that is satisfied if the
argument constraint is not satisfied.
Declaration
public static Constraint operator !(Constraint constraint)
Parameters
Returns
Implements