Convert Specflow Step Argument in Table Cell Contents Using CreateInstance

Has anyone solved the puzzle of how to apply StepFlow Step Argument argument conversions to cells in a table in combination with SpecFlow.Assist CreateInstance / CreateSet? (code combined here to save space)

Given a table like the following:
 | Price | Zip   | Effective Date |
 | 10.00 | 90210 | in 2 days      |
When the 'given' step executes
And the table data populates a poco
Then the effective date should be transformed into a DateTime with value of 2 days from today

[Given(@"a table like the following:")]
public void GivenATableLikeTheFollowing(Table table)
{
    var temp = table.CreateInstance<Temp>();
}

internal class Temp
{
    decimal Price { get; set; }
    int Zip { get; set; }
    DateTime EffectiveDate { get; set; }
}

[Binding]
public class Transforms
{
    [StepArgumentTransformation(@"in (\d+) days?")]
    public DateTime InXDaysTransform(int days)
   {
      return DateTime.Today.AddDays(days);
   }
}

StepArgumentTransformation does not seem to relate to the contents of the table cell (since the step argument is a type table), but somehow SpecFlow.Assist CreateInstance / CreateSet still converts the cell data for the main types.

For example, if the contents of Effective Date are "11/13/2016" instead of "after 2 days", the base property of EffectiveDate poco is converted to DateTime just fine (or int, decimal, etc.).

, , StepArgumentTransformation , ... . : , StepArgumentTransformation CreateInstance/CreateSet.

HelpFlow Assist Assisters , / , DateTime . , , DateTime? , , StepArgumentTransformations - .

DateTime retriever, - ..

    public virtual DateTime GetValue(string value)
    {
        var returnValue = DateTime.MinValue;
        // check for StepArgumentTransformations here first?
        DateTime.TryParse(value, out returnValue);
        return returnValue;
    }

, , StepArgumentTransformation table.CreateInstance? ?

+4
2

, Assist, [StepArgumentTransformation].

, , , , . ( SpecFlow v2.0, .)

https://gist.github.com/gasparnagy/a478e5b7ccb8f557a6dc

+1

, , , , , . , , DateTimeValueRetriever , , -, , - [StepArgumentTransformation] , DateTimeValueRetriever . pr, , , , .

0

All Articles