Class AsyncAssert
Truly awaitable exception assertions for async code under test.
Inherited Members
Namespace: Serenity.Tests.Shared
Assembly: Tests.dll
Syntax
public static class AsyncAssert
Remarks
NUnit's Assert.ThrowsAsync/Assert.CatchAsync/Assert.DoesNotThrowAsync
block the calling thread while waiting for the delegate's task (sync-over-async). Under
Unity's single-threaded synchronization context that blocks the main thread — so any tested
delegate that actually YIELDS (a Task.Delay, a timeout, real asynchronous I/O)
deadlocks the editor: the continuation needs the main thread the assert is blocking. These
helpers await the delegate instead and never block; call them with await from a test
declared public async Task.
Methods
CatchAsync<TException>(Func<Task>, string)
Asserts that awaiting action throws TException
or a derived type (matching NUnit's Assert.CatchAsync semantics).
Declaration
public static Task<TException> CatchAsync<TException>(Func<Task> action, string message = null) where TException : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Task> | action | The asynchronous code expected to throw. |
| string | message | Optional context appended to the failure message. |
Returns
| Type | Description |
|---|---|
| Task<TException> | The caught exception, for further asserts. |
Type Parameters
| Name | Description |
|---|---|
| TException |
DoesNotThrowAsync(Func<Task>, string)
Asserts that awaiting action completes without throwing.
Declaration
public static Task DoesNotThrowAsync(Func<Task> action, string message = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Task> | action | The asynchronous code expected NOT to throw. |
| string | message | Optional context appended to the failure message. |
Returns
| Type | Description |
|---|---|
| Task |
ThrowsAsync<TException>(Func<Task>, string)
Asserts that awaiting action throws EXACTLY
TException (derived types fail, matching NUnit's
Assert.ThrowsAsync semantics).
Declaration
public static Task<TException> ThrowsAsync<TException>(Func<Task> action, string message = null) where TException : Exception
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Task> | action | The asynchronous code expected to throw. |
| string | message | Optional context appended to the failure message. |
Returns
| Type | Description |
|---|---|
| Task<TException> | The caught exception, for further asserts. |
Type Parameters
| Name | Description |
|---|---|
| TException |