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);
}
}
@darrencauthon
Copy link

Hope everything is ok. Sorry, I wasn't trying to push, I just think it's a good idea. :)

@marcusoftnet
Copy link
Author

marcusoftnet commented Sep 6, 2011 via email

@darrencauthon
Copy link

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.

@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