Created
October 19, 2012 09:14
-
-
Save cairey/3917111 to your computer and use it in GitHub Desktop.
MSTestContrib BDD Extensions
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
namespace MSTestContrib.Specifications | |
{ | |
public static class BDDExtensions | |
{ | |
public static ThenGrammar Then(this WhenGrammar whenGrammar, string description, Action<SpecificationContext> implementation) | |
{ | |
Func<SpecificationContext, bool> implementationWithReturnTrue = (x) => | |
{ | |
implementation(x); | |
return true; | |
}; | |
var thenGrammar = new ThenGrammar(whenGrammar.Context, description, implementationWithReturnTrue, ThenGrammarPrefix.Then); | |
thenGrammar.Evaluate(); | |
return thenGrammar; | |
} | |
public static ThenGrammar And(this ThenGrammar thenGrammar, string description, Action<SpecificationContext> implementation) | |
{ | |
Func<SpecificationContext, bool> implementationWithReturnTrue = (x) => | |
{ | |
implementation(x); | |
return true; | |
}; | |
var thenGrammar1 = new ThenGrammar(thenGrammar.Context, description, implementationWithReturnTrue, ThenGrammarPrefix.Then); | |
thenGrammar1.Evaluate(); | |
return thenGrammar1; | |
} | |
public static ThenGrammar Then(this GivenGrammar givenGrammar, string description, Action<SpecificationContext> implementation) | |
{ | |
Func<SpecificationContext, bool> implementationWithReturnTrue = (x) => | |
{ | |
implementation(x); | |
return true; | |
}; | |
var thenGrammar = new ThenGrammar(givenGrammar.Context, description, implementationWithReturnTrue, ThenGrammarPrefix.Then); | |
thenGrammar.Evaluate(); | |
return thenGrammar; | |
} | |
public static GivenGrammar But(this GivenGrammar givenGrammar, string description, Action<SpecificationContext> implementation) | |
{ | |
var newGrammar = new GivenGrammar(givenGrammar.Context, description, implementation, GivenGrammarPrefix.And); | |
newGrammar.Evaluate(); | |
return newGrammar; | |
} | |
public static ThenGrammar But(this ThenGrammar thenGrammar, string description, Action<SpecificationContext> implementation) | |
{ | |
Func<SpecificationContext, bool> implementationWithReturnTrue = (x) => | |
{ | |
implementation(x); | |
return true; | |
}; | |
var newGrammar = new ThenGrammar(thenGrammar.Context, description, implementationWithReturnTrue, ThenGrammarPrefix.And); | |
newGrammar.Evaluate(); | |
return newGrammar; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment