StepArgumentTransformation registers a method that converts text captured by a custom parameter placeholder into a value passed to a step definition. The method must be in a class marked with [Binding], and its attribute expression is a regular expression. section 12.3.4
When defining a transformation:
- Use capture groups to pass matched text to the conversion method. section 12.3.4
- Set Name to choose the custom parameter type’s name; if omitted, the return type name is used. section 12.3.4
- Keep transformation methods in a separate support class when appropriate, rather than adding them to step-definition classes. section 12.3.4
Listing 12.2 Custom parameter type
[StepArgumentTransformation("(red|blue|yellow)", Name = "color")]
public Color ConvertColor(string colorValue)
{
return new Color(colorValue);
}A color-name expression captures the matched text and converts it to a Color value. section 12.3.4
Recognizing named orders
A transformation can extend an {order} parameter to recognize text such as “order B” and look up its order number. Step-definition matching occurs before the captured text is matched to a transformation. section 17.2
