Table of Contents

Class Bdd

Namespace
TinyBDD
Assembly
TinyBDD.dll

Entry points for creating a ScenarioContext and starting fluent Given/When/Then chains.

public static class Bdd
Inheritance
Bdd
Inherited Members

Examples

var ctx = Bdd.CreateContext(this);
await Bdd.Given(ctx, "numbers", () => new[]{1,2,3})
         .When("sum", arr => arr.Sum())
         .Then("> 0", total => total > 0);
ctx.AssertPassed();

Remarks

Use this static API when you want to work with an explicit ScenarioContext. Call CreateContext(object, string?, ITraitBridge?, ScenarioOptions?) to construct a context from attributes on your test class and method (see FeatureAttribute, ScenarioAttribute, and TagAttribute). Then begin your scenario with one of the Given overloads.

If you prefer not to pass a context around, use the ambient Flow API by setting Current at the start of a test (TinyBDD base classes do this for you).

Methods

Configure(Action<TinyBddOptionsBuilder>)

Configures TinyBDD with extensibility options including observers and services.

public static ScenarioOptions Configure(Action<TinyBddOptionsBuilder> configure)

Parameters

configure Action<TinyBddOptionsBuilder>

An action to configure the TinyBddOptionsBuilder.

Returns

ScenarioOptions

Configured ScenarioOptions with extensibility options applied.

Examples

var options = TinyBdd.Configure(builder => builder
    .AddObserver(new LoggingObserver())
    .AddObserver(new TelemetryObserver()));

var ctx = Bdd.CreateContext(this, options: options);
await Bdd.Given(ctx, "start", () => 1)
    .When("add", x => x + 1)
    .Then("is 2", x => x == 2);

Remarks

This method provides an EF Core-style fluent API for adding cross-cutting functionality to TinyBDD scenarios. Extensions like structured logging, OpenTelemetry, and JSON reporting are added through this builder.

CreateContext(object, string?, ITraitBridge?, ScenarioOptions?)

Creates a ScenarioContext by inspecting featureSource and the current test method for FeatureAttribute, ScenarioAttribute, and TagAttribute.

public static ScenarioContext CreateContext(object featureSource, string? scenarioName = null, ITraitBridge? traits = null, ScenarioOptions? options = null)

Parameters

featureSource object

Any object from the test class; only its type is used to read attributes.

scenarioName string

Optional scenario name override; defaults to the method name or Name.

traits ITraitBridge

Optional trait bridge for propagating tags to the host framework.

options ScenarioOptions

Optional ScenarioOptions that customizes scenario behavior.

Returns

ScenarioContext

A new ScenarioContext populated with feature/scenario metadata and tags.

Given<T>(ScenarioContext, Action, T)

Starts a Given step with an auto-generated title using a synchronous setup action plus a seed value.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Action setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Action

Synchronous action that performs setup side-effects.

seed T

Value seeded into the chain after performing setup.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the seed value.

Given<T>(ScenarioContext, Func<CancellationToken, Task<T>>)

Starts a token-aware Given step with an auto-generated title using an asynchronous factory that observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<CancellationToken, Task<T>> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<CancellationToken, Task<T>>

Asynchronous factory that observes a CancellationToken.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, Func<CancellationToken, Task>, T)

Starts a token-aware Given step with an auto-generated title using an async side-effect (Task) that observes a CancellationToken and keeps the seed value.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<CancellationToken, Task> setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<CancellationToken, Task>

Asynchronous side-effect that observes a CancellationToken.

seed T

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, Func<CancellationToken, ValueTask<T>>)

Starts a token-aware Given step with an auto-generated title using a ValueTask-producing factory that observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<CancellationToken, ValueTask<T>> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<CancellationToken, ValueTask<T>>

ValueTask-producing factory that observes a CancellationToken.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, Func<CancellationToken, ValueTask>, T)

Starts a token-aware Given step with an auto-generated title using an async side-effect (ValueTask) that observes a CancellationToken and keeps the seed value.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<CancellationToken, ValueTask> setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<CancellationToken, ValueTask>

Asynchronous side-effect that observes a CancellationToken.

seed T

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, Func<Task<T>, CancellationToken, Task>, Task<T>)

Starts a token-aware Given step with an auto-generated title using an async side-effect (Task) that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<Task<T>, CancellationToken, Task> setup, Task<T> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<Task<T>, CancellationToken, Task>

Asynchronous side-effect that observes a CancellationToken.

seed Task<T>

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, Func<Task<T>, CancellationToken, ValueTask>, Task<T>)

Starts a token-aware Given step with an auto-generated title using an async side-effect (ValueTask) that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<Task<T>, CancellationToken, ValueTask> setup, Task<T> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<Task<T>, CancellationToken, ValueTask>

Asynchronous side-effect that observes a CancellationToken.

seed Task<T>

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, Func<Task<T>>)

Starts a Given step with an auto-generated title using an asynchronous Task-producing factory.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<Task<T>> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<Task<T>>

Task-producing factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, Func<ValueTask<T>>)

Starts a Given step with an auto-generated title using a ValueTask-producing factory.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<ValueTask<T>> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<ValueTask<T>>

ValueTask-producing factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, Func<T, CancellationToken, ValueTask<T>>, T)

Starts a token-aware Given step with an auto-generated title using an async factory (ValueTask<T>) that accepts a seed value and observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<T, CancellationToken, ValueTask<T>> setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<T, CancellationToken, ValueTask<T>>

Asynchronous factory that observes a CancellationToken.

seed T

Seed value passed to setup.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, Func<T, CancellationToken, ValueTask>, T)

Starts a token-aware Given step with an auto-generated title using an async side-effect (ValueTask) that accepts a seed value and observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<T, CancellationToken, ValueTask> setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<T, CancellationToken, ValueTask>

Asynchronous side-effect that observes a CancellationToken.

seed T

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, Func<T>)

Starts a Given step with an auto-generated title using a synchronous factory.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, Func<T> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<T>

Synchronous factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, string, Action, T)

Starts a Given step with an explicit title using a synchronous setup action plus a seed value.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Action setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Action

Synchronous action that performs setup side-effects.

seed T

Value seeded into the chain after performing setup.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the seed value.

Given<T>(ScenarioContext, string, Func<CancellationToken, Task<T>>)

Starts a token-aware Given step with an explicit title using an asynchronous factory that observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<CancellationToken, Task<T>> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<CancellationToken, Task<T>>

Asynchronous factory that observes a CancellationToken.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, string, Func<CancellationToken, Task>, T)

Starts a token-aware Given step with an explicit title using an async side-effect (Task) that observes a CancellationToken and keeps the seed value.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<CancellationToken, Task> setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<CancellationToken, Task>

Asynchronous side-effect that observes a CancellationToken.

seed T

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, string, Func<CancellationToken, ValueTask<T>>)

Starts a token-aware Given step with an explicit title using a ValueTask-producing factory that observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<CancellationToken, ValueTask<T>> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<CancellationToken, ValueTask<T>>

ValueTask-producing factory that observes a CancellationToken.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, string, Func<CancellationToken, ValueTask>, T)

Starts a token-aware Given step with an explicit title using an async side-effect (ValueTask) that observes a CancellationToken and keeps the seed value.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<CancellationToken, ValueTask> setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<CancellationToken, ValueTask>

Asynchronous side-effect that observes a CancellationToken.

seed T

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, string, Func<Task<T>, CancellationToken, Task>, Task<T>)

Starts a token-aware Given step with an explicit title using an async side-effect (Task) that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<Task<T>, CancellationToken, Task> setup, Task<T> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<Task<T>, CancellationToken, Task>

Asynchronous side-effect that observes a CancellationToken.

seed Task<T>

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, string, Func<Task<T>, CancellationToken, ValueTask>, Task<T>)

Starts a token-aware Given step with an explicit title using an async side-effect (ValueTask) that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<Task<T>, CancellationToken, ValueTask> setup, Task<T> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<Task<T>, CancellationToken, ValueTask>

Asynchronous side-effect that observes a CancellationToken.

seed Task<T>

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, string, Func<Task<T>>)

Starts a Given step with an explicit title using an asynchronous Task-producing factory.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<Task<T>> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<Task<T>>

Task-producing factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, string, Func<ValueTask<T>>)

Starts a Given step with an explicit title using a ValueTask-producing factory.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<ValueTask<T>> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<ValueTask<T>>

ValueTask-producing factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, string, Func<T, CancellationToken, ValueTask<T>>, T)

Starts a token-aware Given step with an explicit title using an async factory (ValueTask<T>) that accepts a seed value and observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<T, CancellationToken, ValueTask<T>> setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<T, CancellationToken, ValueTask<T>>

Asynchronous factory that observes a CancellationToken.

seed T

Seed value passed to setup.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<T>(ScenarioContext, string, Func<T, CancellationToken, ValueTask>, T)

Starts a token-aware Given step with an explicit title using an async side-effect (ValueTask) that accepts a seed value and observes a CancellationToken.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<T, CancellationToken, ValueTask> setup, T seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<T, CancellationToken, ValueTask>

Asynchronous side-effect that observes a CancellationToken.

seed T

Value carried after the side-effect.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

Type carried in the chain.

Given<T>(ScenarioContext, string, Func<T>)

Starts a Given step with an explicit title using a synchronous factory.

public static ScenarioChain<T> Given<T>(ScenarioContext ctx, string title, Func<T> setup)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<T>

Synchronous factory for the initial value.

Returns

ScenarioChain<T>

A ScenarioChain<T> for further chaining.

Type Parameters

T

The type produced by the setup function.

Given<TIn, TOut>(ScenarioContext, Func<Task<TIn>, CancellationToken, Task<TOut>>, Task<TIn>)

Starts a token-aware Given step with an auto-generated title using an async factory (Task) that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<Task<TIn>, CancellationToken, Task<TOut>> setup, Task<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<Task<TIn>, CancellationToken, Task<TOut>>

Asynchronous factory that observes a CancellationToken.

seed Task<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, Func<Task<TIn>, CancellationToken, ValueTask<TOut>>, Task<TIn>)

Starts a token-aware Given step with an auto-generated title using an async factory (ValueTask) that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<Task<TIn>, CancellationToken, ValueTask<TOut>> setup, Task<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<Task<TIn>, CancellationToken, ValueTask<TOut>>

ValueTask-producing factory that observes a CancellationToken.

seed Task<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, Func<Task<TIn>, CancellationToken, TOut>, Task<TIn>)

Starts a token-aware Given step with an auto-generated title using a synchronous factory that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<Task<TIn>, CancellationToken, TOut> setup, Task<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<Task<TIn>, CancellationToken, TOut>

Factory that observes a CancellationToken.

seed Task<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, Func<Task<TIn>, TOut>, Task<TIn>)

Starts a Given step with an auto-generated title using a synchronous factory that accepts Task-based seed.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<Task<TIn>, TOut> setup, Task<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<Task<TIn>, TOut>

Factory that accepts a Task<TResult>.

seed Task<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, Func<ValueTask<TIn>, CancellationToken, ValueTask<TOut>>, ValueTask<TIn>)

Starts a token-aware Given step with an auto-generated title using an async factory (ValueTask) that accepts ValueTask-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<ValueTask<TIn>, CancellationToken, ValueTask<TOut>> setup, ValueTask<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<ValueTask<TIn>, CancellationToken, ValueTask<TOut>>

ValueTask-producing factory that observes a CancellationToken.

seed ValueTask<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, Func<ValueTask<TIn>, CancellationToken, TOut>, ValueTask<TIn>)

Starts a token-aware Given step with an auto-generated title using a synchronous factory that accepts ValueTask-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<ValueTask<TIn>, CancellationToken, TOut> setup, ValueTask<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<ValueTask<TIn>, CancellationToken, TOut>

Factory that observes a CancellationToken.

seed ValueTask<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, Func<ValueTask<TIn>, TOut>, ValueTask<TIn>)

Starts a Given step with an auto-generated title using a synchronous factory that accepts ValueTask-based seed.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<ValueTask<TIn>, TOut> setup, ValueTask<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<ValueTask<TIn>, TOut>

Factory that accepts a ValueTask<TResult>.

seed ValueTask<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, Func<TIn, CancellationToken, Task<TOut>>, TIn)

Starts a token-aware Given step with an auto-generated title using an async factory (Task) that accepts a seed value and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<TIn, CancellationToken, Task<TOut>> setup, TIn seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<TIn, CancellationToken, Task<TOut>>

Asynchronous factory that observes a CancellationToken.

seed TIn

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, Func<TIn, CancellationToken, ValueTask<TOut>>, TIn)

Starts a token-aware Given step with an auto-generated title using an async factory (ValueTask<T>) that accepts a seed value and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<TIn, CancellationToken, ValueTask<TOut>> setup, TIn seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<TIn, CancellationToken, ValueTask<TOut>>

ValueTask-producing factory that observes a CancellationToken.

seed TIn

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, Func<TIn, TOut>, TIn)

Starts a Given step with an auto-generated title using a synchronous factory that accepts a seed value.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, Func<TIn, TOut> setup, TIn seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

setup Func<TIn, TOut>

Synchronous factory for the initial value.

seed TIn

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<Task<TIn>, CancellationToken, Task<TOut>>, Task<TIn>)

Starts a token-aware Given step with an explicit title using an async factory (Task) that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<Task<TIn>, CancellationToken, Task<TOut>> setup, Task<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<Task<TIn>, CancellationToken, Task<TOut>>

Asynchronous factory that observes a CancellationToken.

seed Task<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<Task<TIn>, CancellationToken, ValueTask<TOut>>, Task<TIn>)

Starts a token-aware Given step with an explicit title using an async factory (ValueTask) that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<Task<TIn>, CancellationToken, ValueTask<TOut>> setup, Task<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<Task<TIn>, CancellationToken, ValueTask<TOut>>

ValueTask-producing factory that observes a CancellationToken.

seed Task<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<Task<TIn>, CancellationToken, TOut>, Task<TIn>)

Starts a token-aware Given step with an explicit title using a synchronous factory that accepts Task-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<Task<TIn>, CancellationToken, TOut> setup, Task<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<Task<TIn>, CancellationToken, TOut>

Factory that observes a CancellationToken.

seed Task<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<Task<TIn>, TOut>, Task<TIn>)

Starts a Given step with an explicit title using a synchronous factory that accepts Task-based seed.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<Task<TIn>, TOut> setup, Task<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<Task<TIn>, TOut>

Factory that accepts a Task<TResult>.

seed Task<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<ValueTask<TIn>, CancellationToken, ValueTask<TOut>>, ValueTask<TIn>)

Starts a token-aware Given step with an explicit title using an async factory (ValueTask) that accepts ValueTask-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<ValueTask<TIn>, CancellationToken, ValueTask<TOut>> setup, ValueTask<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<ValueTask<TIn>, CancellationToken, ValueTask<TOut>>

ValueTask-producing factory that observes a CancellationToken.

seed ValueTask<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<ValueTask<TIn>, CancellationToken, TOut>, ValueTask<TIn>)

Starts a token-aware Given step with an explicit title using a synchronous factory that accepts ValueTask-based seed and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<ValueTask<TIn>, CancellationToken, TOut> setup, ValueTask<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<ValueTask<TIn>, CancellationToken, TOut>

Factory that observes a CancellationToken.

seed ValueTask<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<ValueTask<TIn>, TOut>, ValueTask<TIn>)

Starts a Given step with an explicit title using a synchronous factory that accepts ValueTask-based seed.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<ValueTask<TIn>, TOut> setup, ValueTask<TIn> seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<ValueTask<TIn>, TOut>

Factory that accepts a ValueTask<TResult>.

seed ValueTask<TIn>

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<TIn, CancellationToken, Task<TOut>>, TIn)

Starts a token-aware Given step with an explicit title using an async factory (Task) that accepts a seed value and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<TIn, CancellationToken, Task<TOut>> setup, TIn seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<TIn, CancellationToken, Task<TOut>>

Asynchronous factory that observes a CancellationToken.

seed TIn

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<TIn, CancellationToken, ValueTask<TOut>>, TIn)

Starts a token-aware Given step with an explicit title using an async factory (ValueTask<T>) that accepts a seed value and observes a CancellationToken.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<TIn, CancellationToken, ValueTask<TOut>> setup, TIn seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<TIn, CancellationToken, ValueTask<TOut>>

ValueTask-producing factory that observes a CancellationToken.

seed TIn

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TIn, TOut>(ScenarioContext, string, Func<TIn, TOut>, TIn)

Starts a Given step with an explicit title using a synchronous factory that accepts a seed value.

public static ScenarioChain<TOut> Given<TIn, TOut>(ScenarioContext ctx, string title, Func<TIn, TOut> setup, TIn seed)

Parameters

ctx ScenarioContext

Scenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).

title string

Human-friendly step title.

setup Func<TIn, TOut>

Synchronous factory for the initial value.

seed TIn

Seed value passed to setup.

Returns

ScenarioChain<TOut>

A ScenarioChain<T> for further chaining.

Type Parameters

TIn

Seed type.

TOut

Result type.

Given<TState, T>(ScenarioContext, 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>(ScenarioContext ctx, string title, TState state, Func<TState, CancellationToken, Task<T>> setup)

Parameters

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

Returns

ScenarioChain<T>

Type Parameters

TState
T

Given<TState, T>(ScenarioContext, 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>(ScenarioContext ctx, string title, TState state, Func<TState, CancellationToken, ValueTask<T>> setup)

Parameters

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

Returns

ScenarioChain<T>

Type Parameters

TState
T

Given<TState, T>(ScenarioContext, 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>(ScenarioContext ctx, string title, TState state, Func<TState, Task<T>> setup)

Parameters

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

Returns

ScenarioChain<T>

Type Parameters

TState
T

Given<TState, T>(ScenarioContext, 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>(ScenarioContext ctx, string title, TState state, Func<TState, ValueTask<T>> setup)

Parameters

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

Returns

ScenarioChain<T>

Type Parameters

TState
T

Given<TState, T>(ScenarioContext, string, TState, Func<TState, T>)

Starts a Given step with state, avoiding closure allocation.

public static ScenarioChain<T> Given<TState, T>(ScenarioContext ctx, string title, TState state, Func<TState, T> setup)

Parameters

ctx ScenarioContext

Scenario context.

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.

ReconfigureContext(ScenarioContext, Action<ScenarioContextPrototype>)

Reconfigures a scenario context by applying a configuration action to its prototype.

public static ScenarioContext ReconfigureContext(ScenarioContext ctx, Action<ScenarioContextPrototype> configure)

Parameters

ctx ScenarioContext

The existing scenario context that will be reconfigured.

configure Action<ScenarioContextPrototype>

An action delegate used to configure the ScenarioContextPrototype. This allows customization of the prototype before building the new context.

Returns

ScenarioContext

A new instance of ScenarioContext created with the specified configuration applied, based on the original context and the configuration action.

Register(ITestMethodResolver)

Registers an ITestMethodResolver used to discover the current test method when creating a ScenarioContext.

public static void Register(ITestMethodResolver resolver)

Parameters

resolver ITestMethodResolver

ScenarioOutline<TExample>(ScenarioContext, string)

Creates a Gherkin-style scenario outline builder.

public static ScenarioOutlineBuilder<TExample> ScenarioOutline<TExample>(ScenarioContext ctx, string title)

Parameters

ctx ScenarioContext

The scenario context.

title string

The scenario outline title.

Returns

ScenarioOutlineBuilder<TExample>

A ScenarioOutlineBuilder<TExample> for defining the scenario outline.

Type Parameters

TExample

The type of example data.

Examples

await Bdd.ScenarioOutline<(int a, int b, int expected)>(ctx, "Addition")
    .Given("first number", ex => ex.a)
    .When("added to second", (a, ex) => a + ex.b)
    .Then("result matches expected", (sum, ex) => sum == ex.expected)
    .Examples(
        (a: 1, b: 2, expected: 3),
        (a: 5, b: 5, expected: 10))
    .AssertAllPassedAsync();

Scenario<TExample>(ScenarioContext, string, params TExample[])

Creates a data-driven scenario builder with the specified examples.

public static ExamplesBuilder<TExample> Scenario<TExample>(ScenarioContext ctx, string title, params TExample[] examples)

Parameters

ctx ScenarioContext

The scenario context.

title string

The scenario title.

examples TExample[]

The example data values.

Returns

ExamplesBuilder<TExample>

An ExamplesBuilder<TExample> for defining the scenario.

Type Parameters

TExample

The type of example data.

Examples

await Bdd.Scenario(ctx, "Adding numbers",
        new { a = 1, b = 2, expected = 3 },
        new { a = 5, b = 5, expected = 10 })
    .ForEachAsync(ex =>
        Bdd.Given(ctx, $"a={ex.Data.a}, b={ex.Data.b}", () => (ex.Data.a, ex.Data.b))
            .When("added", x => x.a + x.b)
            .Then($"equals {ex.Data.expected}", sum => sum == ex.Data.expected));

See Also