Table of Contents

Class ScenarioContextAsserts

Namespace
TinyBDD
Assembly
TinyBDD.dll

Assertion helpers for verifying the outcome of a recorded scenario.

public static class ScenarioContextAsserts
Inheritance
ScenarioContextAsserts
Inherited Members

Examples

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

// Verify success
ctx.AssertPassed();
var ctx = Bdd.CreateContext(this);
await Bdd.Given(ctx, "seed", () => 1)
         .When("boom", _ => throw new InvalidOperationException("nope"))
         .Then("unreached", () => Task.CompletedTask);

// Verify at least one failure was recorded
ctx.AssertFailed();

Remarks

These extensions inspect Steps to determine whether any step captured an error. They are intended to be called at the end of a scenario to validate its outcome in a test.

Methods

AssertFailed(ScenarioContext)

Ensures the scenario has at least one failed step. Throws InvalidOperationException when all steps passed.

public static void AssertFailed(this ScenarioContext ctx)

Parameters

ctx ScenarioContext

Exceptions

InvalidOperationException

Thrown when no failed steps are present.

AssertPassed(ScenarioContext)

Ensures the scenario has no failed steps. Throws InvalidOperationException if any recorded Error is non-null.

public static void AssertPassed(this ScenarioContext ctx)

Parameters

ctx ScenarioContext

Exceptions

InvalidOperationException

Thrown when at least one step failed.

See Also