Class Flow
- Namespace
- TinyBDD
- Assembly
- TinyBDD.dll
Ambient, context-free entry points for building BDD chains when Current is set.
public static class Flow
- Inheritance
-
Flow
- Inherited Members
Examples
var prev = Ambient.Current.Value; Ambient.Current.Value = Bdd.CreateContext(this);
try
{
await Flow.Given(() => 1)
.When("double", x => x * 2)
.Then("== 2", v => v == 2);
}
finally { Ambient.Current.Value = prev; }
Remarks
Use this API when you prefer not to pass ScenarioContext through your methods. Set Current at the start of a test (TinyBDD test base classes do this for you).
All overloads delegate to Bdd equivalents using the current ambient context. If the ambient context is not set, an InvalidOperationException is thrown.
Methods
From(ScenarioContext)
Creates a helper for starting chains from an explicit context.
public static FromContext From(ScenarioContext ctx)
Parameters
ctxScenarioContextThe scenario context to use for subsequent calls.
Returns
- FromContext
A FromContext helper bound to
ctx.
Given<T>(Func<CancellationToken, Task<T>>)
Starts a token-aware Given step with a default title and asynchronous setup.
public static ScenarioChain<T> Given<T>(Func<CancellationToken, Task<T>> setup)
Parameters
setupFunc<CancellationToken, Task<T>>Asynchronous factory that observes a CancellationToken.
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<T>(Func<CancellationToken, ValueTask<T>>)
Starts a token-aware Given step with a default title and ValueTask setup.
public static ScenarioChain<T> Given<T>(Func<CancellationToken, ValueTask<T>> setup)
Parameters
setupFunc<CancellationToken, ValueTask<T>>ValueTask-producing factory that observes a CancellationToken.
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<T>(Func<Task<T>>)
Starts a Given step with a default title and asynchronous setup.
public static ScenarioChain<T> Given<T>(Func<Task<T>> setup)
Parameters
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<T>(Func<ValueTask<T>>)
Starts a Given step with a default title and ValueTask setup.
public static ScenarioChain<T> Given<T>(Func<ValueTask<T>> setup)
Parameters
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<T>(Func<T>)
Starts a Given step with a default title and synchronous setup.
public static ScenarioChain<T> Given<T>(Func<T> setup)
Parameters
setupFunc<T>Synchronous factory for the initial value.
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<T>(string, Func<CancellationToken, Task<T>>)
Starts a token-aware Given step with an explicit title and asynchronous setup.
public static ScenarioChain<T> Given<T>(string title, Func<CancellationToken, Task<T>> setup)
Parameters
titlestringHuman-friendly step title.
setupFunc<CancellationToken, Task<T>>Asynchronous factory that observes a CancellationToken.
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<T>(string, Func<CancellationToken, ValueTask<T>>)
Starts a token-aware Given step with an explicit title and ValueTask setup.
public static ScenarioChain<T> Given<T>(string title, Func<CancellationToken, ValueTask<T>> setup)
Parameters
titlestringHuman-friendly step title.
setupFunc<CancellationToken, ValueTask<T>>ValueTask-producing factory that observes a CancellationToken.
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<T>(string, Func<Task<T>>)
Starts a Given step with an explicit title and asynchronous setup.
public static ScenarioChain<T> Given<T>(string title, Func<Task<T>> setup)
Parameters
titlestringHuman-friendly step title.
setupFunc<Task<T>>Asynchronous factory for the initial value.
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<T>(string, Func<ValueTask<T>>)
Starts a Given step with an explicit title and ValueTask setup.
public static ScenarioChain<T> Given<T>(string title, Func<ValueTask<T>> setup)
Parameters
titlestringHuman-friendly step title.
setupFunc<ValueTask<T>>ValueTask-producing factory for the initial value.
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<T>(string, Func<T>)
Starts a Given step with an explicit title and synchronous setup.
public static ScenarioChain<T> Given<T>(string title, Func<T> setup)
Parameters
Returns
- ScenarioChain<T>
A ScenarioChain<T> that can be continued with
When/Then.
Type Parameters
TThe type produced by the setup function.
Given<TState, T>(string, TState, Func<TState, CancellationToken, Task<T>>)
Starts a token-aware Given step with state, avoiding closure allocation.
public static ScenarioChain<T> Given<TState, T>(string title, TState state, Func<TState, CancellationToken, Task<T>> setup)
Parameters
titlestringstateTStatesetupFunc<TState, CancellationToken, Task<T>>
Returns
Type Parameters
TStateT
Given<TState, T>(string, TState, Func<TState, CancellationToken, ValueTask<T>>)
Starts a token-aware Given step with state using ValueTask, avoiding closure allocation.
public static ScenarioChain<T> Given<TState, T>(string title, TState state, Func<TState, CancellationToken, ValueTask<T>> setup)
Parameters
titlestringstateTStatesetupFunc<TState, CancellationToken, ValueTask<T>>
Returns
Type Parameters
TStateT
Given<TState, T>(string, TState, Func<TState, Task<T>>)
Starts a Given step with state using async Task, avoiding closure allocation.
public static ScenarioChain<T> Given<TState, T>(string title, TState state, Func<TState, Task<T>> setup)
Parameters
Returns
Type Parameters
TStateT
Given<TState, T>(string, TState, Func<TState, ValueTask<T>>)
Starts a Given step with state using async ValueTask, avoiding closure allocation.
public static ScenarioChain<T> Given<TState, T>(string title, TState state, Func<TState, ValueTask<T>> setup)
Parameters
Returns
Type Parameters
TStateT
Given<TState, T>(string, TState, Func<TState, T>)
Starts a Given step with state, avoiding closure allocation.
public static ScenarioChain<T> Given<TState, T>(string title, TState state, Func<TState, T> setup)
Parameters
titlestringHuman-friendly step title.
stateTStateState value to pass to the setup function.
setupFunc<TState, T>Synchronous factory that receives the state.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TStateThe type of state to pass.
TThe type produced by the setup function.