Created
July 23, 2013 04:17
-
-
Save robfe/6059822 to your computer and use it in GitHub Desktop.
string to boolean transforms for specflow step names
This file contains 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
[Binding] | |
public class StepArgumentTransforms | |
{ | |
static readonly List<string> _positives = "is,can,will,should,does,do,have,correct".Split(',').ToList(); | |
static readonly List<string> _negatives = "{0}n't,{0}not,{0} not,{0} no,in{0},un{0}".Split(',').SelectMany(s => _positives.Select(word => string.Format(s, word))).ToList(); | |
[StepArgumentTransformation] | |
public bool EnglishBool(string s) | |
{ | |
if (_positives.Contains(s)) | |
{ | |
return true; | |
} | |
if (_negatives.Contains(s)) | |
{ | |
return false; | |
} | |
throw new InvalidOperationException("Couldn't create a bool from "+s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment