Assert
The Assert class contains a collection of static methods that
implement the most common assertions used in NUnit.
protected Assert()
We don't actually want any instances of this object, but some people
like to inherit from it to add other static methods. Hence, the
protected constructor disallows any instances of this object.
public static void AreEqual(double expected, double actual, double delta, string message, object[] args)
Verifies that two doubles are equal considering a delta. If the
expected value is infinity then the delta value is ignored. If
they are not equal then an AssertionException is
thrown.
Verifies that two doubles are equal considering a delta. If the
expected value is infinity then the delta value is ignored. If
they are not equal then an AssertionException is
thrown.
public static void AreEqual(double expected, double? actual, double delta, string message, object[] args)
Verifies that two doubles are equal considering a delta. If the
expected value is infinity then the delta value is ignored. If
they are not equal then an AssertionException is
thrown.
Verifies that two doubles are equal considering a delta. If the
expected value is infinity then the delta value is ignored. If
they are not equal then an AssertionException is
thrown.
Verifies that two objects are equal. Two objects are considered
equal if both are null, or if both have the same value. NUnit
has special semantics for some object types.
If they are not equal an AssertionException is thrown.
Verifies that two objects are equal. Two objects are considered
equal if both are null, or if both have the same value. NUnit
has special semantics for some object types.
If they are not equal an AssertionException is thrown.
Verifies that two objects are not equal. Two objects are considered
equal if both are null, or if both have the same value. NUnit
has special semantics for some object types.
If they are equal an AssertionException is thrown.
Verifies that two objects are not equal. Two objects are considered
equal if both are null, or if both have the same value. NUnit
has special semantics for some object types.
If they are equal an AssertionException is thrown.
Asserts that two objects do not refer to the same object. If they
are the same an AssertionException is thrown.
Asserts that two objects do not refer to the same object. If they
are the same an AssertionException is thrown.
Asserts that two objects refer to the same object. If they
are not the same an AssertionException is thrown.
Asserts that two objects refer to the same object. If they
are not the same an AssertionException is thrown.
protected static void AssertDoublesAreEqual(double expected, double actual, double delta, string message, object[] args)
Helper for Assert.AreEqual(double expected, double actual, ...)
allowing code generation to work consistently.
Apply a constraint to an actual value, succeeding if the constraint
is satisfied and throwing an assertion exception on failure.
Used as a synonym for That in rare cases where a private setter
causes a Visual Basic compilation error.
public static void ByVal(object actual, IResolveConstraint expression, string message, object[] args)
Apply a constraint to an actual value, succeeding if the constraint
is satisfied and throwing an assertion exception on failure.
Used as a synonym for That in rare cases where a private setter
causes a Visual Basic compilation error.
Verifies that a delegate throws an exception when called
and returns it.
Verifies that a delegate throws an exception when called
and returns it.
public static Exception Catch(Type expectedExceptionType, TestDelegate code, string message, object[] args)
Verifies that a delegate throws an exception of a certain Type
or one derived from it when called and returns it.
Verifies that a delegate throws an exception of a certain Type
or one derived from it when called and returns it.
public static TActual Catch<TActual>(TestDelegate code, string message, object[] args) where TActual : Exception
Verifies that a delegate throws an exception of a certain Type
or one derived from it when called and returns it.
Verifies that a delegate throws an exception of a certain Type
or one derived from it when called and returns it.
Verifies that an async delegate throws an exception when called
and returns it.
Verifies that an async delegate throws an exception when called
and returns it.
public static Exception CatchAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, object[] args)
Verifies that an async delegate throws an exception of a certain Type
or one derived from it when called and returns it.
Verifies that an async delegate throws an exception of a certain Type
or one derived from it when called and returns it.
public static TActual CatchAsync<TActual>(AsyncTestDelegate code, string message, object[] args) where TActual : Exception
Verifies that an async delegate throws an exception of a certain Type
or one derived from it when called and returns it.
Verifies that an async delegate throws an exception of a certain Type
or one derived from it when called and returns it.
Asserts that an object is contained in a collection.
Asserts that an object is contained in a collection.
Verifies that a delegate does not throw an exception
Verifies that a delegate does not throw an exception.
Verifies that an async delegate does not throw an exception
Verifies that an async delegate does not throw an exception.
DO NOT USE! Use Assert.AreEqual(...) instead.
The Equals method throws an InvalidOperationException. This is done
to make sure there is no mistake by calling this function.
Throws an AssertionException with the message and arguments
that are passed in. This is used by the other Assert functions.
Throws an AssertionException with the message that is
passed in. This is used by the other Assert functions.
Throws an AssertionException.
This is used by the other Assert functions.
Asserts that a condition is false. If the condition is true the method throws
an AssertionException.
Asserts that a condition is false. If the condition is true the method throws
an AssertionException.
Asserts that a condition is false. If the condition is true the method throws
an AssertionException.
Asserts that a condition is false. If the condition is true the method throws
an AssertionException.
Verifies that the first int is greater than the second
int. If it is not, then an
AssertionException is thrown.
Verifies that the first int is greater than the second
int. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
public static void GreaterOrEqual(IComparable arg1, IComparable arg2, string message, object[] args)
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is greater than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Throws an IgnoreException with the message and arguments
that are passed in. This causes the test to be reported as ignored.
Throws an IgnoreException with the message that is
passed in. This causes the test to be reported as ignored.
Throws an IgnoreException.
This causes the test to be reported as ignored.
Throws an InconclusiveException with the message and arguments
that are passed in. This causes the test to be reported as inconclusive.
Throws an InconclusiveException with the message that is
passed in. This causes the test to be reported as inconclusive.
Throws an InconclusiveException.
This causes the test to be reported as Inconclusive.
Asserts that an object may be assigned a value of a given Type.
Asserts that an object may be assigned a value of a given Type.
Asserts that an object may be assigned a value of a given Type.
Asserts that an object may be assigned a value of a given Type.
Assert that a string is empty - that is equal to string.Empty
Assert that a string is empty - that is equal to string.Empty
Assert that an array, list or other collection is empty
Assert that an array, list or other collection is empty
Asserts that a condition is false. If the condition is true the method throws
an AssertionException.
Asserts that a condition is false. If the condition is true the method throws
an AssertionException.
Asserts that a condition is false. If the condition is true the method throws
an AssertionException.
Asserts that a condition is false. If the condition is true the method throws
an AssertionException.
Asserts that an object is an instance of a given type.
Asserts that an object is an instance of a given type.
Asserts that an object is an instance of a given type.
Asserts that an object is an instance of a given type.
Verifies that the double that is passed in is an NaN value.
If the object is not NaN then an AssertionException
is thrown.
Verifies that the double that is passed in is an NaN value.
If the object is not NaN then an AssertionException
is thrown.
Verifies that the double that is passed in is an NaN value.
If the object is not NaN then an AssertionException
is thrown.
Verifies that the double that is passed in is an NaN value.
If the object is not NaN then an AssertionException
is thrown.
Asserts that an object may not be assigned a value of a given Type.
Asserts that an object may not be assigned a value of a given Type.
Asserts that an object may not be assigned a value of a given Type.
Asserts that an object may not be assigned a value of a given Type.
Assert that a string is not empty - that is not equal to string.Empty
Assert that a string is not empty - that is not equal to string.Empty
Assert that an array, list or other collection is not empty
Assert that an array, list or other collection is not empty
Asserts that an object is not an instance of a given type.
Asserts that an object is not an instance of a given type.
Asserts that an object is not an instance of a given type.
Asserts that an object is not an instance of a given type.
Verifies that the object that is passed in is not equal to null
If the object is null then an AssertionException
is thrown.
Verifies that the object that is passed in is not equal to null
If the object is null then an AssertionException
is thrown.
Verifies that the object that is passed in is equal to null
If the object is not null then an AssertionException
is thrown.
Verifies that the object that is passed in is equal to null
If the object is not null then an AssertionException
is thrown.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Verifies that the first value is less than or equal to the second
value. If it is not, then an
AssertionException is thrown.
Wraps code containing a series of assertions, which should all
be executed, even if they fail. Failed results are saved and
reported at the end of the code block.
Wraps code containing a series of assertions, which should all
be executed, even if they fail. Failed results are saved and
reported at the end of the code block.
Asserts that an int is negative.
Asserts that an int is negative.
Asserts that an unsigned int is negative.
Asserts that an unsigned int is negative.
Asserts that a Long is negative.
Asserts that a Long is negative.
Asserts that an unsigned Long is negative.
Asserts that an unsigned Long is negative.
Asserts that a decimal is negative.
Asserts that a decimal is negative.
Asserts that a double is negative.
Asserts that a double is negative.
Asserts that a float is negative.
Asserts that a float is negative.
Verifies that the object that is passed in is not equal to null
If the object is null then an AssertionException
is thrown.
Verifies that the object that is passed in is not equal to null
If the object is null then an AssertionException
is thrown.
Asserts that an int is not zero.
Asserts that an int is not zero.
Asserts that an unsigned int is not zero.
Asserts that an unsigned int is not zero.
Asserts that a Long is not zero.
Asserts that a Long is not zero.
Asserts that an unsigned Long is not zero.
Asserts that an unsigned Long is not zero.
Asserts that a decimal is zero.
Asserts that a decimal is zero.
Asserts that a double is zero.
Asserts that a double is zero.
Asserts that a float is zero.
Asserts that a float is zero.
Verifies that the object that is passed in is equal to null
If the object is not null then an AssertionException
is thrown.
Verifies that the object that is passed in is equal to null
If the object is not null then an AssertionException
is thrown.
Throws a SuccessException with the message and arguments
that are passed in. This allows a test to be cut short, with a result
of success returned to NUnit.
Throws a SuccessException with the message and arguments
that are passed in. This allows a test to be cut short, with a result
of success returned to NUnit.
Throws a SuccessException with the message and arguments
that are passed in. This allows a test to be cut short, with a result
of success returned to NUnit.
Asserts that an int is positive.
Asserts that an int is positive.
Asserts that an unsigned int is positive.
Asserts that an unsigned int is positive.
Asserts that a Long is positive.
Asserts that a Long is positive.
Asserts that an unsigned Long is positive.
Asserts that an unsigned Long is positive.
Asserts that a decimal is positive.
Asserts that a decimal is positive.
Asserts that a double is positive.
Asserts that a double is positive.
Asserts that a float is positive.
Asserts that a float is positive.
DO NOT USE!
The ReferenceEquals method throws an InvalidOperationException. This is done
to make sure there is no mistake by calling this function.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Apply a constraint to an actual value, succeeding if the constraint
is satisfied and throwing an assertion exception on failure.
public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, string message, object[] args)
Apply a constraint to an actual value, succeeding if the constraint
is satisfied and throwing an assertion exception on failure.
public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, Func<string> getExceptionMessage)
Apply a constraint to an actual value, succeeding if the constraint
is satisfied and throwing an assertion exception on failure.
Asserts that the code represented by a delegate throws an exception
that satisfies the constraint provided.
public static void That(TestDelegate code, IResolveConstraint constraint, string message, object[] args)
Asserts that the code represented by a delegate throws an exception
that satisfies the constraint provided.
public static void That(TestDelegate code, IResolveConstraint constraint, Func<string> getExceptionMessage)
Asserts that the code represented by a delegate throws an exception
that satisfies the constraint provided.
Apply a constraint to an actual value, succeeding if the constraint
is satisfied and throwing an assertion exception on failure.
public static void That<TActual>(TActual actual, IResolveConstraint expression, string message, object[] args)
Apply a constraint to an actual value, succeeding if the constraint
is satisfied and throwing an assertion exception on failure.
public static void That<TActual>(TActual actual, IResolveConstraint expression, Func<string> getExceptionMessage)
Apply a constraint to an actual value, succeeding if the constraint
is satisfied and throwing an assertion exception on failure.
public static Exception Throws(IResolveConstraint expression, TestDelegate code, string message, object[] args)
Verifies that a delegate throws a particular exception when called.
Verifies that a delegate throws a particular exception when called.
public static Exception Throws(Type expectedExceptionType, TestDelegate code, string message, object[] args)
Verifies that a delegate throws a particular exception when called.
Verifies that a delegate throws a particular exception when called.
public static TActual Throws<TActual>(TestDelegate code, string message, object[] args) where TActual : Exception
Verifies that a delegate throws a particular exception when called.
Verifies that a delegate throws a particular exception when called.
public static Exception ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code, string message, object[] args)
Verifies that an async delegate throws a particular exception when called.
Verifies that an async delegate throws a particular exception when called.
public static Exception ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, object[] args)
Verifies that an async delegate throws a particular exception when called.
Verifies that an async delegate throws a particular exception when called.
public static TActual ThrowsAsync<TActual>(AsyncTestDelegate code, string message, object[] args) where TActual : Exception
Verifies that an async delegate throws a particular exception when called.
Verifies that an async delegate throws a particular exception when called.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Asserts that a condition is true. If the condition is false the method throws
an AssertionException.
Issues a warning using the message and arguments provided.
Issues a warning using the message provided.
Asserts that an int is zero.
Asserts that an int is zero.
Asserts that an unsigned int is zero.
Asserts that an unsigned int is zero.
Asserts that a Long is zero.
Asserts that a Long is zero.
Asserts that an unsigned Long is zero.
Asserts that an unsigned Long is zero.
Asserts that a decimal is zero.
Asserts that a decimal is zero.
Asserts that a double is zero.
Asserts that a double is zero.
Asserts that a float is zero.
Asserts that a float is zero.