Method Throws
- Namespace
- Xunit
- Assembly
- xunit.v3.assert.dll
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
Throws(Type, Action, Func<Exception, string?>)
Verifies that the exact exception is thrown (and not a derived exception type).
public static Exception Throws(Type exceptionType, Action testCode, Func<Exception, string?> inspector)
Parameters
exceptionTypeTypeThe type of the exception expected to be thrown
testCodeActionA delegate to the code to be tested
inspectorFunc<Exception, string>A function which inspects the exception to determine if it's valid or not. Returns
nullif the exception is valid, or a message if it's not.
Returns
- Exception
The exception that was thrown, when successful
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
Throws(Type, Func<object?>, Func<Exception, string?>)
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, Func<Exception, string?> inspector)
Parameters
exceptionTypeTypeThe type of the exception expected to be thrown
testCodeFunc<object>A delegate to the code to be tested
inspectorFunc<Exception, string>A function which inspects the exception to determine if it's valid or not. Returns
nullif the exception is valid, or a message if it's not.
Returns
- Exception
The exception that was thrown, when successful
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
Throws<T>(Action, Func<T, string?>)
Verifies that the exact exception is thrown (and not a derived exception type).
public static T Throws<T>(Action testCode, Func<T, string?> inspector) where T : Exception
Parameters
testCodeActionA delegate to the code to be tested
inspectorFunc<T, string>A function which inspects the exception to determine if it's valid or not. Returns
nullif the exception is valid, or a message if it's not.
Returns
- T
The exception that was thrown, when successful
Type Parameters
TThe type of the exception expected to be thrown
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
Throws<T>(Func<object?>, Func<T, string?>)
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, Func<T, string?> inspector) where T : Exception
Parameters
testCodeFunc<object>A delegate to the code to be tested
inspectorFunc<T, string>A function which inspects the exception to determine if it's valid or not. Returns
nullif the exception is valid, or a message if it's not.
Returns
- T
The exception that was thrown, when successful
Type Parameters
TThe type of the exception expected to be thrown
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
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