Struct ThenChain<T>
- Namespace
- TinyBDD
- Assembly
- TinyBDD.dll
Represents a chain of Then assertions that can be further extended with
And/But and awaited to execute the recorded scenario.
public readonly struct ThenChain<T>
Type Parameters
TThe value type produced by the preceding step and carried through assertions.
- Inherited Members
- Extension Methods
Examples
var ctx = Bdd.CreateContext(this);
await Bdd.Given(ctx, "start", () => 2)
.When("double", x => x * 2)
.Then(">= 4", v => v >= 4) // returns ThenChain<int>
.And("!= 5", v => v != 5); // add another assertion, then await
Remarks
TinyBDD defers execution: steps are queued until you await the chain. Calling any of the
And/But methods only records additional steps; the actual execution happens when the chain is awaited.
Methods
And(Action<T>)
Adds a And assertion with a default title using a synchronous action.
public ThenChain<T> And(Action<T> assertion)
Parameters
assertionAction<T>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<Task>)
Adds a And assertion with a default title (no value parameter).
public ThenChain<T> And(Func<Task> assertion)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<T, bool>)
Adds an And boolean assertion with a default title
public ThenChain<T> And(Func<T, bool> predicate)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<T, CancellationToken, Task<bool>>)
Adds an And boolean assertion with a default title observing a token.
public ThenChain<T> And(Func<T, CancellationToken, Task<bool>> predicate)
Parameters
predicateFunc<T, CancellationToken, Task<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<T, CancellationToken, Task>)
Adds an And assertion with a default title observing a token.
public ThenChain<T> And(Func<T, CancellationToken, Task> assertion)
Parameters
assertionFunc<T, CancellationToken, Task>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<T, CancellationToken, ValueTask<bool>>)
Adds an And boolean assertion with a default title observing a token.
public ThenChain<T> And(Func<T, CancellationToken, ValueTask<bool>> predicate)
Parameters
predicateFunc<T, CancellationToken, ValueTask<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<T, CancellationToken, ValueTask>)
Adds an And assertion with a default title observing a token.
public ThenChain<T> And(Func<T, CancellationToken, ValueTask> assertion)
Parameters
assertionFunc<T, CancellationToken, ValueTask>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<T, Task<bool>>)
Adds an And boolean assertion with a default title
public ThenChain<T> And(Func<T, Task<bool>> predicate)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<T, Task>)
Adds an And assertion with a default title
public ThenChain<T> And(Func<T, Task> assertion)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<T, ValueTask<bool>>)
Adds an And boolean assertion with a default title
public ThenChain<T> And(Func<T, ValueTask<bool>> predicate)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(Func<T, ValueTask>)
Adds an And assertion with a default title
public ThenChain<T> And(Func<T, ValueTask> assertion)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Action<T>)
Adds a And assertion with an explicit title using a synchronous action.
public ThenChain<T> And(string title, Action<T> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionAction<T>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<Task>)
Adds a And assertion with an explicit title (no value parameter).
public ThenChain<T> And(string title, Func<Task> assertion)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<T, bool>)
Adds an And boolean assertion with an explicit title
public ThenChain<T> And(string title, Func<T, bool> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, bool>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<T, CancellationToken, Task<bool>>)
Adds an And boolean assertion with an explicit title observing a token.
public ThenChain<T> And(string title, Func<T, CancellationToken, Task<bool>> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, CancellationToken, Task<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<T, CancellationToken, Task>)
Adds an And assertion with an explicit title observing a token.
public ThenChain<T> And(string title, Func<T, CancellationToken, Task> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionFunc<T, CancellationToken, Task>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<T, CancellationToken, ValueTask<bool>>)
Adds an And boolean assertion with an explicit title observing a token.
public ThenChain<T> And(string title, Func<T, CancellationToken, ValueTask<bool>> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, CancellationToken, ValueTask<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<T, CancellationToken, ValueTask>)
Adds an And assertion with an explicit title observing a token.
public ThenChain<T> And(string title, Func<T, CancellationToken, ValueTask> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionFunc<T, CancellationToken, ValueTask>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<T, Task<bool>>)
Adds an And boolean assertion with an explicit title
public ThenChain<T> And(string title, Func<T, Task<bool>> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, Task<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<T, Task>)
Adds an And assertion with an explicit title
public ThenChain<T> And(string title, Func<T, Task> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionFunc<T, Task>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<T, ValueTask<bool>>)
Adds an And boolean assertion with an explicit title
public ThenChain<T> And(string title, Func<T, ValueTask<bool>> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, ValueTask<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
And(string, Func<T, ValueTask>)
Adds an And assertion with an explicit title
public ThenChain<T> And(string title, Func<T, ValueTask> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionFunc<T, ValueTask>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
AssertFailed(CancellationToken)
Completes the chain and asserts that any previous steps failed.
public Task AssertFailed(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenToken used to cancel the operation.
Returns
Remarks
This method is functionally equivalent to calling the extension method AssertFailed(ScenarioContext) on the underlying ScenarioContext. It is provided for convenience to allow fluent chaining at the end of a scenario.
Exceptions
- InvalidOperationException
Thrown when no step failed.
AssertPassed(CancellationToken)
Completes the chain and asserts that all previous steps passed.
public Task AssertPassed(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenToken used to cancel the operation.
Returns
Remarks
This method is functionally equivalent to calling the extension method AssertPassed(ScenarioContext) on the underlying ScenarioContext. It is provided for convenience to allow fluent chaining at the end of a scenario.
Exceptions
- InvalidOperationException
Thrown when at least one step failed.
But(Action<T>)
Adds a But assertion with a default title using a synchronous action.
public ThenChain<T> But(Action<T> assertion)
Parameters
assertionAction<T>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<Task>)
Adds a But assertion with a default title (no value parameter).
public ThenChain<T> But(Func<Task> assertion)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<T, bool>)
Adds an But boolean assertion with a default title
public ThenChain<T> But(Func<T, bool> predicate)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<T, CancellationToken, Task<bool>>)
Adds an But boolean assertion with a default title observing a token.
public ThenChain<T> But(Func<T, CancellationToken, Task<bool>> predicate)
Parameters
predicateFunc<T, CancellationToken, Task<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<T, CancellationToken, Task>)
Adds an But assertion with a default title observing a token.
public ThenChain<T> But(Func<T, CancellationToken, Task> assertion)
Parameters
assertionFunc<T, CancellationToken, Task>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<T, CancellationToken, ValueTask<bool>>)
Adds an But boolean assertion with a default title observing a token.
public ThenChain<T> But(Func<T, CancellationToken, ValueTask<bool>> predicate)
Parameters
predicateFunc<T, CancellationToken, ValueTask<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<T, CancellationToken, ValueTask>)
Adds an But assertion with a default title observing a token.
public ThenChain<T> But(Func<T, CancellationToken, ValueTask> assertion)
Parameters
assertionFunc<T, CancellationToken, ValueTask>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<T, Task<bool>>)
Adds an But boolean assertion with a default title
public ThenChain<T> But(Func<T, Task<bool>> predicate)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<T, Task>)
Adds an But assertion with a default title
public ThenChain<T> But(Func<T, Task> assertion)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<T, ValueTask<bool>>)
Adds an But boolean assertion with a default title
public ThenChain<T> But(Func<T, ValueTask<bool>> predicate)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(Func<T, ValueTask>)
Adds an But assertion with a default title
public ThenChain<T> But(Func<T, ValueTask> assertion)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Action<T>)
Adds a But assertion with an explicit title using a synchronous action.
public ThenChain<T> But(string title, Action<T> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionAction<T>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<Task>)
Adds a But assertion with an explicit title (no value parameter).
public ThenChain<T> But(string title, Func<Task> assertion)
Parameters
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<T, bool>)
Adds an But boolean assertion with an explicit title
public ThenChain<T> But(string title, Func<T, bool> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, bool>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<T, CancellationToken, Task<bool>>)
Adds an But boolean assertion with an explicit title observing a token.
public ThenChain<T> But(string title, Func<T, CancellationToken, Task<bool>> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, CancellationToken, Task<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<T, CancellationToken, Task>)
Adds an But assertion with an explicit title observing a token.
public ThenChain<T> But(string title, Func<T, CancellationToken, Task> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionFunc<T, CancellationToken, Task>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<T, CancellationToken, ValueTask<bool>>)
Adds an But boolean assertion with an explicit title observing a token.
public ThenChain<T> But(string title, Func<T, CancellationToken, ValueTask<bool>> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, CancellationToken, ValueTask<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<T, CancellationToken, ValueTask>)
Adds an But assertion with an explicit title observing a token.
public ThenChain<T> But(string title, Func<T, CancellationToken, ValueTask> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionFunc<T, CancellationToken, ValueTask>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<T, Task<bool>>)
Adds an But boolean assertion with an explicit title
public ThenChain<T> But(string title, Func<T, Task<bool>> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, Task<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<T, Task>)
Adds an But assertion with an explicit title
public ThenChain<T> But(string title, Func<T, Task> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionFunc<T, Task>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<T, ValueTask<bool>>)
Adds an But boolean assertion with an explicit title
public ThenChain<T> But(string title, Func<T, ValueTask<bool>> predicate)
Parameters
titlestringDisplay title for the assertion.
predicateFunc<T, ValueTask<bool>>Predicate evaluated against the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
But(string, Func<T, ValueTask>)
Adds an But assertion with an explicit title
public ThenChain<T> But(string title, Func<T, ValueTask> assertion)
Parameters
titlestringDisplay title for the assertion.
assertionFunc<T, ValueTask>Asynchronous assertion that receives the carried value.
Returns
- ThenChain<T>
A ThenChain<T> for further chaining.
Finally(Action<T>)
Registers a cleanup handler that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(Action<T> effect)
Parameters
effectAction<T>Cleanup action that receives the carried value.
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
Finally(Func<T, CancellationToken, Task>)
Registers a cleanup handler that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(Func<T, CancellationToken, Task> effect)
Parameters
effectFunc<T, CancellationToken, Task>Cleanup action that receives the carried value.
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
Finally(Func<T, CancellationToken, ValueTask>)
Registers a cleanup handler that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(Func<T, CancellationToken, ValueTask> effect)
Parameters
effectFunc<T, CancellationToken, ValueTask>Cleanup action that receives the carried value.
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
Finally(Func<T, Task>)
Registers a cleanup handler that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(Func<T, Task> effect)
Parameters
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
Finally(Func<T, ValueTask>)
Registers a cleanup handler that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(Func<T, ValueTask> effect)
Parameters
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
Finally(string, Action<T>)
Registers a cleanup handler with an explicit title that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(string title, Action<T> effect)
Parameters
titlestringDisplay title for this finally handler.
effectAction<T>Cleanup action that receives the carried value.
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
Finally(string, Func<T, CancellationToken, Task>)
Registers a cleanup handler with an explicit title that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(string title, Func<T, CancellationToken, Task> effect)
Parameters
titlestringDisplay title for this finally handler.
effectFunc<T, CancellationToken, Task>Cleanup action that receives the carried value.
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
Finally(string, Func<T, CancellationToken, ValueTask>)
Registers a cleanup handler with an explicit title that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(string title, Func<T, CancellationToken, ValueTask> effect)
Parameters
titlestringDisplay title for this finally handler.
effectFunc<T, CancellationToken, ValueTask>Cleanup action that receives the carried value.
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
Finally(string, Func<T, Task>)
Registers a cleanup handler with an explicit title that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(string title, Func<T, Task> effect)
Parameters
titlestringDisplay title for this finally handler.
effectFunc<T, Task>Cleanup action that receives the carried value.
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
Finally(string, Func<T, ValueTask>)
Registers a cleanup handler with an explicit title that executes after all steps complete. The handler receives the current chain value and executes even if subsequent steps fail.
public ThenChain<T> Finally(string title, Func<T, ValueTask> effect)
Parameters
titlestringDisplay title for this finally handler.
effectFunc<T, ValueTask>Cleanup action that receives the carried value.
Returns
- ThenChain<T>
The same ThenChain<T> for further chaining.
GetAwaiter()
Gets an awaiter that executes the queued scenario steps when awaited.
public ValueTaskAwaiter GetAwaiter()
Returns
- ValueTaskAwaiter
The awaiter for the underlying asynchronous execution.
When(Action<T>)
public ScenarioChain<T> When(Action<T> effect)
Parameters
effectAction<T>
Returns
When(Func<T, CancellationToken, Task>)
public ScenarioChain<T> When(Func<T, CancellationToken, Task> effect)
Parameters
effectFunc<T, CancellationToken, Task>
Returns
When(Func<T, CancellationToken, ValueTask>)
public ScenarioChain<T> When(Func<T, CancellationToken, ValueTask> effect)
Parameters
effectFunc<T, CancellationToken, ValueTask>
Returns
When(Func<T, Task>)
public ScenarioChain<T> When(Func<T, Task> effect)
Parameters
Returns
When(Func<T, ValueTask>)
public ScenarioChain<T> When(Func<T, ValueTask> effect)
Parameters
Returns
When(string, Action<T>)
public ScenarioChain<T> When(string title, Action<T> effect)
Parameters
Returns
When(string, Func<T, CancellationToken, Task>)
public ScenarioChain<T> When(string title, Func<T, CancellationToken, Task> effect)
Parameters
titlestringeffectFunc<T, CancellationToken, Task>
Returns
When(string, Func<T, CancellationToken, ValueTask>)
public ScenarioChain<T> When(string title, Func<T, CancellationToken, ValueTask> effect)
Parameters
titlestringeffectFunc<T, CancellationToken, ValueTask>
Returns
When(string, Func<T, Task>)
public ScenarioChain<T> When(string title, Func<T, Task> effect)
Parameters
Returns
When(string, Func<T, ValueTask>)
public ScenarioChain<T> When(string title, Func<T, ValueTask> effect)
Parameters
Returns
When<TOut>(Func<T, CancellationToken, Task<TOut>>)
public ScenarioChain<TOut> When<TOut>(Func<T, CancellationToken, Task<TOut>> f)
Parameters
fFunc<T, CancellationToken, Task<TOut>>
Returns
- ScenarioChain<TOut>
Type Parameters
TOut
When<TOut>(Func<T, CancellationToken, ValueTask<TOut>>)
public ScenarioChain<TOut> When<TOut>(Func<T, CancellationToken, ValueTask<TOut>> f)
Parameters
fFunc<T, CancellationToken, ValueTask<TOut>>
Returns
- ScenarioChain<TOut>
Type Parameters
TOut
When<TOut>(Func<T, Task<TOut>>)
public ScenarioChain<TOut> When<TOut>(Func<T, Task<TOut>> f)
Parameters
Returns
- ScenarioChain<TOut>
Type Parameters
TOut
When<TOut>(Func<T, ValueTask<TOut>>)
public ScenarioChain<TOut> When<TOut>(Func<T, ValueTask<TOut>> f)
Parameters
Returns
- ScenarioChain<TOut>
Type Parameters
TOut
When<TOut>(Func<T, TOut>)
public ScenarioChain<TOut> When<TOut>(Func<T, TOut> f)
Parameters
fFunc<T, TOut>
Returns
- ScenarioChain<TOut>
Type Parameters
TOut
When<TOut>(string, Func<T, CancellationToken, Task<TOut>>)
public ScenarioChain<TOut> When<TOut>(string title, Func<T, CancellationToken, Task<TOut>> f)
Parameters
titlestringfFunc<T, CancellationToken, Task<TOut>>
Returns
- ScenarioChain<TOut>
Type Parameters
TOut
When<TOut>(string, Func<T, CancellationToken, ValueTask<TOut>>)
public ScenarioChain<TOut> When<TOut>(string title, Func<T, CancellationToken, ValueTask<TOut>> f)
Parameters
titlestringfFunc<T, CancellationToken, ValueTask<TOut>>
Returns
- ScenarioChain<TOut>
Type Parameters
TOut
When<TOut>(string, Func<T, Task<TOut>>)
public ScenarioChain<TOut> When<TOut>(string title, Func<T, Task<TOut>> f)
Parameters
Returns
- ScenarioChain<TOut>
Type Parameters
TOut
When<TOut>(string, Func<T, ValueTask<TOut>>)
public ScenarioChain<TOut> When<TOut>(string title, Func<T, ValueTask<TOut>> f)
Parameters
Returns
- ScenarioChain<TOut>
Type Parameters
TOut
When<TOut>(string, Func<T, TOut>)
public ScenarioChain<TOut> When<TOut>(string title, Func<T, TOut> f)
Parameters
Returns
- ScenarioChain<TOut>
Type Parameters
TOut