Created
March 27, 2012 12:40
-
-
Save i-e-b/2215515 to your computer and use it in GitHub Desktop.
Context wrapper for MSpec
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
#pragma warning disable 169 // ReSharper disable StaticFieldInGenericType, InconsistentNaming | |
using System; | |
using System.Transactions; | |
namespace Machine.Specifications { | |
public abstract class ContextAndResult<TSubject, TResult> { | |
protected static Exception the_exception; | |
protected static TSubject subject; | |
protected static TResult result; | |
/// <summary> | |
/// Use like <code>Because it = ShouldFail(() => subject.do(something));</code> | |
/// </summary> | |
protected static Because ShouldFail (Action throwingCase) { | |
return () => { the_exception = Catch.Exception(throwingCase); }; | |
} | |
} | |
public abstract class ContextOf<TSubject> : ContextAndResult<TSubject, object> { } | |
public abstract class DatabaseContextOf<TSubject> : DatabaseContextAndResult<TSubject, object> { } | |
public abstract class DatabaseContextAndResult<TSubject, TResult> : ContextAndResult<TSubject, TResult> { | |
private static TransactionScope scope; | |
Establish database_context = () => { scope = new TransactionScope(); }; | |
Cleanup database_cleanup = () => { if (scope != null) scope.Dispose(); }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment