Assert.ThrowsAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ThrowsAsync<TException>(Func<Task>, Func<Exception,String>) |
Asserts that the delegate |
ThrowsAsync<TException>(Func<Task>, String, Object[]) |
Asserts that the delegate |
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
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
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
- 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
The exception that was thrown.
Exceptions
Thrown if action
does not throws exception of type TException
.
Applies to
.NET