Skip to content

Defining a custom step method

Michael W Powell edited this page Dec 8, 2020 · 1 revision

If the x method is not to your taste, it is trivial to define your own synonym. For instance,

public static class MyExtensions
{
    public static IStepBuilder o(this string text, Action body) => text.x(body);

    public static IStepBuilder ʃ(this string text, Action body) => text.x(body);

    public static IStepBuilder σʃσ(this string text, Action body) => text.x(body);

    public static IStepBuilder (this string text, Action body) => text.x(body);

    public static IStepBuilder χ(this string text, Action body) => text.x(body);
}

Note that to support object disposal and async steps you need to provide overloads of your custom step method which accept Action<IStepContext>, Func<Task> and Func<IStepContext, Task>. For example, the full set of custom step methods for o would be:

public static class MyExtensions
{
    public static IStepBuilder o(this string text, Action body) => text.x(body);

    public static IStepBuilder o(this string text, Action<IStepContext> body) => text.x(body);

    public static IStepBuilder o(this string text, Func<Task> body) => text.x(body);

    public static IStepBuilder o(this string text, Func<IStepContext, Task> body) => text.x(body);
}
Clone this wiki locally