Show / Hide Table of Contents

Class AssertThat

Provides static methods for making assertions in tests with descriptive failure messages.

Inheritance
object
AssertThat
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class AssertThat

Methods

| Edit this page View Source

AreEqual<T>(T, T)

Verifies that two values are equal.

Declaration
public static void AreEqual<T>(T expected, T actual)
Parameters
Type Name Description
T expected

The expected value.

T actual

The actual value.

Type Parameters
Name Description
T

The type of values to compare.

Exceptions
Type Condition
AssertionException

Thrown when the values are not equal.

| Edit this page View Source

AreEqual<T>(T, T, string)

Verifies that two values are equal.

Declaration
public static void AreEqual<T>(T expected, T actual, string message)
Parameters
Type Name Description
T expected

The expected value.

T actual

The actual value.

string message

The message to display if the assertion fails.

Type Parameters
Name Description
T

The type of values to compare.

Exceptions
Type Condition
AssertionException

Thrown when the values are not equal.

| Edit this page View Source

AreNotEqual<T>(T, T)

Verifies that two values are not equal.

Declaration
public static void AreNotEqual<T>(T expected, T actual)
Parameters
Type Name Description
T expected

The value that should not match the actual value.

T actual

The actual value.

Type Parameters
Name Description
T

The type of values to compare.

Exceptions
Type Condition
AssertionException

Thrown when the values are equal.

| Edit this page View Source

AreNotEqual<T>(T, T, string)

Verifies that two values are not equal.

Declaration
public static void AreNotEqual<T>(T expected, T actual, string message)
Parameters
Type Name Description
T expected

The value that should not match the actual value.

T actual

The actual value.

string message

The message to display if the assertion fails.

Type Parameters
Name Description
T

The type of values to compare.

Exceptions
Type Condition
AssertionException

Thrown when the values are equal.

| Edit this page View Source

AreNotSame(object?, object?)

Verifies that the two object references do not refer to the same object.

Declaration
public static void AreNotSame(object? expected, object? actual)
Parameters
Type Name Description
object expected

The object reference that should not match the actual reference.

object actual

The actual object reference.

Exceptions
Type Condition
AssertionException

Thrown when the references are the same.

| Edit this page View Source

AreNotSame(object?, object?, string)

Verifies that the two object references do not refer to the same object.

Declaration
public static void AreNotSame(object? expected, object? actual, string message)
Parameters
Type Name Description
object expected

The object reference that should not match the actual reference.

object actual

The actual object reference.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the references are the same.

| Edit this page View Source

AreSame(object?, object?)

Verifies that the two object references refer to the same object.

Declaration
public static void AreSame(object? expected, object? actual)
Parameters
Type Name Description
object expected

The expected object reference.

object actual

The actual object reference.

Exceptions
Type Condition
AssertionException

Thrown when the references are not the same.

| Edit this page View Source

AreSame(object?, object?, string)

Verifies that the two object references refer to the same object.

Declaration
public static void AreSame(object? expected, object? actual, string message)
Parameters
Type Name Description
object expected

The expected object reference.

object actual

The actual object reference.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the references are not the same.

| Edit this page View Source

DoesNotThrow(Action)

Verifies that the specified action does not throw any exception.

Declaration
public static void DoesNotThrow(Action action)
Parameters
Type Name Description
Action action

The action to execute.

Exceptions
Type Condition
AssertionException

Thrown when an exception is thrown.

| Edit this page View Source

DoesNotThrow(Action, string)

Verifies that the specified action does not throw any exception.

Declaration
public static void DoesNotThrow(Action action, string message)
Parameters
Type Name Description
Action action

The action to execute.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when an exception is thrown.

| Edit this page View Source

Fail(string)

Fails the test with the specified message.

Declaration
[DoesNotReturn]
public static void Fail(string message)
Parameters
Type Name Description
string message

The failure message.

Exceptions
Type Condition
AssertionException

Always thrown.

| Edit this page View Source

IsFalse(bool)

Verifies that the specified condition is false.

Declaration
public static void IsFalse(bool condition)
Parameters
Type Name Description
bool condition

The condition to verify.

Exceptions
Type Condition
AssertionException

Thrown when the condition is true.

| Edit this page View Source

IsFalse(bool, string)

Verifies that the specified condition is false.

Declaration
public static void IsFalse(bool condition, string message)
Parameters
Type Name Description
bool condition

The condition to verify.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the condition is true.

| Edit this page View Source

IsNotNull<T>(T?)

Verifies that the specified value is not null.

Declaration
public static void IsNotNull<T>(T? value) where T : class
Parameters
Type Name Description
T value

The value to check.

Type Parameters
Name Description
T

The type of the value.

Exceptions
Type Condition
AssertionException

Thrown when the value is null.

| Edit this page View Source

IsNotNull<T>(T?, string)

Verifies that the specified value is not null.

Declaration
public static void IsNotNull<T>(T? value, string message) where T : class
Parameters
Type Name Description
T value

The value to check.

string message

The message to display if the assertion fails.

Type Parameters
Name Description
T

The type of the value.

Exceptions
Type Condition
AssertionException

Thrown when the value is null.

| Edit this page View Source

IsNotOfType<T>(object?)

Verifies that the specified value is not of the specified type.

Declaration
public static void IsNotOfType<T>(object? value)
Parameters
Type Name Description
object value

The value to check.

Type Parameters
Name Description
T

The type that the value should not be.

Exceptions
Type Condition
AssertionException

Thrown when the value is of the specified type.

| Edit this page View Source

IsNotOfType<T>(object?, string)

Verifies that the specified value is not of the specified type.

Declaration
public static void IsNotOfType<T>(object? value, string message)
Parameters
Type Name Description
object value

The value to check.

string message

The message to display if the assertion fails.

Type Parameters
Name Description
T

The type that the value should not be.

Exceptions
Type Condition
AssertionException

Thrown when the value is of the specified type.

| Edit this page View Source

IsNull<T>(T?)

Verifies that the specified value is null.

Declaration
public static void IsNull<T>(T? value) where T : class
Parameters
Type Name Description
T value

The value to check.

Type Parameters
Name Description
T

The type of the value.

Exceptions
Type Condition
AssertionException

Thrown when the value is not null.

| Edit this page View Source

IsNull<T>(T?, string)

Verifies that the specified value is null.

Declaration
public static void IsNull<T>(T? value, string message) where T : class
Parameters
Type Name Description
T value

The value to check.

string message

The message to display if the assertion fails.

Type Parameters
Name Description
T

The type of the value.

Exceptions
Type Condition
AssertionException

Thrown when the value is not null.

| Edit this page View Source

IsOfType<T>(object?)

Verifies that the specified value is of the expected type.

Declaration
public static void IsOfType<T>(object? value)
Parameters
Type Name Description
object value

The value to check.

Type Parameters
Name Description
T

The expected type.

Exceptions
Type Condition
AssertionException

Thrown when the value is not of the expected type.

| Edit this page View Source

IsOfType<T>(object?, string)

Verifies that the specified value is of the expected type.

Declaration
public static void IsOfType<T>(object? value, string message)
Parameters
Type Name Description
object value

The value to check.

string message

The message to display if the assertion fails.

Type Parameters
Name Description
T

The expected type.

Exceptions
Type Condition
AssertionException

Thrown when the value is not of the expected type.

| Edit this page View Source

IsTrue(bool)

Verifies that the specified condition is true.

Declaration
public static void IsTrue(bool condition)
Parameters
Type Name Description
bool condition

The condition to verify.

Exceptions
Type Condition
AssertionException

Thrown when the condition is false.

| Edit this page View Source

IsTrue(bool, string)

Verifies that the specified condition is true.

Declaration
public static void IsTrue(bool condition, string message)
Parameters
Type Name Description
bool condition

The condition to verify.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the condition is false.

| Edit this page View Source

Throws<T>(Action)

Verifies that the specified action throws an exception of the expected type.

Declaration
public static T Throws<T>(Action action) where T : Exception
Parameters
Type Name Description
Action action

The action to execute.

Returns
Type Description
T

The thrown exception.

Type Parameters
Name Description
T

The expected exception type.

Exceptions
Type Condition
AssertionException

Thrown when no exception or wrong exception type is thrown.

| Edit this page View Source

Throws<T>(Action, string)

Verifies that the specified action throws an exception of the expected type.

Declaration
public static T Throws<T>(Action action, string message) where T : Exception
Parameters
Type Name Description
Action action

The action to execute.

string message

The message to display if the assertion fails.

Returns
Type Description
T

The thrown exception.

Type Parameters
Name Description
T

The expected exception type.

Exceptions
Type Condition
AssertionException

Thrown when no exception or wrong exception type is thrown.

  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com