Condividi tramite


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 ref class Assert abstract sealed
public static class Assert
type Assert = class
Public Class Assert
Inheritance
Assert

Properties

That

Gets the singleton instance of the Assert functionality.

Methods

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

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

AreEqual(Double, Double, Double, String)

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

AreEqual(Double, Double, Double)

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

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(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(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(Single, Single, Single, String, Object[])

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

AreEqual(Single, Single, Single, String)

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

AreEqual(Single, Single, Single)

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

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, CultureInfo, String)

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

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, 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(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)

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<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)

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)

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(Double, Double, Double, String, Object[])

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

AreNotEqual(Double, Double, Double, String)

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

AreNotEqual(Double, Double, Double)

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

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(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(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(Single, Single, Single, String, Object[])

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

AreNotEqual(Single, Single, Single, String)

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

AreNotEqual(Single, Single, Single)

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

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, CultureInfo, String)

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

AreNotEqual(String, String, Boolean, CultureInfo)

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

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, 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)

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

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, 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.

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.

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, 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)

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, 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.

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)

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)

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()

Throws an AssertFailedException.

Fail(String, Object[])

Throws an AssertFailedException.

Fail(String)

Throws an AssertFailedException.

Inconclusive()

Throws an AssertInconclusiveException.

Inconclusive(String, Object[])

Throws an AssertInconclusiveException.

Inconclusive(String)

Throws an AssertInconclusiveException.

IsFalse()

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

IsFalse(Boolean, String, Object[])

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

IsFalse(Boolean, String)

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

IsFalse(Boolean)

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

IsFalse(Nullable<Boolean>, String)

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

IsFalse(Nullable<Boolean>)

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

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, 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.

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.

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)

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)

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, String, Object[])

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

IsNotNull(Object, String)

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

IsNotNull(Object)

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

IsNull(Object, String, Object[])

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

IsNull(Object, String)

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

IsNull(Object)

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

IsTrue()

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

IsTrue()

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

IsTrue()

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

IsTrue(Boolean, String, Object[])

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

IsTrue(Boolean, String)

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

IsTrue(Boolean)

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

ReplaceNullChars(String)

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

ThrowsException<T>()

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.

ThrowsException<T>()

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.

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 T.

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 T.

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 T.

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 T.

ThrowsExceptionAsync<T>()

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>, 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.

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 T.

Applies to