Last active
February 17, 2018 20:06
-
-
Save jeffjohnson9046/2e0562ecffa26c1844f473bbee809053 to your computer and use it in GitHub Desktop.
A C# class for rolling back database modifications after they've happened.
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
/// <summary> | |
/// A class for rolling back database transactions after the test has completed. | |
/// </summary> | |
[TestClass] | |
public abstract class TransactionRollbackIntegrationTestBase | |
{ | |
private TransactionScope transactionScope; | |
/// <summary> | |
/// Create the transaction scope to enforce creating a new transaction prior to the test executing. | |
/// </summary> | |
[TestInitialize] | |
public virtual void Setup() | |
{ | |
transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { Timeout = new TimeSpan(0, 10, 0) }); | |
} | |
/// <summary> | |
/// Rollback the transaction and cleanup the transaction scope after test execution completes. | |
/// </summary> | |
[TestCleanup] | |
public virtual void Teardown() | |
{ | |
Transaction.Current.Rollback(); | |
transactionScope.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment