Class VhTestUtil
Provides test assertions that wait for a value, or check the exception an API call throws.
public static class VhTestUtil
- Inheritance
-
VhTestUtil
- Inherited Members
Remarks
A wait reads the value every 100 milliseconds until it matches or the timeout passes; a read under way is not cut by the timeout, as it may still bring the value. The caller's token ends the wait for an asynchronous read, not a synchronous factory, nor the task itself.
Methods
AssertAlreadyExistsException(Task, string?, string?)
Awaits a task that must throw what tells an object exists already (Is(Exception)), or an ApiException that names AlreadyExistsException.
public static Task<Exception> AssertAlreadyExistsException(Task task, string? message = null, string? contains = null)
Parameters
taskTaskThe task.
messagestringAdded to the failure's message, or null.
containsstringText the exception's message must hold, ignoring case, or null.
Returns
Exceptions
- VhTestUtil.AssertException
The task succeeded, or threw another kind.
- Exception
The exception's message does not hold the text.
AssertApiException(int, Task, string?, string?)
Awaits a task that must throw an ApiException with a status code.
public static Task<Exception> AssertApiException(int expectedStatusCode, Task task, string? message = null, string? contains = null)
Parameters
expectedStatusCodeintThe status code.
taskTaskThe task.
messagestringAdded to the failure's message, or null.
containsstringText the exception's message must hold, ignoring case, or null.
Returns
Exceptions
- VhTestUtil.AssertException
The task succeeded.
- Exception
The task threw with another status code or message, or threw another exception, which passes through.
AssertApiException(HttpStatusCode, Task, string?)
Awaits a task that must throw an ApiException with a status code.
public static Task<Exception> AssertApiException(HttpStatusCode expectedStatusCode, Task task, string? message = null)
Parameters
expectedStatusCodeHttpStatusCodeThe status code.
taskTaskThe task.
messagestringAdded to the failure's message, or null.
Returns
Exceptions
- VhTestUtil.AssertException
The task succeeded.
- Exception
The task threw with another status code.
AssertApiException(string, Task, string?, string?)
Awaits a task that must throw an exception of a type's name, or an ApiException that names it.
public static Task<Exception> AssertApiException(string expectedExceptionType, Task task, string? message = null, string? contains = null)
Parameters
expectedExceptionTypestringThe exception type's name.
taskTaskThe task.
messagestringAdded to the failure's message, or null.
containsstringText the exception's message must hold, ignoring case, or null.
Returns
Exceptions
- VhTestUtil.AssertException
The task succeeded, or threw another type.
- Exception
The exception's message does not hold the text.
AssertApiException<T>(Task, string?, string?)
Awaits a task that must throw an exception of a type, or an ApiException that names it; the type's simple name is compared, not its identity.
public static Task<Exception> AssertApiException<T>(Task task, string? message = null, string? contains = null)
Parameters
taskTaskThe task.
messagestringAdded to the failure's message, or null.
containsstringText the exception's message must hold, ignoring case, or null.
Returns
Type Parameters
TThe exception's type.
Exceptions
- VhTestUtil.AssertException
The task succeeded, or threw another type.
- Exception
The exception's message does not hold the text.
AssertEqualsWait<TValue>(TValue, Func<Task<TValue>>, string?, int, bool, CancellationToken)
Waits until a value read asynchronously matches, and fails when it does not by the timeout.
public static Task AssertEqualsWait<TValue>(TValue expectedValue, Func<Task<TValue>> valueFactory, string? message = null, int timeout = 5000, bool noTimeoutOnDebugger = true, CancellationToken cancellationToken = default)
Parameters
expectedValueTValueThe expected value.
valueFactoryFunc<Task<TValue>>Reads the value.
messagestringThe failure's message, or null for
Unexpected Value.timeoutintHow long to wait, in milliseconds. The default is 5000.
noTimeoutOnDebuggerbooltrue to wait a day while a debugger is attached.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that completes when the value matches.
Type Parameters
TValueThe type of the value.
Exceptions
- VhTestUtil.AssertException
The value still differs at the timeout.
- ArgumentOutOfRangeException
timeoutis negative, other than -1.- OperationCanceledException
cancellationTokenwas canceled.
AssertEqualsWait<TValue>(TValue, Func<TValue>, string?, int, bool, CancellationToken)
Waits until a value matches, and fails when it does not by the timeout.
public static Task AssertEqualsWait<TValue>(TValue expectedValue, Func<TValue> valueFactory, string? message = null, int timeout = 5000, bool noTimeoutOnDebugger = true, CancellationToken cancellationToken = default)
Parameters
expectedValueTValueThe expected value.
valueFactoryFunc<TValue>Reads the value.
messagestringThe failure's message, or null for
Unexpected Value.timeoutintHow long to wait, in milliseconds. The default is 5000.
noTimeoutOnDebuggerbooltrue to wait a day while a debugger is attached.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that completes when the value matches.
Type Parameters
TValueThe type of the value.
Exceptions
- VhTestUtil.AssertException
The value still differs at the timeout.
- ArgumentOutOfRangeException
timeoutis negative, other than -1.- OperationCanceledException
cancellationTokenwas canceled.
AssertEqualsWait<TValue>(TValue, Task<TValue>, string?, int, bool, CancellationToken)
Waits for a task, and fails when its result does not match.
public static Task AssertEqualsWait<TValue>(TValue expectedValue, Task<TValue> task, string? message = null, int timeout = 5000, bool noTimeoutOnDebugger = true, CancellationToken cancellationToken = default)
Parameters
expectedValueTValueThe expected value.
taskTask<TValue>The task.
messagestringThe failure's message, or null for
Unexpected Value.timeoutintHow long to wait, in milliseconds. The default is 5000.
noTimeoutOnDebuggerbooltrue to wait a day while a debugger is attached.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that completes when the value matches.
Type Parameters
TValueThe type of the value.
Exceptions
- VhTestUtil.AssertException
The value still differs at the timeout.
- ArgumentOutOfRangeException
timeoutis negative, other than -1.- OperationCanceledException
cancellationTokenwas canceled.
AssertNotExistsException(Task, string?, string?)
Awaits a task that must throw what tells an object was not found (Is(Exception)), or an ApiException that names NotExistsException.
public static Task<Exception> AssertNotExistsException(Task task, string? message = null, string? contains = null)
Parameters
taskTaskThe task.
messagestringAdded to the failure's message, or null.
containsstringText the exception's message must hold, ignoring case, or null.
Returns
Exceptions
- VhTestUtil.AssertException
The task succeeded, or threw another kind.
- Exception
The exception's message does not hold the text.