Skip to content

Instantly share code, notes, and snippets.

@joebuschmann
Last active August 29, 2015 14:07
Show Gist options
  • Save joebuschmann/fedf72efd71d3b1f148d to your computer and use it in GitHub Desktop.
Save joebuschmann/fedf72efd71d3b1f148d to your computer and use it in GitHub Desktop.
Example of using a step argument transform to convert text to an enum value
[StepArgumentTransformation(@"from (A-Z|Z-A)")]
public SortOrder SortOrderTransform(string sortOrderPhrase)
{
if (sortOrderPhrase == "Z-A")
return SortOrder.Descending;
return SortOrder.Ascending;
}
[When(@"I sort by product name (.*)")]
public void WhenISortByProductName(SortOrder sortOrder)
{
_products.Sort((s1, s2) =>
{
if (sortOrder == SortOrder.Descending)
return s1.ProductName.CompareTo(s2.ProductName) * (-1);
return s1.ProductName.CompareTo(s2.ProductName);
});
int i = 1;
_products.ForEach(p => p.Index = i++);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment