c# - Format a string in SpecFlow using Step Argument Conversion -


i wanted know if possible convert string string using step argument conversion. here example:

i have steps like:

when in element 'element' enter 'value'

those steps have accept different data, number, date , on. definition this:

    [when(@"in element '(.*)' enter '(.*)'")]     public void whenienterinelement(string element, string value)     {         enter(value, element);     } 

i accept things like:

when in element "element" enter "today plus 3 days"

and use step argument conversion like:

    [stepargumenttransformation(@"today plus (\d+) days")]     public string convertdate(int days)     {         return datetime.today.adddays(days).tostring();     } 

it isn't working because i'm trying convert string srting right? isn't there way step argument conversion?

it sounds really want reformat string, can restrict single binding method.

but

following conversions can performed specflow (in following precedence):
  • no conversion, if argument instance of parameter type (e.g. parameter type object or string)
  • step argument transformation
  • standard conversion
  • (from https://github.com/techtalk/specflow/wiki/step-argument-conversions)

    since method takes string parameter, no stepargumenttransformations used.

    you have 2 options

    1) use transformations each data type , method binding each type

    [when(@"in element '(.*)' enter '(.*)'")] public void whenienterinelement(string element, datetime value) {     enter(value, element.tostring()); }  [stepargumenttransformation(@"today plus (\d+) days")] public datetime convertdate(int days) {     return datetime.today.adddays(days); } 

    2) wrap string purposes of being able reuse step bindings different unparsed data

    public class wrappedstring {     public string value;     public wrappedstring(string value):value(value) {} }  [when(@"in element '(.*)' enter '(.*)'")] public void whenienterinelement(string element, wrappedstring value) {     enter(value, element.value); }  [stepargumenttransformation(@"today plus (\d+) days")] public wrappedstring convertdate(int days) {     return new wrappedstring(datetime.today.adddays(days).tostring()); } 

    1) perhaps cleaner, sounds scenario based little around being able manipulate text - in case (2) may model requirement.


    Comments

    Popular posts from this blog

    c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

    javascript - firefox memory leak -

    Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -