Back to Nunit

GreaterThan Constraint

docs/articles/nunit/writing-tests/constraints/GreaterThanConstraint.md

latest833 B
Original Source

GreaterThan Constraint

GreaterThanConstraint tests that one value is greater than another.

It works with numeric types, DateTime, TimeSpan, and any type implementing IComparable. For custom types, a user-specified comparer can be provided using the Using modifier.

Constructor

csharp
GreaterThanConstraint(object expected)

Syntax

csharp
Is.GreaterThan(object expected)
Is.Positive // Equivalent to Is.GreaterThan(0)

Modifiers

csharp
...Using(IComparer comparer)
...Using<T>(IComparer<T> comparer)
...Using<T>(Comparison<T> comparer)
...Within(object tolerance)

Examples of Use

[!code-csharpGreaterThanExamples] [!code-csharpWith Comparer]