• Home
  • .NET
  • Unity
  • Godot
  • Design Overview
  • API Documentation
  • Changelog
  • GitHub
Show / Hide Table of Contents
  • Responsible
    • BddExtensions
    • IExternalResultSource
    • IFailureListener
    • IGlobalContextProvider
    • IOptionalTestResponder
    • ITestInstruction<T>
    • ITestOperation<T>
    • ITestResponder<T>
    • ITestScheduler
    • ITestWaitCondition<T>
    • LinqSupport
    • OptionalTestResponder
    • RepetitionLimitExceededException
    • Responsibly
    • TestFailureException
    • TestInstruction
    • TestInstructionExecutor
    • TestInstructionExecutor.StateNotificationCallback
    • TestOperationState
    • TestResponder
    • TestWaitCondition
  • Responsible.Bdd
    • IBddStep
    • Keywords
    • ScenarioBuilder
  • Responsible.Context
    • RunContext
  • Responsible.Docs
    • Inherit
  • Responsible.State
    • ITestOperationState
    • ITestOperationState<T>
    • StateStringBuilder
    • TestOperationStateTransition
    • TestOperationStatus
  • Responsible.Unity
    • TestOperationYieldInstruction<T>
    • UnhandledLogMessageException
    • UnityErrorLogInterceptor
    • UnityFailureListener
    • UnityTestInstructionExecutor
    • UnityTestScheduler
  • Responsible.Utilities
    • IMultipleTaskAwaiter<T>
    • IMultipleTaskSource<T>
    • IndentedStringBuilder<T>
    • RetryingPoller

Class Responsibly

Main class for constructing primitive wait conditions and instructions, and composing responders.

Inheritance
object
Responsibly
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, int)

Execute a synchronous action safely, and return a non-null object.

Declaration
[Pure]
public static ITestInstruction<object> Do(string description, Action action, string memberName = "", string sourceFilePath = "", 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.

int sourceLineNumber

Source line number provided by compiler. May be overridden for custom operators.

Returns
Type Description
ITestInstruction<object>

A test instruction which calls action and returns a non-null object when executed.

DoAndReturn<T>(string, Func<T>, string, string, int)

Execute a synchronous action safely, and return a result.

Declaration
[Pure]
public static ITestInstruction<T> DoAndReturn<T>(string description, Func<T> func, string memberName = "", string sourceFilePath = "", 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.

int sourceLineNumber

Source line number provided by compiler. May be overridden for custom operators.

Returns
Type Description
ITestInstruction<T>

A test instruction which calls func and returns its value when executed.

Type Parameters
Name Description
T

Result type of the returned test instruction and func

Remarks

This is not an overload of Do(string, Action, string, string, int), because C# is bad at overload resolution with lambdas.

RespondToAllOf<T>(params 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, int) 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 responders once all responders have completed executing.

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>(params 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, int) 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 responders optionally, one at a time.

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, int)

Constructs a test instruction that returns a value synchronously.

Declaration
[Pure]
public static ITestInstruction<T> Return<T>(T value, string memberName = "", string sourceFilePath = "", 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.

int sourceLineNumber

Source line number provided by compiler. May be overridden for custom operators.

Returns
Type Description
ITestInstruction<T>

A test instruction returning value.

Type Parameters
Name Description
T

Result type of the returned test instruction.

WaitForAllOf<T>(params 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 conditions once they have all completed.

Type Parameters
Name Description
T

Result type of the conditions to wait on.

WaitForCondition(string, Func<bool>, Action<StateStringBuilder>, string, string, int)

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, string memberName = "", string sourceFilePath = "", int sourceLineNumber = 0)
Parameters
Type Name Description
string description

Description of the operation, to be included in the state output.

Func<bool> 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.

int 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 condition returns true.

WaitForConditionOn<T>(string, Func<T>, Func<T, bool>, Action<StateStringBuilder>, string, string, int)

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, string memberName = "", string sourceFilePath = "", 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 condition on.

Func<T, bool> condition

Condition to check with the return value of getObject.

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.

int 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 getObject, when condition returns true for it.

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, int)

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, string memberName = "", string sourceFilePath = "", int sourceLineNumber = 0)
Parameters
Type Name Description
string objectDescription

Description of the object to be tested with constraint, to be included in the operation state description.

Func<T> getObject

Function that returns the object to test constraint on.

IResolveConstraint constraint

Constraint to check with the return value of getObject.

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.

int 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 getObject, when constraint is met for it.

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, int)

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, int).

Declaration
[Pure]
public static ITestWaitCondition<object> WaitForCoroutine(string description, Func<IEnumerator> startCoroutine, string memberName = "", string sourceFilePath = "", 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.

int 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, int)

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, int).

Declaration
[Pure]
public static ITestWaitCondition<object> WaitForCoroutineMethod(Func<IEnumerator> coroutineMethod, string memberName = "", string sourceFilePath = "", 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.

int 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(int, string, string, int)

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, string memberName = "", string sourceFilePath = "", int sourceLineNumber = 0)
Parameters
Type Name Description
int 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.

int sourceLineNumber

Source line number provided by compiler. May be overridden for custom operators.

Returns
Type Description
ITestInstruction<object>

Test instruction which completes after frames whole frames.

WaitForSeconds(double, string, string, int)

Constructs a test instruction, which will complete with Instance after seconds seconds have passed.

Declaration
[Pure]
public static ITestInstruction<object> WaitForSeconds(double seconds, string memberName = "", string sourceFilePath = "", 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.

int sourceLineNumber

Source line number provided by compiler. May be overridden for custom operators.

Returns
Type Description
ITestInstruction<object>

Test instruction which completes after seconds seconds.

WaitForTask<T>(string, Func<CancellationToken, Task<T>>, string, string, int)

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, string memberName = "", string sourceFilePath = "", 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.

int 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 taskRunner.

Type Parameters
Name Description
T

Result type of the task to wait on.

In this article
Back to top Generated by DocFX