Table of Contents

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

ctx ScenarioContext

The 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

setup Func<CancellationToken, Task<T>>

Asynchronous factory that observes a CancellationToken.

Returns

ScenarioChain<T>

A ScenarioChain<T> that can be continued with When/Then.

Type Parameters

T

The 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

setup Func<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

T

The 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

setup Func<Task<T>>

Asynchronous factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> that can be continued with When/Then.

Type Parameters

T

The 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

setup Func<ValueTask<T>>

ValueTask-producing factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> that can be continued with When/Then.

Type Parameters

T

The 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

setup Func<T>

Synchronous factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> that can be continued with When/Then.

Type Parameters

T

The 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

title string

Human-friendly step title.

setup Func<CancellationToken, Task<T>>

Asynchronous factory that observes a CancellationToken.

Returns

ScenarioChain<T>

A ScenarioChain<T> that can be continued with When/Then.

Type Parameters

T

The 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

title string

Human-friendly step title.

setup Func<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

T

The 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

title string

Human-friendly step title.

setup Func<Task<T>>

Asynchronous factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> that can be continued with When/Then.

Type Parameters

T

The 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

title string

Human-friendly step title.

setup Func<ValueTask<T>>

ValueTask-producing factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> that can be continued with When/Then.

Type Parameters

T

The 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

title string

Human-friendly step title.

setup Func<T>

Synchronous factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> that can be continued with When/Then.

Type Parameters

T

The 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

title string
state TState
setup Func<TState, CancellationToken, Task<T>>

Returns

ScenarioChain<T>

Type Parameters

TState
T

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

title string
state TState
setup Func<TState, CancellationToken, ValueTask<T>>

Returns

ScenarioChain<T>

Type Parameters

TState
T

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

title string
state TState
setup Func<TState, Task<T>>

Returns

ScenarioChain<T>

Type Parameters

TState
T

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

title string
state TState
setup Func<TState, ValueTask<T>>

Returns

ScenarioChain<T>

Type Parameters

TState
T

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

title string

Human-friendly step title.

state TState

State value to pass to the setup function.

setup Func<TState, T>

Synchronous factory that receives the state.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

TState

The type of state to pass.

T

The type produced by the setup function.

See Also