次の方法で共有


Assert.Throws Method

Definition

Overloads

Throws<TException>(Action, Assert.AssertNonStrictThrowsInterpolatedStringHandler<TException>)

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.

Throws<TException>(Action, 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.

Throws<TException>(Action, 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.

Throws<TException>(Action, Assert.AssertNonStrictThrowsInterpolatedStringHandler<TException>)

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 TException Throws<TException> (Action action, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertNonStrictThrowsInterpolatedStringHandler<TException> message) where TException : Exception;
static member Throws : Action * AssertNonStrictThrowsInterpolatedStringHandler -> 'Exception (requires 'Exception :> Exception)
Public Shared Function Throws(Of TException As Exception) (action As Action, ByRef message As Assert.AssertNonStrictThrowsInterpolatedStringHandler(Of TException)) As TException

Type Parameters

TException

The type of exception expected to be thrown.

Parameters

action
Action

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

message
Assert.AssertNonStrictThrowsInterpolatedStringHandler<TException>

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

Returns

TException

The exception that was thrown.

Applies to

Throws<TException>(Action, 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 TException Throws<TException> (Action action, Func<Exception?,string> messageBuilder) where TException : Exception;
static member Throws : Action * Func<Exception, string> -> 'Exception (requires 'Exception :> Exception)
Public Shared Function Throws(Of TException As Exception) (action As Action, messageBuilder As Func(Of Exception, String)) As TException

Type Parameters

TException

The type of exception expected to be thrown.

Parameters

action
Action

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

TException

The exception that was thrown.

Exceptions

Thrown if action does not throws exception of type TException.

Applies to

Throws<TException>(Action, 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 TException Throws<TException> (Action action, string message = "", params object[] messageArgs) where TException : Exception;
static member Throws : Action * string * obj[] -> 'Exception (requires 'Exception :> Exception)
Public Shared Function Throws(Of TException As Exception) (action As Action, Optional message As String = "", ParamArray messageArgs As Object()) As TException

Type Parameters

TException

The type of exception expected to be thrown.

Parameters

action
Action

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

TException

The exception that was thrown.

Exceptions

Thrown if action does not throws exception of type TException.

Applies to