Class StepExtensions
- Namespace
- TinyBDD.Extensions
- Assembly
- TinyBDD.dll
Extension methods for composing reusable step sequences.
public static class StepExtensions
- Inheritance
-
StepExtensions
- Inherited Members
Methods
ApplyEffect<T>(ScenarioChain<T>, Func<ScenarioChain<T>, ScenarioChain<T>>)
Applies a side-effect step that preserves the chain type.
public static ScenarioChain<T> ApplyEffect<T>(this ScenarioChain<T> chain, Func<ScenarioChain<T>, ScenarioChain<T>> steps)
Parameters
chainScenarioChain<T>The current scenario chain.
stepsFunc<ScenarioChain<T>, ScenarioChain<T>>A function that applies side-effect steps.
Returns
- ScenarioChain<T>
The same chain after applying the steps.
Type Parameters
TThe type carried by the chain.
ApplyThen<T, TIntermediate, TOut>(ScenarioChain<T>, Func<ScenarioChain<T>, ScenarioChain<TIntermediate>>, Func<ScenarioChain<TIntermediate>, ScenarioChain<TOut>>)
Chains multiple scenario steps together, allowing composition of reusable step definitions.
public static ScenarioChain<TOut> ApplyThen<T, TIntermediate, TOut>(this ScenarioChain<T> chain, Func<ScenarioChain<T>, ScenarioChain<TIntermediate>> first, Func<ScenarioChain<TIntermediate>, ScenarioChain<TOut>> second)
Parameters
chainScenarioChain<T>The current chain.
firstFunc<ScenarioChain<T>, ScenarioChain<TIntermediate>>First step sequence to apply.
secondFunc<ScenarioChain<TIntermediate>, ScenarioChain<TOut>>Second step sequence to apply.
Returns
- ScenarioChain<TOut>
The chain after applying both step sequences.
Type Parameters
TThe input type.
TIntermediateThe intermediate type.
TOutThe output type.
Apply<T>(ThenChain<T>, Func<ThenChain<T>, ThenChain<T>>)
Applies a reusable assertion sequence to the then chain.
public static ThenChain<T> Apply<T>(this ThenChain<T> chain, Func<ThenChain<T>, ThenChain<T>> assertions)
Parameters
chainThenChain<T>The current then chain.
assertionsFunc<ThenChain<T>, ThenChain<T>>A function that applies additional assertions.
Returns
- ThenChain<T>
The chain after applying the assertions.
Type Parameters
TThe type carried by the chain.
Examples
public static ThenChain<User> AssertValidUser(this ThenChain<User> chain)
=> chain
.And("has id", u => u.Id > 0)
.And("has name", u => !string.IsNullOrEmpty(u.Name));
await Given("a user", () => new User { Id = 1, Name = "John" })
.Then("exists", u => u != null)
.Apply(c => c.AssertValidUser())
.AssertPassed();
Apply<T, TOut>(ScenarioChain<T>, Func<ScenarioChain<T>, ScenarioChain<TOut>>)
Applies a reusable step sequence to the scenario chain.
public static ScenarioChain<TOut> Apply<T, TOut>(this ScenarioChain<T> chain, Func<ScenarioChain<T>, ScenarioChain<TOut>> steps)
Parameters
chainScenarioChain<T>The current scenario chain.
stepsFunc<ScenarioChain<T>, ScenarioChain<TOut>>A function that applies additional steps to the chain.
Returns
- ScenarioChain<TOut>
The chain after applying the steps.
Type Parameters
TThe input type of the chain.
TOutThe output type after applying the steps.
Examples
public static ScenarioChain<User> WithLoggedInUser(this ScenarioChain<object> chain)
=> chain.When("user logs in", _ => new User { IsLoggedIn = true });
await Given("system ready", () => new object())
.Apply(c => c.WithLoggedInUser())
.Then("user is logged in", u => u.IsLoggedIn)
.AssertPassed();