Class TestResponder
Contains extension methods on ITestResponder<T>.
Namespace: Responsible
Assembly: Responsible.dll
Syntax
public static class TestResponder
Methods
BoxResult<T>(ITestResponder<T>)
Converts a test responder returning a value type into one returning the same value boxed into Object. Can be useful for example in conjunction with RespondToAllOf<T>(ITestResponder<T>[])
Declaration
[Pure]
public static ITestResponder<object> BoxResult<T>(this ITestResponder<T> responder)
where T : struct
Parameters
Type | Name | Description |
---|---|---|
ITestResponder<T> | responder | Test responder to wrap. |
Returns
Type | Description |
---|---|
ITestResponder<Object> | A test responder which behaves otherwise identically to |
Type Parameters
Name | Description |
---|---|
T | Return type of the responder to convert. |
ExpectWithinSeconds<T>(ITestResponder<T>, Double, String, String, Int32)
Constructs a test instruction, which will expect the provided responder to start responding within the provided timeout, and then continue executing the instruction of the responder. If the condition isn't met within the timeout, the instruction will complete with an error.
Declaration
[Pure]
public static ITestInstruction<T> ExpectWithinSeconds<T>(this ITestResponder<T> responder, double timeoutSeconds, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
ITestResponder<T> | responder | Responder to apply the timeout to. |
Double | timeoutSeconds | Timeout for the responder to start responding, in seconds. |
String | memberName | Caller member name provided by compiler. May be overridden for custom operators. |
String | sourceFilePath | Caller file path provided by compiler. May be overridden for custom operators. |
Int32 | sourceLineNumber | Source line number provided by compiler. May be overridden for custom operators. |
Returns
Type | Description |
---|---|
ITestInstruction<T> | A test instruction which completes with the result of the responder, or a failure, if either the timeout is met or the responder otherwise fails. |
Type Parameters
Name | Description |
---|---|
T | Result type of the responder and the returned test instruction. |
Remarks
The timeout for the complete operation will be the sum of the given timeout and the timeout of the instruction part of the responder.
Optionally<T>(ITestResponder<T>)
Converts a test responder to an optional test responder. An alias for RespondToAnyOf<T>(ITestResponder<T>[]) with a single argument.
Declaration
[Pure]
public static IOptionalTestResponder Optionally<T>(this ITestResponder<T> responder)
Parameters
Type | Name | Description |
---|---|---|
ITestResponder<T> | responder | Responder to convert to an optional responder. |
Returns
Type | Description |
---|---|
IOptionalTestResponder | An optional responder, which optionally responds to |
Type Parameters
Name | Description |
---|---|
T | Result type of the responder, which is discarded by the returned optional responder. |
Repeatedly<T>(ITestResponder<T>, Int32, String, String, Int32)
Converts a test responder to an optional test responder which repeatedly executes the responder, zero or more times.
Declaration
[Pure]
public static IOptionalTestResponder Repeatedly<T>(this ITestResponder<T> respondTo, int maximumRepeatCount, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
ITestResponder<T> | respondTo | Responder to convert to a repeated responder. |
Int32 | maximumRepeatCount | Maximum number of times this responder is allowed to be executed. If this count is exceeded, the operation will fail. |
String | memberName | Caller member name provided by compiler. May be overridden for custom operators. |
String | sourceFilePath | Caller file path provided by compiler. May be overridden for custom operators. |
Int32 | sourceLineNumber | Source line number provided by compiler. May be overridden for custom operators. |
Returns
Type | Description |
---|---|
IOptionalTestResponder | An optional responder, which repeatedly responds to |
Type Parameters
Name | Description |
---|---|
T | Result type of the responder, which is discarded by the returned optional responder. |
Remarks
Unless this is the intended behaviour,
make sure that the responder is not synchronously ready to execute after finishing,
as otherwise it will execute again in the same frame.
The maximumRepeatCount
parameter is non-optional,
in order to bail out of these situations faster, as timeouts do not apply within a single frame
(the timeout mechanism might be improved later, but is currently not trivial to do).
Select<T1, T2>(ITestResponder<T1>, Func<T1, T2>, String, String, Int32)
Applies a selector to the result of a test responder when the responder completes, transforming the result type to another type.
Declaration
[Pure]
public static ITestResponder<T2> Select<T1, T2>(this ITestResponder<T1> responder, Func<T1, T2> selector, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
ITestResponder<T1> | responder | A test responder to apply the selector to. |
Func<T1, T2> | selector | A function to apply to the result of the responder. |
String | memberName | Caller member name provided by compiler. May be overridden for custom operators. |
String | sourceFilePath | Caller file path provided by compiler. May be overridden for custom operators. |
Int32 | sourceLineNumber | Source line number provided by compiler. May be overridden for custom operators. |
Returns
Type | Description |
---|---|
ITestResponder<T2> | A test responder whose result is the result of invoking
|
Type Parameters
Name | Description |
---|---|
T1 | Return type of the initial responder. |
T2 | Return type of the selector and the returned responder. |