-
-
Save marcusoftnet/1195044 to your computer and use it in GitHub Desktop.
[Binding] | |
public class DynamicStepArgumentTransformations | |
{ | |
[StepArgumentTransformation] | |
public IEnumerable<object> TransformToEnumerable(Table table) | |
{ | |
return table.CreateDynamicSet(); | |
} | |
[StepArgumentTransformation] | |
public IList<object> TransformToList(Table table) | |
{ | |
return table.CreateDynamicSet().ToList<object>(); | |
} | |
[StepArgumentTransformation] | |
public dynamic TransformToDynamicInstance(Table table) | |
{ | |
return table.CreateDynamicInstance(); | |
} | |
} | |
[Binding] | |
public class StepArgumentTransformationSteps | |
{ | |
[Given(@"I create a set of dynamic instances from this table using step argument transformation")] | |
public void a(IList<dynamic> dynamicSet) | |
{ | |
State.OriginalSet = dynamicSet; | |
} | |
[When(@"I compare the set to this table using step argument transformation")] | |
public void b(Table table) | |
{ | |
table.CompareToDynamicSet(State.OriginalSet); | |
} | |
[Given(@"I create a dynamic instance from this table using step argument transformation")] | |
public void c(dynamic instance) | |
{ | |
State.OriginalInstance = instance; | |
} | |
[When(@"I compare it to this table using step argument transformation")] | |
public void d(Table table) | |
{ | |
table.CompareToDynamicInstance((object)State.OriginalInstance); | |
} | |
} |
Hope everything is ok. Sorry, I wasn't trying to push, I just think it's a good idea. :)
Just a suggestion, but I think the IList example should probably be built first, using the existing 3.5 functionality. That feature can be added to SpecFlow today, as is, without having to upgrade to 4.0.
Part of any new 4.0 branch can include the IEnumerable. Or better yet, branch from the 4.0 branch so it is not dependent on the IEnumerable feature.
OK - either i totally failed to understand what is to be built or this was super-easy. The SpecFlow runtime had all the tools already. I simply used the StepArgumentTransformation.
I have a working version in the gist now.
It uses my DynamicExtension library (https://github.com/marcushammarberg/SpecFlow.Assist.Dynamic) for now but can easily be swaped to the main SpecFlow runtime when the dynamic stuff is moved there.
Also - to get this to work you have to use an configuration key - making the feature "opt-in" which might be nice i think.
I tried to get the transformation to work with the T (where T : class) but that threw on me. Probably some limitations in the current SpecFlow runtime.
What have i missed? What this what we talked about? Any ideas on the Transform thing?
Yes - it the Step argument conversions attribute I think (https://github.com/techtalk/SpecFlow/wiki/Step-Argument-Conversions).
As far as implementing it.... I have some stress related (I think) issues to deal with first. Seeing someone to find out what it is soon. Then I'll get on this.