Assert Assert Assert Class

Definition

A collection of helper classes to test various conditions within unit tests. If the condition being tested is not met, an exception is thrown.

public sealed class Assert
type Assert = class
Public NotInheritable Class Assert
Inheritance
AssertAssertAssert

Properties

That That That

Gets the singleton instance of the Assert functionality.

Methods

AreEqual(Object, Object) AreEqual(Object, Object) AreEqual(Object, Object)

Tests whether the specified objects are equal and throws an exception if the two objects are not equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreEqual(String, String, Boolean, CultureInfo, String, Object[]) AreEqual(String, String, Boolean, CultureInfo, String, Object[]) AreEqual(String, String, Boolean, CultureInfo, String, Object[])

Tests whether the specified strings are equal and throws an exception if they are not equal.

AreEqual(String, String, Boolean, String, Object[]) AreEqual(String, String, Boolean, String, Object[]) AreEqual(String, String, Boolean, String, Object[])

Tests whether the specified strings are equal and throws an exception if they are not equal. The invariant culture is used for the comparison.

AreEqual(Single, Single, Single, String, Object[]) AreEqual(Single, Single, Single, String, Object[]) AreEqual(Single, Single, Single, String, Object[])

Tests whether the specified floats are equal and throws an exception if they are not equal.

AreEqual(Double, Double, Double, String, Object[]) AreEqual(Double, Double, Double, String, Object[]) AreEqual(Double, Double, Double, String, Object[])

Tests whether the specified doubles are equal and throws an exception if they are not equal.

AreEqual(String, String, Boolean, String) AreEqual(String, String, Boolean, String) AreEqual(String, String, Boolean, String)

Tests whether the specified strings are equal and throws an exception if they are not equal. The invariant culture is used for the comparison.

AreEqual(String, String, Boolean, CultureInfo) AreEqual(String, String, Boolean, CultureInfo) AreEqual(String, String, Boolean, CultureInfo)

Tests whether the specified strings are equal and throws an exception if they are not equal.

AreEqual(String, String, Boolean, CultureInfo, String) AreEqual(String, String, Boolean, CultureInfo, String) AreEqual(String, String, Boolean, CultureInfo, String)

Tests whether the specified strings are equal and throws an exception if they are not equal.

AreEqual(Object, Object, String, Object[]) AreEqual(Object, Object, String, Object[]) AreEqual(Object, Object, String, Object[])

Tests whether the specified objects are equal and throws an exception if the two objects are not equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreEqual(Double, Double, Double, String) AreEqual(Double, Double, Double, String) AreEqual(Double, Double, Double, String)

Tests whether the specified doubles are equal and throws an exception if they are not equal.

AreEqual(String, String, Boolean) AreEqual(String, String, Boolean) AreEqual(String, String, Boolean)

Tests whether the specified strings are equal and throws an exception if they are not equal. The invariant culture is used for the comparison.

AreEqual(Single, Single, Single) AreEqual(Single, Single, Single) AreEqual(Single, Single, Single)

Tests whether the specified floats are equal and throws an exception if they are not equal.

AreEqual(Object, Object, String) AreEqual(Object, Object, String) AreEqual(Object, Object, String)

Tests whether the specified objects are equal and throws an exception if the two objects are not equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreEqual(Double, Double, Double) AreEqual(Double, Double, Double) AreEqual(Double, Double, Double)

Tests whether the specified doubles are equal and throws an exception if they are not equal.

AreEqual(Single, Single, Single, String) AreEqual(Single, Single, Single, String) AreEqual(Single, Single, Single, String)

Tests whether the specified floats are equal and throws an exception if they are not equal.

AreEqual<T>(T, T, String, Object[]) AreEqual<T>(T, T, String, Object[]) AreEqual<T>(T, T, String, Object[])

Tests whether the specified values are equal and throws an exception if the two values are not equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreEqual<T>(T, T, String) AreEqual<T>(T, T, String) AreEqual<T>(T, T, String)

Tests whether the specified values are equal and throws an exception if the two values are not equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreEqual<T>(T, T) AreEqual<T>(T, T) AreEqual<T>(T, T)

Tests whether the specified values are equal and throws an exception if the two values are not equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreNotEqual(String, String, Boolean, String) AreNotEqual(String, String, Boolean, String) AreNotEqual(String, String, Boolean, String)

Tests whether the specified strings are unequal and throws an exception if they are equal. The invariant culture is used for the comparison.

AreNotEqual(String, String, Boolean, CultureInfo, String, Object[]) AreNotEqual(String, String, Boolean, CultureInfo, String, Object[]) AreNotEqual(String, String, Boolean, CultureInfo, String, Object[])

Tests whether the specified strings are unequal and throws an exception if they are equal.

AreNotEqual(String, String, Boolean, String, Object[]) AreNotEqual(String, String, Boolean, String, Object[]) AreNotEqual(String, String, Boolean, String, Object[])

Tests whether the specified strings are unequal and throws an exception if they are equal. The invariant culture is used for the comparison.

AreNotEqual(String, String, Boolean, CultureInfo, String) AreNotEqual(String, String, Boolean, CultureInfo, String) AreNotEqual(String, String, Boolean, CultureInfo, String)

Tests whether the specified strings are unequal and throws an exception if they are equal.

AreNotEqual(Single, Single, Single, String, Object[]) AreNotEqual(Single, Single, Single, String, Object[]) AreNotEqual(Single, Single, Single, String, Object[])

Tests whether the specified floats are unequal and throws an exception if they are equal.

AreNotEqual(Double, Double, Double, String, Object[]) AreNotEqual(Double, Double, Double, String, Object[]) AreNotEqual(Double, Double, Double, String, Object[])

Tests whether the specified doubles are unequal and throws an exception if they are equal.

AreNotEqual(String, String, Boolean, CultureInfo) AreNotEqual(String, String, Boolean, CultureInfo) AreNotEqual(String, String, Boolean, CultureInfo)

Tests whether the specified strings are unequal and throws an exception if they are equal.

AreNotEqual(Object, Object) AreNotEqual(Object, Object) AreNotEqual(Object, Object)

Tests whether the specified objects are unequal and throws an exception if the two objects are equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreNotEqual(Object, Object, String, Object[]) AreNotEqual(Object, Object, String, Object[]) AreNotEqual(Object, Object, String, Object[])

Tests whether the specified objects are unequal and throws an exception if the two objects are equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreNotEqual(Double, Double, Double, String) AreNotEqual(Double, Double, Double, String) AreNotEqual(Double, Double, Double, String)

Tests whether the specified doubles are unequal and throws an exception if they are equal.

AreNotEqual(String, String, Boolean) AreNotEqual(String, String, Boolean) AreNotEqual(String, String, Boolean)

Tests whether the specified strings are unequal and throws an exception if they are equal. The invariant culture is used for the comparison.

AreNotEqual(Single, Single, Single) AreNotEqual(Single, Single, Single) AreNotEqual(Single, Single, Single)

Tests whether the specified floats are unequal and throws an exception if they are equal.

AreNotEqual(Object, Object, String) AreNotEqual(Object, Object, String) AreNotEqual(Object, Object, String)

Tests whether the specified objects are unequal and throws an exception if the two objects are equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreNotEqual(Double, Double, Double) AreNotEqual(Double, Double, Double) AreNotEqual(Double, Double, Double)

Tests whether the specified doubles are unequal and throws an exception if they are equal.

AreNotEqual(Single, Single, Single, String) AreNotEqual(Single, Single, Single, String) AreNotEqual(Single, Single, Single, String)

Tests whether the specified floats are unequal and throws an exception if they are equal.

AreNotEqual<T>(T, T, String, Object[]) AreNotEqual<T>(T, T, String, Object[]) AreNotEqual<T>(T, T, String, Object[])

Tests whether the specified values are unequal and throws an exception if the two values are equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreNotEqual<T>(T, T) AreNotEqual<T>(T, T) AreNotEqual<T>(T, T)

Tests whether the specified values are unequal and throws an exception if the two values are equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreNotEqual<T>(T, T, String) AreNotEqual<T>(T, T, String) AreNotEqual<T>(T, T, String)

Tests whether the specified values are unequal and throws an exception if the two values are equal. Different numeric types are treated as unequal even if the logical values are equal. 42L is not equal to 42.

AreNotSame(Object, Object, String) AreNotSame(Object, Object, String) AreNotSame(Object, Object, String)

Tests whether the specified objects refer to different objects and throws an exception if the two inputs refer to the same object.

AreNotSame(Object, Object, String, Object[]) AreNotSame(Object, Object, String, Object[]) AreNotSame(Object, Object, String, Object[])

Tests whether the specified objects refer to different objects and throws an exception if the two inputs refer to the same object.

AreNotSame(Object, Object) AreNotSame(Object, Object) AreNotSame(Object, Object)

Tests whether the specified objects refer to different objects and throws an exception if the two inputs refer to the same object.

AreSame(Object, Object) AreSame(Object, Object) AreSame(Object, Object)

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

AreSame(Object, Object, String) AreSame(Object, Object, String) AreSame(Object, Object, String)

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

AreSame(Object, Object, String, Object[]) AreSame(Object, Object, String, Object[]) AreSame(Object, Object, String, Object[])

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

Equals(Object, Object) Equals(Object, Object) Equals(Object, Object)

Static equals overloads are used for comparing instances of two types for reference equality. This method should not be used for comparison of two instances for equality. This object will always throw with Assert.Fail. Please use Assert.AreEqual and associated overloads in your unit tests.

Fail() Fail() Fail()

Throws an AssertFailedException.

Fail(String) Fail(String) Fail(String)

Throws an AssertFailedException.

Fail(String, Object[]) Fail(String, Object[]) Fail(String, Object[])

Throws an AssertFailedException.

Inconclusive(String, Object[]) Inconclusive(String, Object[]) Inconclusive(String, Object[])

Throws an AssertInconclusiveException.

Inconclusive() Inconclusive() Inconclusive()

Throws an AssertInconclusiveException.

Inconclusive(String) Inconclusive(String) Inconclusive(String)

Throws an AssertInconclusiveException.

IsFalse(Boolean) IsFalse(Boolean) IsFalse(Boolean)

Tests whether the specified condition is false and throws an exception if the condition is true.

IsFalse(Boolean, String) IsFalse(Boolean, String) IsFalse(Boolean, String)

Tests whether the specified condition is false and throws an exception if the condition is true.

IsFalse(Boolean, String, Object[]) IsFalse(Boolean, String, Object[]) IsFalse(Boolean, String, Object[])

Tests whether the specified condition is false and throws an exception if the condition is true.

IsInstanceOfType(Object, Type, String, Object[]) IsInstanceOfType(Object, Type, String, Object[]) IsInstanceOfType(Object, Type, String, Object[])

Tests whether the specified object is an instance of the expected type and throws an exception if the expected type is not in the inheritance hierarchy of the object.

IsInstanceOfType(Object, Type) IsInstanceOfType(Object, Type) IsInstanceOfType(Object, Type)

Tests whether the specified object is an instance of the expected type and throws an exception if the expected type is not in the inheritance hierarchy of the object.

IsInstanceOfType(Object, Type, String) IsInstanceOfType(Object, Type, String) IsInstanceOfType(Object, Type, String)

Tests whether the specified object is an instance of the expected type and throws an exception if the expected type is not in the inheritance hierarchy of the object.

IsNotInstanceOfType(Object, Type, String, Object[]) IsNotInstanceOfType(Object, Type, String, Object[]) IsNotInstanceOfType(Object, Type, String, Object[])

Tests whether the specified object is not an instance of the wrong type and throws an exception if the specified type is in the inheritance hierarchy of the object.

IsNotInstanceOfType(Object, Type, String) IsNotInstanceOfType(Object, Type, String) IsNotInstanceOfType(Object, Type, String)

Tests whether the specified object is not an instance of the wrong type and throws an exception if the specified type is in the inheritance hierarchy of the object.

IsNotInstanceOfType(Object, Type) IsNotInstanceOfType(Object, Type) IsNotInstanceOfType(Object, Type)

Tests whether the specified object is not an instance of the wrong type and throws an exception if the specified type is in the inheritance hierarchy of the object.

IsNotNull(Object) IsNotNull(Object) IsNotNull(Object)

Tests whether the specified object is non-null and throws an exception if it is null.

IsNotNull(Object, String) IsNotNull(Object, String) IsNotNull(Object, String)

Tests whether the specified object is non-null and throws an exception if it is null.

IsNotNull(Object, String, Object[]) IsNotNull(Object, String, Object[]) IsNotNull(Object, String, Object[])

Tests whether the specified object is non-null and throws an exception if it is null.

IsNull(Object) IsNull(Object) IsNull(Object)

Tests whether the specified object is null and throws an exception if it is not.

IsNull(Object, String) IsNull(Object, String) IsNull(Object, String)

Tests whether the specified object is null and throws an exception if it is not.

IsNull(Object, String, Object[]) IsNull(Object, String, Object[]) IsNull(Object, String, Object[])

Tests whether the specified object is null and throws an exception if it is not.

IsTrue(Boolean, String, Object[]) IsTrue(Boolean, String, Object[]) IsTrue(Boolean, String, Object[])

Tests whether the specified condition is true and throws an exception if the condition is false.

IsTrue(Boolean, String) IsTrue(Boolean, String) IsTrue(Boolean, String)

Tests whether the specified condition is true and throws an exception if the condition is false.

IsTrue(Boolean) IsTrue(Boolean) IsTrue(Boolean)

Tests whether the specified condition is true and throws an exception if the condition is false.

ReplaceNullChars(String) ReplaceNullChars(String) ReplaceNullChars(String)

Replaces null characters ('\0') with "\0".

ThrowsException<T>(Action) ThrowsException<T>(Action) ThrowsException<T>(Action)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


            AssertFailedException
        if code does not throws exception or throws exception of type other than <code data-dev-comment-type="typeparamref">T</code>.
ThrowsException<T>(Func<Object>) ThrowsException<T>(Func<Object>) ThrowsException<T>(Func<Object>)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


            AssertFailedException
        if code does not throws exception or throws exception of type other than <code data-dev-comment-type="typeparamref">T</code>.
ThrowsException<T>(Action, String) ThrowsException<T>(Action, String) ThrowsException<T>(Action, String)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


            AssertFailedException
        if code does not throws exception or throws exception of type other than <code data-dev-comment-type="typeparamref">T</code>.
ThrowsException<T>(Func<Object>, String) ThrowsException<T>(Func<Object>, String) ThrowsException<T>(Func<Object>, String)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


            AssertFailedException
        if code does not throws exception or throws exception of type other than <code data-dev-comment-type="typeparamref">T</code>.
ThrowsException<T>(Action, String, Object[]) ThrowsException<T>(Action, String, Object[]) ThrowsException<T>(Action, String, Object[])

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


            AssertFailedException
        if code does not throws exception or throws exception of type other than <code data-dev-comment-type="typeparamref">T</code>.
ThrowsException<T>(Func<Object>, String, Object[]) ThrowsException<T>(Func<Object>, String, Object[]) ThrowsException<T>(Func<Object>, String, Object[])

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


            AssertFailedException
        if code does not throws exception or throws exception of type other than <code data-dev-comment-type="typeparamref">T</code>.
ThrowsExceptionAsync<T>(Func<Task>, String) ThrowsExceptionAsync<T>(Func<Task>, String) ThrowsExceptionAsync<T>(Func<Task>, String)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws

AssertFailedException
if code does not throws exception or throws exception of type other than T.

ThrowsExceptionAsync<T>(Func<Task>) ThrowsExceptionAsync<T>(Func<Task>) ThrowsExceptionAsync<T>(Func<Task>)

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws


            AssertFailedException
        if code does not throws exception or throws exception of type other than <code data-dev-comment-type="typeparamref">T</code>.
ThrowsExceptionAsync<T>(Func<Task>, String, Object[]) ThrowsExceptionAsync<T>(Func<Task>, String, Object[]) ThrowsExceptionAsync<T>(Func<Task>, String, Object[])

Tests whether the code specified by delegate action throws exact given exception of type T (and not of derived type) and throws

AssertFailedException
if code does not throws exception or throws exception of type other than T.

Applies to