Skip to content

Step metadata

Michael W Powell edited this page Dec 8, 2020 · 2 revisions

The context object that is passed into a step delegate gives you access to metadata about the current step and scenario.

For example, you may want to interact with the file system isolate all your actions in a dedicated directory for the scenario:

[Scenario]
public void SomeScenario(string directory)
{
    "Given a directory".x(context => Directory.CreateDirectory(directory = context.Step.Scenario.DisplayName))
    //                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        .Rollback(() => Directory.Delete(directory));
    //                                   ^^^^^^^^^

    "When...".x(() => ...);

    "Then...".x(() => ...);
}
Clone this wiki locally