Class ObjectAssertExtensions
Provides fluent assertion extension methods for all objects.
Inherited Members
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class ObjectAssertExtensions
Methods
| Edit this page View SourceShouldBeFalse(bool, string)
Verifies that the boolean value is false.
Declaration
public static bool ShouldBeFalse(this bool actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | actual | The actual boolean value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| bool | The actual value for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is true. |
ShouldBeNull<T>(T?, string)
Verifies that the object is null.
Declaration
public static T? ShouldBeNull<T>(this T? actual, string message) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual object. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual object for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the object is not null. |
ShouldBeOfType<T>(object?, string)
Verifies that the object is of the specified type.
Declaration
public static T ShouldBeOfType<T>(this object? actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| object | actual | The actual object. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual object cast to the expected type for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The expected type. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the object is not of the expected type. |
ShouldBeSameAs<T>(T, T, string)
Verifies that the two object references refer to the same object.
Declaration
public static T ShouldBeSameAs<T>(this T actual, T expected, string message) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual object. |
| T | expected | The expected object reference. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual object for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the references are not the same. |
ShouldBeTrue(bool, string)
Verifies that the boolean value is true.
Declaration
public static bool ShouldBeTrue(this bool actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | actual | The actual boolean value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| bool | The actual value for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is false. |
ShouldEqual<T>(T, T, string)
Verifies that the object is equal to the expected value.
Declaration
public static T ShouldEqual<T>(this T actual, T expected, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual object. |
| T | expected | The expected value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual object for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the values are not equal. |
ShouldNotBeNull<T>(T?, string)
Verifies that the object is not null.
Declaration
public static T ShouldNotBeNull<T>(this T? actual, string message) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual object. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual object for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the object is null. |
ShouldNotBeOfType<T>(object?, string)
Verifies that the object is not of the specified type.
Declaration
public static object? ShouldNotBeOfType<T>(this object? actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| object | actual | The actual object. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| object | The actual object for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type that the object should not be. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the object is of the specified type. |
ShouldNotBeSameAs<T>(T, T, string)
Verifies that the two object references do not refer to the same object.
Declaration
public static T ShouldNotBeSameAs<T>(this T actual, T notExpected, string message) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual object. |
| T | notExpected | The object reference that should not match. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual object for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the references are the same. |
ShouldNotEqual<T>(T, T, string)
Verifies that the object is not equal to the specified value.
Declaration
public static T ShouldNotEqual<T>(this T actual, T notExpected, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual object. |
| T | notExpected | The value that should not match. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual object for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the values are equal. |
ShouldNotThrow(Action, string)
Verifies that the action does not throw any exception.
Declaration
public static Action ShouldNotThrow(this Action action, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | action | The action to execute. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| Action | The action for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when an exception is thrown. |
ShouldThrow<T>(Action, string)
Verifies that the action throws an exception of the specified type.
Declaration
public static T ShouldThrow<T>(this 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 for further verification. |
Type Parameters
| Name | Description |
|---|---|
| T | The expected exception type. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when no exception or wrong exception type is thrown. |