Skip to content

Instantly share code, notes, and snippets.

@cairey
Created October 19, 2012 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cairey/3917111 to your computer and use it in GitHub Desktop.
Save cairey/3917111 to your computer and use it in GitHub Desktop.
MSTestContrib BDD Extensions
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