Skip to content

AsyncActionAssertions.ThrowAsync Method

Overloads

Name Description
ThrowAsync<TException>() Asserts that the async action throws an exception of the specified type.
ThrowAsync<TException>(String) Asserts that the async action throws an exception of the specified type with the specified message.
ThrowAsync<TException>(String, Exception) Asserts that the async action throws an exception of the specified type with the specified message and inner exception.
ThrowAsync<TException>(TException) Asserts that the async action throws the exact specified exception instance.

ThrowAsync<TException>()

Asserts that the async action throws an exception of the specified type.

public Task<ActionAssertionsChain<TException>> ThrowAsync<TException>()
   where TException : Exception;

Type Parameters

Name Description
TException The expected exception type.

Returns

Task<ActionAssertionsChain<TException>>

A Task<TResult> that resolves to an ActionAssertionsChain<TException> containing the thrown exception.

ThrowAsync<TException>(String)

Asserts that the async action throws an exception of the specified type with the specified message.

public Task<ActionAssertionsChain<TException>> ThrowAsync<TException>(string expectedMessage)
   where TException : Exception;

Type Parameters

Name Description
TException The expected exception type.

Parameters

Name Type Description
expectedMessage String The expected exception message.

Returns

Task<ActionAssertionsChain<TException>>

A Task<TResult> that resolves to an ActionAssertionsChain<TException> containing the thrown exception.

ThrowAsync<TException>(String, Exception)

Asserts that the async action throws an exception of the specified type with the specified message and inner exception.

public Task<ActionAssertionsChain<TException>> ThrowAsync<TException>(string expectedMessage, Exception? expectedInnerException)
   where TException : Exception;

Type Parameters

Name Description
TException The expected exception type.

Parameters

Name Type Description
expectedMessage String The expected exception message.
expectedInnerException Exception The expected inner exception, or null to assert no inner exception.

Returns

Task<ActionAssertionsChain<TException>>

A Task<TResult> that resolves to an ActionAssertionsChain<TException> containing the thrown exception.

ThrowAsync<TException>(TException)

Asserts that the async action throws the exact specified exception instance.

public Task<ActionAssertionsChain<TException>> ThrowAsync<TException>(TException expected)
   where TException : Exception;

Type Parameters

Name Description
TException The expected exception type.

Parameters

Name Type Description
expected TException The expected exception instance.

Returns

Task<ActionAssertionsChain<TException>>

A Task<TResult> that resolves to an ActionAssertionsChain<TException> containing the thrown exception.