Before and After actions
WARNING
The Before/After actions are not additive. The last one specified is the only one executed.
Alba allows you to 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:
cs
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;
});
}