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
configureAction<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
featureSourceobjectAny object from the test class; only its type is used to read attributes.
scenarioNamestringOptional scenario name override; defaults to the method name or Name.
traitsITraitBridgeOptional trait bridge for propagating tags to the host framework.
optionsScenarioOptionsOptional 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupActionSynchronous action that performs setup side-effects.
seedTValue seeded into the chain after performing
setup.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<CancellationToken, Task<T>>Asynchronous factory that observes a CancellationToken.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<CancellationToken, Task>Asynchronous side-effect that observes a CancellationToken.
seedTValue carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<CancellationToken, ValueTask<T>>ValueTask-producing factory that observes a CancellationToken.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<CancellationToken, ValueTask>Asynchronous side-effect that observes a CancellationToken.
seedTValue carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<Task<T>, CancellationToken, Task>Asynchronous side-effect that observes a CancellationToken.
seedTask<T>Value carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<Task<T>, CancellationToken, ValueTask>Asynchronous side-effect that observes a CancellationToken.
seedTask<T>Value carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<Task<T>>Task-producing factory for the initial value.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<ValueTask<T>>ValueTask-producing factory for the initial value.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<T, CancellationToken, ValueTask<T>>Asynchronous factory that observes a CancellationToken.
seedTSeed value passed to
setup.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<T, CancellationToken, ValueTask>Asynchronous side-effect that observes a CancellationToken.
seedTValue carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<T>Synchronous factory for the initial value.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupActionSynchronous action that performs setup side-effects.
seedTValue seeded into the chain after performing
setup.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<CancellationToken, Task<T>>Asynchronous factory that observes a CancellationToken.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<CancellationToken, Task>Asynchronous side-effect that observes a CancellationToken.
seedTValue carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<CancellationToken, ValueTask<T>>ValueTask-producing factory that observes a CancellationToken.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<CancellationToken, ValueTask>Asynchronous side-effect that observes a CancellationToken.
seedTValue carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<Task<T>, CancellationToken, Task>Asynchronous side-effect that observes a CancellationToken.
seedTask<T>Value carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<Task<T>, CancellationToken, ValueTask>Asynchronous side-effect that observes a CancellationToken.
seedTask<T>Value carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<Task<T>>Task-producing factory for the initial value.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<ValueTask<T>>ValueTask-producing factory for the initial value.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<T, CancellationToken, ValueTask<T>>Asynchronous factory that observes a CancellationToken.
seedTSeed value passed to
setup.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<T, CancellationToken, ValueTask>Asynchronous side-effect that observes a CancellationToken.
seedTValue carried after the side-effect.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TType 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<T>Synchronous factory for the initial value.
Returns
- ScenarioChain<T>
A ScenarioChain<T> for further chaining.
Type Parameters
TThe 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<Task<TIn>, CancellationToken, Task<TOut>>Asynchronous factory that observes a CancellationToken.
seedTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<Task<TIn>, CancellationToken, ValueTask<TOut>>ValueTask-producing factory that observes a CancellationToken.
seedTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<Task<TIn>, CancellationToken, TOut>Factory that observes a CancellationToken.
seedTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<Task<TIn>, TOut>Factory that accepts a Task<TResult>.
seedTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<ValueTask<TIn>, CancellationToken, ValueTask<TOut>>ValueTask-producing factory that observes a CancellationToken.
seedValueTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<ValueTask<TIn>, CancellationToken, TOut>Factory that observes a CancellationToken.
seedValueTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<ValueTask<TIn>, TOut>Factory that accepts a ValueTask<TResult>.
seedValueTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<TIn, CancellationToken, Task<TOut>>Asynchronous factory that observes a CancellationToken.
seedTInSeed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<TIn, CancellationToken, ValueTask<TOut>>ValueTask-producing factory that observes a CancellationToken.
seedTInSeed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
setupFunc<TIn, TOut>Synchronous factory for the initial value.
seedTInSeed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<Task<TIn>, CancellationToken, Task<TOut>>Asynchronous factory that observes a CancellationToken.
seedTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<Task<TIn>, CancellationToken, ValueTask<TOut>>ValueTask-producing factory that observes a CancellationToken.
seedTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<Task<TIn>, CancellationToken, TOut>Factory that observes a CancellationToken.
seedTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<Task<TIn>, TOut>Factory that accepts a Task<TResult>.
seedTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<ValueTask<TIn>, CancellationToken, ValueTask<TOut>>ValueTask-producing factory that observes a CancellationToken.
seedValueTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<ValueTask<TIn>, CancellationToken, TOut>Factory that observes a CancellationToken.
seedValueTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<ValueTask<TIn>, TOut>Factory that accepts a ValueTask<TResult>.
seedValueTask<TIn>Seed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<TIn, CancellationToken, Task<TOut>>Asynchronous factory that observes a CancellationToken.
seedTInSeed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<TIn, CancellationToken, ValueTask<TOut>>ValueTask-producing factory that observes a CancellationToken.
seedTInSeed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContextScenario context created by CreateContext(object, string?, ITraitBridge?, ScenarioOptions?).
titlestringHuman-friendly step title.
setupFunc<TIn, TOut>Synchronous factory for the initial value.
seedTInSeed value passed to
setup.
Returns
- ScenarioChain<TOut>
A ScenarioChain<T> for further chaining.
Type Parameters
TInSeed type.
TOutResult 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
ctxScenarioContexttitlestringstateTStatesetupFunc<TState, CancellationToken, Task<T>>
Returns
Type Parameters
TStateT
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
ctxScenarioContexttitlestringstateTStatesetupFunc<TState, CancellationToken, ValueTask<T>>
Returns
Type Parameters
TStateT
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
ctxScenarioContexttitlestringstateTStatesetupFunc<TState, Task<T>>
Returns
Type Parameters
TStateT
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
ctxScenarioContexttitlestringstateTStatesetupFunc<TState, ValueTask<T>>
Returns
Type Parameters
TStateT
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
ctxScenarioContextScenario context.
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.
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
ctxScenarioContextThe existing scenario context that will be reconfigured.
configureAction<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
resolverITestMethodResolver
ScenarioOutline<TExample>(ScenarioContext, string)
Creates a Gherkin-style scenario outline builder.
public static ScenarioOutlineBuilder<TExample> ScenarioOutline<TExample>(ScenarioContext ctx, string title)
Parameters
ctxScenarioContextThe scenario context.
titlestringThe scenario outline title.
Returns
- ScenarioOutlineBuilder<TExample>
A ScenarioOutlineBuilder<TExample> for defining the scenario outline.
Type Parameters
TExampleThe 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
ctxScenarioContextThe scenario context.
titlestringThe scenario title.
examplesTExample[]The example data values.
Returns
- ExamplesBuilder<TExample>
An ExamplesBuilder<TExample> for defining the scenario.
Type Parameters
TExampleThe 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));