Table of Contents

Class ComparisonConstraint

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

Abstract base class for constraints that compare values to determine if one is greater than, equal to or less than the other.

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

Constructors

ComparisonConstraint(object, string)

Initializes a new instance of the ComparisonConstraint class.

protected ComparisonConstraint(object expected, string comparisonText)

Parameters

expected object

The value against which to make a comparison.

comparisonText string

The text indicating the type of comparison.

Properties

Description

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

public override string Description { get; }

Property Value

string

Percent

Switches the .Within() modifier to interpret its tolerance as a percentage that the actual values is allowed to deviate from the expected value.

public ComparisonConstraint Percent { get; }

Property Value

ComparisonConstraint

Self

Methods

ApplyTo<TActual>(TActual)

Test whether the constraint is satisfied by a given value

public override ConstraintResult ApplyTo<TActual>(TActual actual)

Parameters

actual TActual

The value to be tested

Returns

ConstraintResult

A ConstraintResult

Type Parameters

TActual

PerformComparison(ComparisonAdapter, object, object, Tolerance)

Protected function overridden by derived class to actually perform the comparison

protected abstract bool PerformComparison(ComparisonAdapter comparer, object actual, object expected, Tolerance tolerance)

Parameters

comparer ComparisonAdapter
actual object
expected object
tolerance Tolerance

Returns

bool

Using(IComparer)

Modifies the constraint to use an IComparer and returns self

public ComparisonConstraint Using(IComparer comparer)

Parameters

comparer IComparer

The comparer used for comparison tests

Returns

ComparisonConstraint

A constraint modified to use the given comparer

Using<T>(IComparer<T>)

Modifies the constraint to use an IComparer<T> and returns self

public ComparisonConstraint Using<T>(IComparer<T> comparer)

Parameters

comparer IComparer<T>

The comparer used for comparison tests

Returns

ComparisonConstraint

A constraint modified to use the given comparer

Type Parameters

T

Using<T>(Comparison<T>)

Modifies the constraint to use a Comparison<T> and returns self

public ComparisonConstraint Using<T>(Comparison<T> comparer)

Parameters

comparer Comparison<T>

The comparer used for comparison tests

Returns

ComparisonConstraint

A constraint modified to use the given comparer

Type Parameters

T

Within(object)

Set the tolerance for use in this comparison

public ComparisonConstraint Within(object amount)

Parameters

amount object

Returns

ComparisonConstraint