次の方法で共有


Assert.ThrowsExactly Method

Definition

Overloads

ThrowsExactly<TException>(Action, String, Object[])

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

ThrowsExactly<TException>(Action, Func<Exception,String>)

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

ThrowsExactly<TException>(Action, Assert.AssertThrowsExactlyInterpolatedStringHandler<TException>)

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

ThrowsExactly<TException>(Action, String, Object[])

Source:
Assert.ThrowsException.cs

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

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

ThrowsExactly<TException>(Action, Func<Exception,String>)

Source:
Assert.ThrowsException.cs

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

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

ThrowsExactly<TException>(Action, Assert.AssertThrowsExactlyInterpolatedStringHandler<TException>)

Source:
Assert.ThrowsException.cs

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

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