Before and after actions

WARNING

The Before/After actions are not additive. The last one specified is the only one executed.

As of Alba 2.0, you can specify actions that run immediately before or after an HTTP request is executed for common setup or teardown work like setting up authentication credentials or tracing or whatever.

Here's a sample:

public void sample_usage(AlbaHost system)
{
    // Synchronously
    system.BeforeEach(context =>
    {
        // Modify the HttpContext immediately before each
        // Scenario()/HTTP request is executed
        context.Request.Headers.Add("trace", "something");
    });

    system.AfterEach(context =>
    {
        // perform an action immediately after the scenario/HTTP request
        // is executed
    });

    // Asynchronously
    system.BeforeEachAsync(context =>
    {
        // do something asynchronous here
        return Task.CompletedTask;
    });

    system.AfterEachAsync(context =>
    {
        // do something asynchronous here
        return Task.CompletedTask;
    });

}

snippet source | anchor