Class Responsibly
Main class for constructing primitive wait conditions and instructions, and composing responders.
Namespace: Responsible
Assembly: Responsible.dll
Syntax
public static class Responsibly
Remarks
Instead of using a class like WaitFor
, we try to avoid conflicting class names by having this class.
It also allows you to use either Responsibly.WaitForCondition
or
using static Responsible.Responsibly;
and simply WaitForCondition
.
Methods
Do(String, Action, String, String, Int32)
Execute a synchronous action safely, and return a non-null object.
Declaration
[Pure]
public static ITestInstruction<object> Do(string description, Action action, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
String | description | Description of the operation, to be included in the state output. |
Action | action | Action to call when the test instruction is executed. |
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<Object> | A test instruction which calls |
DoAndReturn<T>(String, Func<T>, String, String, Int32)
Execute a synchronous action safely, and return a result.
Declaration
[Pure]
public static ITestInstruction<T> DoAndReturn<T>(string description, Func<T> func, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
String | description | Description of the operation, to be included in the state output. |
Func<T> | func | Function to call when the test instruction is executed. |
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 calls |
Type Parameters
Name | Description |
---|---|
T | Result type of the returned test instruction and |
Remarks
This is not an overload of Do(String, Action, String, String, Int32), because C# is bad at overload resolution with lambdas.
RespondToAllOf<T>(ITestResponder<T>[])
Constructs a wait condition that will will complete once all given responders have executed. All responders are waited for concurrently, but only one will be responding at a time. Will complete with an error, if any of the responders completes with an error.
See Select<T1, T2>(ITestResponder<T1>, Func<T1, T2>, String, String, Int32) and BoxResult<T>(ITestResponder<T>) for methods which can be used to make the responder types match.
Declaration
[Pure]
public static ITestWaitCondition<T[]> RespondToAllOf<T>(params ITestResponder<T>[] responders)
Parameters
Type | Name | Description |
---|---|---|
ITestResponder<T>[] | responders | Responders to respond to. |
Returns
Type | Description |
---|---|
ITestWaitCondition<T[]> | A wait condition, which completes with the results of |
Type Parameters
Name | Description |
---|---|
T | Result type of the responders. The result of the returned wait condition is an array of this type. |
RespondToAnyOf<T>(ITestResponder<T>[])
Constructs an optional test responder, which will respond to any of the provided responders. All responders are waited for concurrently, but only one will be responding at a time. Will complete with an error, if any of the responders completes with an error.
See Select<T1, T2>(ITestResponder<T1>, Func<T1, T2>, String, String, Int32) and BoxResult<T>(ITestResponder<T>) for methods which can be used to make the responder types match.
Declaration
[Pure]
public static IOptionalTestResponder RespondToAnyOf<T>(params ITestResponder<T>[] responders)
Parameters
Type | Name | Description |
---|---|---|
ITestResponder<T>[] | responders | Responders to respond to. |
Returns
Type | Description |
---|---|
IOptionalTestResponder | Optional responder which executes the responders in |
Type Parameters
Name | Description |
---|---|
T | Result type of the responders. |
Remarks
The results of the responders are discarded, as returning them optionally is not trivial to implement. Returning the values of the completed responders is something that might be implemented in later versions of Responsible.
Return<T>(T, String, String, Int32)
Constructs a test instruction that returns a value synchronously.
Declaration
[Pure]
public static ITestInstruction<T> Return<T>(T value, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
T | value | Value to return from the test instruction. |
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 returning |
Type Parameters
Name | Description |
---|---|
T | Result type of the returned test instruction. |
WaitForAllOf<T>(ITestWaitCondition<T>[])
Wait for all conditions to complete, and return their results as an array. Will complete with an error if any of the conditions completes with an error.
Declaration
[Pure]
public static ITestWaitCondition<T[]> WaitForAllOf<T>(params ITestWaitCondition<T>[] conditions)
Parameters
Type | Name | Description |
---|---|---|
ITestWaitCondition<T>[] | conditions | Conditions to wait on. |
Returns
Type | Description |
---|---|
ITestWaitCondition<T[]> | A wait condition which completes with the values of |
Type Parameters
Name | Description |
---|---|
T | Result type of the conditions to wait on. |
WaitForCondition(String, Func<Boolean>, Action<StateStringBuilder>, String, String, Int32)
Constructs a wait condition, which will poll a condition, and complete once the condition returns true.
Declaration
[Pure]
public static ITestWaitCondition<object> WaitForCondition(string description, Func<bool> condition, Action<StateStringBuilder> extraContext = null, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
String | description | Description of the operation, to be included in the state output. |
Func<Boolean> | condition | Condition to wait for, will be polled on every frame. |
Action<StateStringBuilder> | extraContext | Action for producing extra context into state descriptions. |
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 |
---|---|
ITestWaitCondition<Object> | A wait condition which completes with a non-null object once |
WaitForConditionOn<T>(String, Func<T>, Func<T, Boolean>, Action<StateStringBuilder>, String, String, Int32)
Constructs a wait condition, which will call getObject
on every frame,
and check condition
on the returned object.
Will complete once the condition returns true,
returning the last value returned by getObject
.
Declaration
[Pure]
public static ITestWaitCondition<T> WaitForConditionOn<T>(string description, Func<T> getObject, Func<T, bool> condition, Action<StateStringBuilder> extraContext = null, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
String | description | Description of the operation, to be included in the state output. |
Func<T> | getObject | Function that returns the object to test |
Func<T, Boolean> | condition | Condition to check with the return value of |
Action<StateStringBuilder> | extraContext | Action for producing extra context into state descriptions. |
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 |
---|---|
ITestWaitCondition<T> | A wait condition, which completes with the value last returned from |
Type Parameters
Name | Description |
---|---|
T | Type of the object to wait on, and result of the returned wait condition. |
WaitForConstraint<T>(String, Func<T>, IResolveConstraint, String, String, Int32)
Unity-only!
Constructs a wait condition, which will call getObject
on every frame,
and check constraint
on the returned object.
Will complete once the constraint is fulfilled,
returning the last value returned by getObject
.
When constructing the state description, will add the constraint state to the description.
Declaration
[Pure]
public static ITestWaitCondition<T> WaitForConstraint<T>(string objectDescription, Func<T> getObject, IResolveConstraint constraint, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
String | objectDescription | Description of the object to be tested with |
Func<T> | getObject | Function that returns the object to test |
IResolveConstraint | constraint | Constraint to check with the return value of |
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 |
---|---|
ITestWaitCondition<T> | A wait condition, which completes with the value last returned from |
Type Parameters
Name | Description |
---|---|
T | Type of the object to wait on, and result of the returned wait condition. |
Remarks
This is Unity-only, as we don't want to depend on NUnit in the netstandard version.
WaitForCoroutine(String, Func<IEnumerator>, String, String, Int32)
Unity-only!
Constructs a wait condition, which will start the provided coroutine when executed. Will complete when the coroutine has terminated. See also WaitForCoroutineMethod(Func<IEnumerator>, String, String, Int32).
Declaration
[Pure]
public static ITestWaitCondition<object> WaitForCoroutine(string description, Func<IEnumerator> startCoroutine, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
String | description | Description of the operation, to be included in the state output. |
Func<IEnumerator> | startCoroutine | Function to start the coroutine to be waited for. |
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 |
---|---|
ITestWaitCondition<Object> | Wait condition, which completes once the coroutine has terminated. |
Remarks
May be used with local functions and lambdas, as the description is manually provided.
WaitForCoroutineMethod(Func<IEnumerator>, String, String, Int32)
Unity-only!
Constructs a wait condition, which will start the provided coroutine when executed. Will complete when the coroutine has terminated. The description will be the coroutine method name. See also WaitForCoroutine(String, Func<IEnumerator>, String, String, Int32).
Declaration
[Pure]
public static ITestWaitCondition<object> WaitForCoroutineMethod(Func<IEnumerator> coroutineMethod, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
Func<IEnumerator> | coroutineMethod | Method to start the coroutine to be waited for. |
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 |
---|---|
ITestWaitCondition<Object> | Wait condition, which completes once the coroutine has terminated. |
Remarks
If used with a lambda or local function, you will get a weird compiler-generated description.
WaitForFrames(Int32, String, String, Int32)
Constructs a test instruction, which will complete with a non-null object after the provided amount of whole frames. Note that zero frames means to wait until the next frame.
Declaration
[Pure]
public static ITestInstruction<object> WaitForFrames(int frames, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | frames | Whole frames to wait for. |
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<Object> | Test instruction which completes after |
WaitForSeconds(Double, String, String, Int32)
Constructs a test instruction, which will complete with Responsible.Utilities.Unit.Instance
after seconds
seconds have passed.
Declaration
[Pure]
public static ITestInstruction<object> WaitForSeconds(double seconds, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
Double | seconds | Seconds to wait for. |
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<Object> | Test instruction which completes after |
WaitForTask<T>(String, Func<CancellationToken, Task<T>>, String, String, Int32)
Constructs a wait condition, which will start a task, and complete with its result when it completes.
Declaration
[Pure]
public static ITestWaitCondition<T> WaitForTask<T>(string description, Func<CancellationToken, Task<T>> taskRunner, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
Parameters
Type | Name | Description |
---|---|---|
String | description | Description of the operation, to be included in the state output. |
Func<CancellationToken, Task<T>> | taskRunner | Function used to start the task to be waited for. |
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 |
---|---|
ITestWaitCondition<T> | Wait condition which completes together with the task constructed with |
Type Parameters
Name | Description |
---|---|
T | Result type of the task to wait on. |