Table of Contents

Class ExceptionAsserts

Namespace
Asserts
Assembly
xunit.v3.assert.dll
public class ExceptionAsserts
Inheritance
ExceptionAsserts
Inherited Members

Methods

Throws(Type, Action)

Verifies that the exact exception is thrown (and not a derived exception type).

public static Exception Throws(Type exceptionType, Action testCode)

Parameters

exceptionType Type

The type of the exception expected to be thrown

testCode Action

A delegate to the code to be tested

Returns

Exception

The exception that was thrown, when successful

Examples

Add an example for this method ?

Contribution guide.

Throws(Type, Func<object?>)

Verifies that the exact exception is thrown (and not a derived exception type). Generally used to test property accessors.

public static Exception Throws(Type exceptionType, Func<object?> testCode)

Parameters

exceptionType Type

The type of the exception expected to be thrown

testCode Func<object>

A delegate to the code to be tested

Returns

Exception

The exception that was thrown, when successful

Examples

Add an example for this method ?

Contribution guide.

ThrowsAnyAsync<T>(Func<Task>)

Verifies that the exact exception or a derived exception type is thrown.

public static Task<T> ThrowsAnyAsync<T>(Func<Task> testCode) where T : Exception

Parameters

testCode Func<Task>

A delegate to the task to be tested

Returns

Task<T>

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

Examples

Add an example for this method ?

Contribution guide.

ThrowsAny<T>(Action)

Verifies that the exact exception or a derived exception type is thrown.

public static T ThrowsAny<T>(Action testCode) where T : Exception

Parameters

testCode Action

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

Examples

Add an example for this method ?

Contribution guide.

ThrowsAny<T>(Func<object?>)

Verifies that the exact exception or a derived exception type is thrown. Generally used to test property accessors.

public static T ThrowsAny<T>(Func<object?> testCode) where T : Exception

Parameters

testCode Func<object>

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

Examples

Add an example for this method ?

Contribution guide.

ThrowsAsync(Type, Func<Task>)

Verifies that the exact exception is thrown (and not a derived exception type).

public static Task<Exception> ThrowsAsync(Type exceptionType, Func<Task> testCode)

Parameters

exceptionType Type

The type of the exception expected to be thrown

testCode Func<Task>

A delegate to the task to be tested

Returns

Task<Exception>

The exception that was thrown, when successful

Examples

Add an example for this method ?

Contribution guide.

ThrowsAsync<T>(Func<Task>)

Verifies that the exact exception is thrown (and not a derived exception type).

public static Task<T> ThrowsAsync<T>(Func<Task> testCode) where T : Exception

Parameters

testCode Func<Task>

A delegate to the task to be tested

Returns

Task<T>

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

Examples

Add an example for this method ?

Contribution guide.

ThrowsAsync<T>(string?, Func<Task>)

Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from ArgumentException and has the given parameter name.

public static Task<T> ThrowsAsync<T>(string? paramName, Func<Task> testCode) where T : ArgumentException

Parameters

paramName string

The parameter name that is expected to be in the exception

testCode Func<Task>

A delegate to the task to be tested

Returns

Task<T>

The exception that was thrown, when successful

Type Parameters

T

Examples

Add an example for this method ?

Contribution guide.

Throws<T>(Action)

Verifies that the exact exception is thrown (and not a derived exception type).

public static T Throws<T>(Action testCode) where T : Exception

Parameters

testCode Action

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

Examples

Add an example for this method ?

Contribution guide.

Throws<T>(Func<object?>)

Verifies that the exact exception is thrown (and not a derived exception type). Generally used to test property accessors.

public static T Throws<T>(Func<object?> testCode) where T : Exception

Parameters

testCode Func<object>

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

The type of the exception expected to be thrown

Examples

Add an example for this method ?

Contribution guide.

Throws<T>(string?, Action)

Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from ArgumentException and has the given parameter name.

public static T Throws<T>(string? paramName, Action testCode) where T : ArgumentException

Parameters

paramName string

The parameter name that is expected to be in the exception

testCode Action

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

Examples

Add an example for this method ?

Contribution guide.

Throws<T>(string?, Func<object?>)

Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from ArgumentException and has the given parameter name.

public static T Throws<T>(string? paramName, Func<object?> testCode) where T : ArgumentException

Parameters

paramName string

The parameter name that is expected to be in the exception

testCode Func<object>

A delegate to the code to be tested

Returns

T

The exception that was thrown, when successful

Type Parameters

T

Examples

Add an example for this method ?

Contribution guide.