Show / Hide Table of Contents

Class ObjectAssertExtensions

Provides fluent assertion extension methods for all objects.

Inheritance
object
ObjectAssertExtensions
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 ObjectAssertExtensions

Methods

| Edit this page View Source

ShouldBeFalse(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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

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