Last active
August 29, 2015 14:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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