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
objectThe value against which to make a comparison.
comparisonText
stringThe 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
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
TActualThe 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
ComparisonAdapteractual
objectexpected
objecttolerance
Tolerance
Returns
Using(IComparer)
Modifies the constraint to use an IComparer and returns self
public ComparisonConstraint Using(IComparer comparer)
Parameters
comparer
IComparerThe 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