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
exceptionTypeTypeThe type of the exception expected to be thrown
testCodeActionA 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
exceptionTypeTypeThe type of the exception expected to be thrown
testCodeFunc<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
Returns
- Task<T>
The exception that was thrown, when successful
Type Parameters
TThe 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
testCodeActionA delegate to the code to be tested
Returns
- T
The exception that was thrown, when successful
Type Parameters
TThe 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
Returns
- T
The exception that was thrown, when successful
Type Parameters
TThe 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
exceptionTypeTypeThe type of the exception expected to be thrown
testCodeFunc<Task>A delegate to the task to be tested
Returns
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
Returns
- Task<T>
The exception that was thrown, when successful
Type Parameters
TThe 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
paramNamestringThe parameter name that is expected to be in the exception
testCodeFunc<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
testCodeActionA delegate to the code to be tested
Returns
- T
The exception that was thrown, when successful
Type Parameters
TThe 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
Returns
- T
The exception that was thrown, when successful
Type Parameters
TThe 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
paramNamestringThe parameter name that is expected to be in the exception
testCodeActionA 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
paramNamestringThe parameter name that is expected to be in the exception
testCodeFunc<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.