Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A C# class for rolling back database modifications after they've happened.
/// <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
You can’t perform that action at this time.