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
featureNamestringFeature name.
featureDescriptionstringOptional feature description.
scenarioNamestringScenario name.
traitBridgeITraitBridgeBridge for traits/categories.
optionsScenarioOptionsScenario options.
Properties
CurrentItem
The current carried item (latest successful state).
public object? CurrentItem { get; }
Property Value
FeatureDescription
Optional human-readable feature description.
public string? FeatureDescription { get; }
Property Value
FeatureName
The logical feature under test, e.g. a capability in your system.
public string FeatureName { get; }
Property Value
IO
Running log of per-step inputs and outputs.
public IReadOnlyList<StepIO> IO { get; }
Property Value
Options
Scenario options. See ScenarioOptions.
public ScenarioOptions Options { get; }
Property Value
ScenarioName
The specific scenario name, typically the test method name or Name.
public string ScenarioName { get; }
Property Value
Steps
All recorded steps in execution order.
public IReadOnlyList<StepResult> Steps { get; }
Property Value
Tags
All tags attached via TagAttribute on class/method or Tags.
public IReadOnlyCollection<string> Tags { get; }
Property Value
TraitBridge
Bridge for integrating tags/categories with a host test framework.
public ITraitBridge TraitBridge { get; }
Property Value
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
AddTag(string)
Adds a tag to the scenario and forwards it to TraitBridge.
public void AddTag(string tag)
Parameters
tagstringThe 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
tagsIEnumerable<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
tagsstring[]Array of string values representing the tags to be added. Each tag must be a non-empty string.