Table of Contents

Class ScenarioContext

Namespace
TinyBDD
Assembly
TinyBDD.dll

Holds feature, scenario and step information during a single BDD run.

public sealed class ScenarioContext
Inheritance
ScenarioContext
Inherited Members
Extension Methods

Examples

var ctx = Bdd.CreateContext(this);
await Bdd.Given(ctx, "seed", () => 1)
         .When("+1", x => x + 1)
         .Then("== 2", v => v == 2);

ctx.AssertPassed();
foreach (var step in ctx.Steps)
    Console.WriteLine($"{step.Kind} {step.Title}: {(step.Error is null ? "OK" : step.Error.Message)}");

Remarks

A ScenarioContext is created via CreateContext(object, string?, ITraitBridge?, ScenarioOptions?) or set as ambient using Current when using the Flow API.

Test adapters use TraitBridge to register tags/categories with the underlying framework while steps are recorded in Steps as the scenario executes.

Constructors

ScenarioContext(string, string?, string, ITraitBridge, ScenarioOptions)

Creates a new scenario context.

public ScenarioContext(string featureName, string? featureDescription, string scenarioName, ITraitBridge traitBridge, ScenarioOptions options)

Parameters

featureName string

Feature name.

featureDescription string

Optional feature description.

scenarioName string

Scenario name.

traitBridge ITraitBridge

Bridge for traits/categories.

options ScenarioOptions

Scenario options.

Properties

CurrentItem

The current carried item (latest successful state).

public object? CurrentItem { get; }

Property Value

object

FeatureDescription

Optional human-readable feature description.

public string? FeatureDescription { get; }

Property Value

string

FeatureName

The logical feature under test, e.g. a capability in your system.

public string FeatureName { get; }

Property Value

string

IO

Running log of per-step inputs and outputs.

public IReadOnlyList<StepIO> IO { get; }

Property Value

IReadOnlyList<StepIO>

Options

Scenario options. See ScenarioOptions.

public ScenarioOptions Options { get; }

Property Value

ScenarioOptions

ScenarioName

The specific scenario name, typically the test method name or Name.

public string ScenarioName { get; }

Property Value

string

Steps

All recorded steps in execution order.

public IReadOnlyList<StepResult> Steps { get; }

Property Value

IReadOnlyList<StepResult>

Tags

All tags attached via TagAttribute on class/method or Tags.

public IReadOnlyCollection<string> Tags { get; }

Property Value

IReadOnlyCollection<string>

TraitBridge

Bridge for integrating tags/categories with a host test framework.

public ITraitBridge TraitBridge { get; }

Property Value

ITraitBridge

Methods

AddStep(StepResult)

Adds a recorded step to Steps. Can be used by generated code or custom step implementations.

public void AddStep(StepResult s)

Parameters

s StepResult

AddTag(string)

Adds a tag to the scenario and forwards it to TraitBridge.

public void AddTag(string tag)

Parameters

tag string

The tag name to add.

AddTags(IEnumerable<string>)

Adds one or more tags to the scenario context in bulk.

public void AddTags(IEnumerable<string> tags)

Parameters

tags IEnumerable<string>

An enumerable collection of string values representing the tags to be added. Each tag must be a non-empty string.

AddTags(params string[])

Adds one or more tags to the scenario context in bulk.

public void AddTags(params string[] tags)

Parameters

tags string[]

Array of string values representing the tags to be added. Each tag must be a non-empty string.

See Also