Skip to content

Instantly share code, notes, and snippets.

@patroza
Created January 25, 2016 09:07
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 patroza/aaa6d287105bd53c5915 to your computer and use it in GitHub Desktop.
Save patroza/aaa6d287105bd53c5915 to your computer and use it in GitHub Desktop.
A slightly improved SpecsFor class
/// <summary>
/// A more closed version of the official SpecsFor class,
/// with some additional helpers
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class SpecsFor<T> : SpecsFor.SpecsFor<T>, IAnd<T> where T : class
{
protected abstract override void Given();
protected abstract override void When();
public sealed override void TearDown() => base.TearDown();
protected sealed override void InitializeClassUnderTest() => base.InitializeClassUnderTest();
/// <summary>
/// A fluent version of Given, so we can use expression bodies
/// </summary>
/// <typeparam name="TContext"></typeparam>
/// <returns></returns>
[UsedImplicitly]
protected new IAnd<T> Given<TContext>() where TContext : IContext<T>, new()
{
base.Given<TContext>();
return this;
}
IAnd<T> IAnd<T>.And<TContext>() => Given<TContext>();
}
public interface IAnd<T>
{
IAnd<T> And<TContext>() where TContext : IContext<T>, new();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment