Class ExceptionAssertExtensions
Defines a code assertion helper for exception-based scenarios.
public static class ExceptionAssertExtensions
- Inheritance
-
ExceptionAssertExtensions
- Inherited Members
Methods
ShouldNotThrow(Action)
Tests whether the specified action does not throw any exception and throws an assertion exception if it does.
public static void ShouldNotThrow(this Action action)
Parameters
actionActionThe action to execute.
Exceptions
- AssertFailedException
Thrown if the
actionthrows an exception.
ShouldNotThrowAsync(Func<Task>)
Tests whether the specified asynchronous action does not throw any exception and throws an assertion exception if it does.
public static Task ShouldNotThrowAsync(this Func<Task> action)
Parameters
Returns
Exceptions
- AssertFailedException
Thrown if the
actionthrows an exception.
ShouldThrowAsync<TException>(Func<Task>)
Tests whether the specified asynchronous action throws an exception of the given type and throws an assertion exception if it does not.
public static Task<TException> ShouldThrowAsync<TException>(this Func<Task> action) where TException : Exception
Parameters
Returns
- Task<TException>
The exception that was thrown.
Type Parameters
TExceptionThe type of exception expected to be thrown.
Exceptions
- AssertFailedException
Thrown if the
actiondoes not throw an exception of typeTException.
ShouldThrow<TException>(Action)
Tests whether the specified action throws an exception of the given type and throws an assertion exception if it does not.
public static TException ShouldThrow<TException>(this Action action) where TException : Exception
Parameters
actionActionThe action to execute.
Returns
- TException
The exception that was thrown.
Type Parameters
TExceptionThe type of exception expected to be thrown.
Exceptions
- AssertFailedException
Thrown if the
actiondoes not throw an exception of typeTException.