次の方法で共有


Assert.ThrowsAsync Method

Definition

Overloads

ThrowsAsync<TException>(Func<Task>, Func<Exception,String>)

Asserts that the delegate action throws an exception of type TException (or derived type) and throws AssertFailedException if code does not throws exception or throws exception of type other than TException.

ThrowsAsync<TException>(Func<Task>, String, Object[])

Asserts that the delegate action throws an exception of type TException (or derived type) and throws AssertFailedException if code does not throws exception or throws exception of type other than TException.

ThrowsAsync<TException>(Func<Task>, Func<Exception,String>)

Source:
Assert.ThrowsException.cs

Asserts that the delegate action throws an exception of type TException (or derived type) and throws AssertFailedException if code does not throws exception or throws exception of type other than TException.

public static System.Threading.Tasks.Task<TException> ThrowsAsync<TException> (Func<System.Threading.Tasks.Task> action, Func<Exception?,string> messageBuilder) where TException : Exception;
static member ThrowsAsync : Func<System.Threading.Tasks.Task> * Func<Exception, string> -> System.Threading.Tasks.Task<'Exception (requires 'Exception :> Exception)> (requires 'Exception :> Exception)
Public Shared Function ThrowsAsync(Of TException As Exception) (action As Func(Of Task), messageBuilder As Func(Of Exception, String)) As Task(Of TException)

Type Parameters

TException

The type of exception expected to be thrown.

Parameters

action
Func<Task>

Delegate to code to be tested and which is expected to throw exception.

messageBuilder
Func<Exception,String>

A func that takes the thrown Exception (or null if the action didn't throw any exception) to construct the message to include in the exception when action does not throws exception of type TException.

Returns

Task<TException>

The exception that was thrown.

Exceptions

Thrown if action does not throws exception of type TException.

Applies to

ThrowsAsync<TException>(Func<Task>, String, Object[])

Source:
Assert.ThrowsException.cs

Asserts that the delegate action throws an exception of type TException (or derived type) and throws AssertFailedException if code does not throws exception or throws exception of type other than TException.

public static System.Threading.Tasks.Task<TException> ThrowsAsync<TException> (Func<System.Threading.Tasks.Task> action, string message = "", params object[] messageArgs) where TException : Exception;
static member ThrowsAsync : Func<System.Threading.Tasks.Task> * string * obj[] -> System.Threading.Tasks.Task<'Exception (requires 'Exception :> Exception)> (requires 'Exception :> Exception)
Public Shared Function ThrowsAsync(Of TException As Exception) (action As Func(Of Task), Optional message As String = "", ParamArray messageArgs As Object()) As Task(Of TException)

Type Parameters

TException

The type of exception expected to be thrown.

Parameters

action
Func<Task>

Delegate to code to be tested and which is expected to throw exception.

message
String

The message to include in the exception when action does not throws exception of type TException.

messageArgs
Object[]

An array of parameters to use when formatting message.

Returns

Task<TException>

The exception that was thrown.

Exceptions

Thrown if action does not throws exception of type TException.

Applies to