Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Defining a custom step method

Adam Ralph edited this page Mar 16, 2014 · 11 revisions

If the f and _ methods are not to your taste, it's trivial to define your own synonym(s). E.g.

public static class MyExtensions
{
    public static IStep x(this string text, Action body)
    {
        return text.f(body);
    }

    public static IStep ʃ(this string text, Action body)
    {
        return text.f(body);
    }

    public static IStep σʃσ(this string text, Action body)
    {
        return text.f(body);
    }

    public static IStep (this string text, Action body)
    {
        return text.f(body);
    }

    public static IStep χ(this string text, Action body)
    {
        return text.f(body);
    }
}

Note that to support all types of steps, you should also provide overloads of your custom step method which accept Action<IStepContext>, Func<Task> and Func<IStepContext, Task>. E.g. a full set of x custom step methods would be:

public static class MyExtensions
{
    public static IStep x(this string text, Action body)
    {
        return text.f(body);
    }

    public static IStep x(this string text, Action<IStepContext> body)
    {
        return text.f(body);
    }

    public static IStep x(this string text, Func<Task> body)
    {
        return text.f(body);
    }

    public static IStep x(this string text, Func<IStepContext, Task> body)
    {
        return text.f(body);
    }
}
Clone this wiki locally