Table of Contents

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

chain ScenarioChain<T>

The current scenario chain.

steps Func<ScenarioChain<T>, ScenarioChain<T>>

A function that applies side-effect steps.

Returns

ScenarioChain<T>

The same chain after applying the steps.

Type Parameters

T

The 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

chain ScenarioChain<T>

The current chain.

first Func<ScenarioChain<T>, ScenarioChain<TIntermediate>>

First step sequence to apply.

second Func<ScenarioChain<TIntermediate>, ScenarioChain<TOut>>

Second step sequence to apply.

Returns

ScenarioChain<TOut>

The chain after applying both step sequences.

Type Parameters

T

The input type.

TIntermediate

The intermediate type.

TOut

The 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

chain ThenChain<T>

The current then chain.

assertions Func<ThenChain<T>, ThenChain<T>>

A function that applies additional assertions.

Returns

ThenChain<T>

The chain after applying the assertions.

Type Parameters

T

The 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

chain ScenarioChain<T>

The current scenario chain.

steps Func<ScenarioChain<T>, ScenarioChain<TOut>>

A function that applies additional steps to the chain.

Returns

ScenarioChain<TOut>

The chain after applying the steps.

Type Parameters

T

The input type of the chain.

TOut

The 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();