Skip to content

AsyncActionAssertions.ThrowAsync Method ​

Overloads ​

NameDescription
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.

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

Type Parameters ​

NameDescription
TExceptionThe 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.

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

Type Parameters ​

NameDescription
TExceptionThe expected exception type.

Parameters ​

NameTypeDescription
expectedMessageStringThe 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.

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

Type Parameters ​

NameDescription
TExceptionThe expected exception type.

Parameters ​

NameTypeDescription
expectedMessageStringThe expected exception message.
expectedInnerExceptionExceptionThe 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.

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

Type Parameters ​

NameDescription
TExceptionThe expected exception type.

Parameters ​

NameTypeDescription
expectedTExceptionThe expected exception instance.

Returns ​

Task<ActionAssertionsChain<TException>>

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