Class AssertThat
Provides static methods for making assertions in tests with descriptive failure messages.
Inherited Members
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class AssertThat
Methods
| Edit this page View SourceAreEqual<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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |