Class Assert
The Assert class contains a collection of static methods that implement the most common assertions used in NUnit.
Inherited Members
Namespace: NUnit.Framework
Assembly: nunit.framework.dll
Syntax
public abstract class Assert : AssertBase
Constructors
View SourceAssert()
Declaration
protected Assert()
Methods
View SourceByVal(object?, IResolveConstraint, string, string, string)
Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert block. Used as a synonym for That in rare cases where a private setter causes a Visual Basic compilation error.
Declaration
public static void ByVal(object? actual, IResolveConstraint expression, string message = "", string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| object | actual | The actual value to test |
| IResolveConstraint | expression | A Constraint expression to be applied |
| string | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
Remarks
This method is provided for use by VB developers needing to test the value of properties with private setters.
Catch(TestDelegate)
Verifies that a delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? Catch(TestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| Exception |
Catch(TestDelegate, string, params object?[]?)
Verifies that a delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? Catch(TestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| Exception |
Catch(Type, TestDelegate)
Verifies that a delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? Catch(Type expectedExceptionType, TestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | expectedExceptionType | The expected Exception Type |
| TestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| Exception |
Catch(Type, TestDelegate, string, params object?[]?)
Verifies that a delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? Catch(Type expectedExceptionType, TestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | expectedExceptionType | The expected Exception Type |
| TestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| Exception |
CatchAsync(AsyncTestDelegate)
Verifies that an async delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? CatchAsync(AsyncTestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| Exception |
CatchAsync(AsyncTestDelegate, string, params object?[]?)
Verifies that an async delegate throws an exception when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? CatchAsync(AsyncTestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| Exception |
CatchAsync(Type, AsyncTestDelegate)
Verifies that an async delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? CatchAsync(Type expectedExceptionType, AsyncTestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | expectedExceptionType | The expected Exception Type |
| AsyncTestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| Exception |
CatchAsync(Type, AsyncTestDelegate, string, params object?[]?)
Verifies that an async delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? CatchAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | expectedExceptionType | The expected Exception Type |
| AsyncTestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| Exception |
CatchAsync<TActual>(AsyncTestDelegate)
Verifies that an async delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static TActual? CatchAsync<TActual>(AsyncTestDelegate code) where TActual : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| TActual |
Type Parameters
| Name | Description |
|---|---|
| TActual |
CatchAsync<TActual>(AsyncTestDelegate, string, params object?[]?)
Verifies that an async delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static TActual? CatchAsync<TActual>(AsyncTestDelegate code, string message, params object?[]? args) where TActual : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| TActual |
Type Parameters
| Name | Description |
|---|---|
| TActual |
Catch<TActual>(TestDelegate)
Verifies that a delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static TActual? Catch<TActual>(TestDelegate code) where TActual : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| TActual |
Type Parameters
| Name | Description |
|---|---|
| TActual |
Catch<TActual>(TestDelegate, string, params object?[]?)
Verifies that a delegate throws an exception of a certain Type or one derived from it when called and returns it. The returned exception may be null when inside a multiple assert block.
Declaration
public static TActual? Catch<TActual>(TestDelegate code, string message, params object?[]? args) where TActual : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| TActual |
Type Parameters
| Name | Description |
|---|---|
| TActual |
Charlie()
An alias of the corresponding Assert.Pass() method. Charlie Poole was the lead of NUnit for 21 years, across at least 207 releases in 37 different repositories, authoring 4,898 commits across them. He participated in 2,990 issues, 1,305 PRs, and impacted 6,992,983 lines of code. NUnit was downloaded from NuGet 225+ million times during his tenure. And those are only the numbers ones we can easily find; our numbers are sourced from after NUnit moved the project to GitHub in 2011, which means there are at least 9 additional years of work not quantified above.
This assertion attempts to pay homage to Charlie, who by virtue of his contributions has helped untold millions of tests pass.
Declaration
public static void Charlie()
DoesNotThrow(TestDelegate)
Verifies that a delegate does not throw an exception.
Declaration
public static void DoesNotThrow(TestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate |
DoesNotThrow(TestDelegate, string, params object?[]?)
Verifies that a delegate does not throw an exception
Declaration
public static void DoesNotThrow(TestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
DoesNotThrowAsync(AsyncTestDelegate)
Verifies that an async delegate does not throw an exception.
Declaration
public static void DoesNotThrowAsync(AsyncTestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | A TestDelegate |
DoesNotThrowAsync(AsyncTestDelegate, string, params object?[]?)
Verifies that an async delegate does not throw an exception
Declaration
public static void DoesNotThrowAsync(AsyncTestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
EnterMultipleScope()
Enters a multiple assert scope. Wraps code containing a series of assertions, which should all be executed, even if they fail. Failed results are saved and reported when the returned IDisposable is disposed.
Declaration
public static IDisposable EnterMultipleScope()
Returns
| Type | Description |
|---|---|
| IDisposable | An IDisposable which when disposed leaves the multiple assertion scope. |
Fail()
Marks the test as failed. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void Fail()
Fail(string)
Marks the test as failed with the message and arguments that are passed in. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void Fail(string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The message to initialize the AssertionException with. |
Ignore()
Throws an IgnoreException. This causes the test to be reported as ignored.
Declaration
public static void Ignore()
Ignore(string)
Throws an IgnoreException with the message and arguments that are passed in. This causes the test to be reported as ignored.
Declaration
public static void Ignore(string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The message to initialize the AssertionException with. |
Inconclusive()
Throws an InconclusiveException. This causes the test to be reported as Inconclusive.
Declaration
public static void Inconclusive()
Inconclusive(string)
Throws an InconclusiveException with the message and arguments that are passed in. This causes the test to be reported as inconclusive.
Declaration
public static void Inconclusive(string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The message to initialize the InconclusiveException with. |
Multiple(AsyncTestDelegate)
Wraps code containing a series of assertions, which should all be executed, even if they fail. Failed results are saved and reported at the end of the code block.
Declaration
public static void Multiple(AsyncTestDelegate testDelegate)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | testDelegate | A TestDelegate to be executed in Multiple Assertion mode. |
Multiple(TestDelegate)
Wraps code containing a series of assertions, which should all be executed, even if they fail. Failed results are saved and reported at the end of the code block.
Declaration
public static void Multiple(TestDelegate testDelegate)
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | testDelegate | A TestDelegate to be executed in Multiple Assertion mode. |
MultipleAsync(AsyncTestDelegate)
Wraps code containing a series of assertions, which should all be executed, even if they fail. Failed results are saved and reported at the end of the code block.
Declaration
public static Task MultipleAsync(AsyncTestDelegate testDelegate)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | testDelegate | An AsyncTestDelegate to be executed in Multiple Assertion mode. |
Returns
| Type | Description |
|---|---|
| Task |
Pass()
Throws a SuccessException with the message and arguments that are passed in. This allows a test to be cut short, with a result of success returned to NUnit.
Declaration
public static void Pass()
Pass(string)
Throws a SuccessException with the message and arguments that are passed in. This allows a test to be cut short, with a result of success returned to NUnit.
Declaration
public static void Pass(string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The message to initialize the AssertionException with. |
That(TestDelegate, IResolveConstraint, NUnitString, string, string)
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That(TestDelegate code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate to be executed |
| IResolveConstraint | constraint | A Constraint expression to be applied |
| NUnitString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
That(TestDelegate, IResolveConstraint, FormattableString, string, string)
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That(TestDelegate code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate to be executed |
| IResolveConstraint | constraint | A Constraint expression to be applied |
| FormattableString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
That(TestDelegate, IResolveConstraint, Func<string>, string, string)
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That(TestDelegate code, IResolveConstraint constraint, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate to be executed |
| IResolveConstraint | constraint | A Constraint expression to be applied |
| Func<string> | getExceptionMessage | A function to build the message included with the Exception |
| string | actualExpression | |
| string | constraintExpression |
That(bool, NUnitString, string)
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That(bool condition, NUnitString message = default, string actualExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | condition | The evaluated condition |
| NUnitString | message | The message to display if the condition is false |
| string | actualExpression |
That(bool, FormattableString, string)
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That(bool condition, FormattableString message, string actualExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | condition | The evaluated condition |
| FormattableString | message | The message to display if the condition is false |
| string | actualExpression |
That(bool, Func<string>, string)
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That(bool condition, Func<string> getExceptionMessage, string actualExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| bool | condition | The evaluated condition |
| Func<string> | getExceptionMessage | A function to build the message included with the Exception |
| string | actualExpression |
That(Func<bool>, NUnitString, string)
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That(Func<bool> condition, NUnitString message = default, string actualExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| Func<bool> | condition | A lambda that returns a Boolean |
| NUnitString | message | The message to display if the condition is false |
| string | actualExpression |
That(Func<bool>, FormattableString, string)
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That(Func<bool> condition, FormattableString message, string actualExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| Func<bool> | condition | A lambda that returns a Boolean |
| FormattableString | message | The message to display if the condition is false |
| string | actualExpression |
That(Func<bool>, Func<string>, string)
Asserts that a condition is true. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That(Func<bool> condition, Func<string> getExceptionMessage, string actualExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| Func<bool> | condition | A lambda that returns a Boolean |
| Func<string> | getExceptionMessage | A function to build the message included with the Exception |
| string | actualExpression |
ThatAsync(AsyncTestDelegate, IResolveConstraint, NUnitString, string, string)
Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static Task ThatAsync(AsyncTestDelegate code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | An AsyncTestDelegate to be executed |
| IResolveConstraint | constraint | A Constraint expression to be applied |
| NUnitString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
Returns
| Type | Description |
|---|---|
| Task | Awaitable. |
ThatAsync(AsyncTestDelegate, IResolveConstraint, FormattableString, string, string)
Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static Task ThatAsync(AsyncTestDelegate code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | An AsyncTestDelegate to be executed |
| IResolveConstraint | constraint | A Constraint expression to be applied |
| FormattableString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
Returns
| Type | Description |
|---|---|
| Task | Awaitable. |
ThatAsync<T>(Func<Task<T>>, IResolveConstraint, NUnitString, string, string)
Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static Task ThatAsync<T>(Func<Task<T>> code, IResolveConstraint constraint, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Task<T>> | code | An async method to be executed |
| IResolveConstraint | constraint | A Constraint expression to be applied |
| NUnitString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
Returns
| Type | Description |
|---|---|
| Task | Awaitable. |
Type Parameters
| Name | Description |
|---|---|
| T |
ThatAsync<T>(Func<Task<T>>, IResolveConstraint, FormattableString, string, string)
Apply a constraint to an async delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static Task ThatAsync<T>(Func<Task<T>> code, IResolveConstraint constraint, FormattableString message, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Task<T>> | code | An async method to be executed |
| IResolveConstraint | constraint | A Constraint expression to be applied |
| FormattableString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
Returns
| Type | Description |
|---|---|
| Task | Awaitable. |
Type Parameters
| Name | Description |
|---|---|
| T |
That<TActual>(ActualValueDelegate<TActual>, IResolveConstraint, NUnitString, string, string)
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| ActualValueDelegate<TActual> | del | An ActualValueDelegate returning the value to be tested |
| IResolveConstraint | expr | A Constraint expression to be applied |
| NUnitString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
Type Parameters
| Name | Description |
|---|---|
| TActual | The Type being compared. |
That<TActual>(ActualValueDelegate<TActual>, IResolveConstraint, FormattableString, string, string)
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, FormattableString message, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| ActualValueDelegate<TActual> | del | An ActualValueDelegate returning the value to be tested |
| IResolveConstraint | expr | A Constraint expression to be applied |
| FormattableString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
Type Parameters
| Name | Description |
|---|---|
| TActual | The Type being compared. |
That<TActual>(ActualValueDelegate<TActual>, IResolveConstraint, Func<string>, string, string)
Apply a constraint to a delegate. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| ActualValueDelegate<TActual> | del | An ActualValueDelegate returning the value to be tested |
| IResolveConstraint | expr | A Constraint expression to be applied |
| Func<string> | getExceptionMessage | A function to build the message included with the Exception |
| string | actualExpression | |
| string | constraintExpression |
Type Parameters
| Name | Description |
|---|---|
| TActual | The Type being compared. |
That<TActual>(TActual, IResolveConstraint, NUnitString, string, string)
Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That<TActual>(TActual actual, IResolveConstraint expression, NUnitString message = default, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| TActual | actual | The actual value to test |
| IResolveConstraint | expression | A Constraint expression to be applied |
| NUnitString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
Type Parameters
| Name | Description |
|---|---|
| TActual | The Type being compared. |
That<TActual>(TActual, IResolveConstraint, FormattableString, string, string)
Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That<TActual>(TActual actual, IResolveConstraint expression, FormattableString message, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| TActual | actual | The actual value to test |
| IResolveConstraint | expression | A Constraint expression to be applied |
| FormattableString | message | The message that will be displayed on failure |
| string | actualExpression | |
| string | constraintExpression |
Type Parameters
| Name | Description |
|---|---|
| TActual | The Type being compared. |
That<TActual>(TActual, IResolveConstraint, Func<string>, string, string)
Apply a constraint to an actual value. Returns without throwing an exception when inside a multiple assert block.
Declaration
public static void That<TActual>(TActual actual, IResolveConstraint expression, Func<string> getExceptionMessage, string actualExpression = "", string constraintExpression = "")
Parameters
| Type | Name | Description |
|---|---|---|
| TActual | actual | The actual value to test |
| IResolveConstraint | expression | A Constraint expression to be applied |
| Func<string> | getExceptionMessage | A function to build the message included with the Exception |
| string | actualExpression | |
| string | constraintExpression |
Type Parameters
| Name | Description |
|---|---|
| TActual | The Type being compared. |
Throws(IResolveConstraint, TestDelegate)
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? Throws(IResolveConstraint expression, TestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| IResolveConstraint | expression | A constraint to be satisfied by the exception |
| TestDelegate | code | A TestSnippet delegate |
Returns
| Type | Description |
|---|---|
| Exception |
Throws(IResolveConstraint, TestDelegate, string, params object?[]?)
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? Throws(IResolveConstraint expression, TestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| IResolveConstraint | expression | A constraint to be satisfied by the exception |
| TestDelegate | code | A TestSnippet delegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| Exception |
Throws(Type, TestDelegate)
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? Throws(Type expectedExceptionType, TestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | expectedExceptionType | The exception Type expected |
| TestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| Exception |
Throws(Type, TestDelegate, string, params object?[]?)
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? Throws(Type expectedExceptionType, TestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | expectedExceptionType | The exception Type expected |
| TestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| Exception |
ThrowsAsync(IResolveConstraint, AsyncTestDelegate)
Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| IResolveConstraint | expression | A constraint to be satisfied by the exception |
| AsyncTestDelegate | code | A TestSnippet delegate |
Returns
| Type | Description |
|---|---|
| Exception |
ThrowsAsync(IResolveConstraint, AsyncTestDelegate, string, params object?[]?)
Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| IResolveConstraint | expression | A constraint to be satisfied by the exception |
| AsyncTestDelegate | code | A TestSnippet delegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| Exception |
ThrowsAsync(Type, AsyncTestDelegate)
Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | expectedExceptionType | The exception Type expected |
| AsyncTestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| Exception |
ThrowsAsync(Type, AsyncTestDelegate, string, params object?[]?)
Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static Exception? ThrowsAsync(Type expectedExceptionType, AsyncTestDelegate code, string message, params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | expectedExceptionType | The exception Type expected |
| AsyncTestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| Exception |
ThrowsAsync<TActual>(AsyncTestDelegate)
Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static TActual? ThrowsAsync<TActual>(AsyncTestDelegate code) where TActual : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| TActual |
Type Parameters
| Name | Description |
|---|---|
| TActual | Type of the expected exception |
ThrowsAsync<TActual>(AsyncTestDelegate, string, params object?[]?)
Verifies that an async delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static TActual? ThrowsAsync<TActual>(AsyncTestDelegate code, string message, params object?[]? args) where TActual : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncTestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| TActual |
Type Parameters
| Name | Description |
|---|---|
| TActual | Type of the expected exception |
Throws<TActual>(TestDelegate)
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static TActual? Throws<TActual>(TestDelegate code) where TActual : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate |
Returns
| Type | Description |
|---|---|
| TActual |
Type Parameters
| Name | Description |
|---|---|
| TActual | Type of the expected exception |
Throws<TActual>(TestDelegate, string, params object?[]?)
Verifies that a delegate throws a particular exception when called. The returned exception may be null when inside a multiple assert block.
Declaration
public static TActual? Throws<TActual>(TestDelegate code, string message, params object?[]? args) where TActual : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| TestDelegate | code | A TestDelegate |
| string | message | The message that will be displayed on failure |
| object[] | args | Arguments to be used in formatting the message |
Returns
| Type | Description |
|---|---|
| TActual |
Type Parameters
| Name | Description |
|---|---|
| TActual | Type of the expected exception |
Warn(string)
Issues a warning using the message and arguments provided.
Declaration
public static void Warn(string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | message | The message to display. |