Skip to content

Instantly share code, notes, and snippets.

@marcusoftnet
Created September 5, 2011 13:57
Show Gist options
  • Save marcusoftnet/1195044 to your computer and use it in GitHub Desktop.
Save marcusoftnet/1195044 to your computer and use it in GitHub Desktop.
SpecFlow ... using method binders... or what we should call them
[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);
}
}
@marcusoftnet
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment