public void TransactionRollback() { TestDatabase database = new TestDatabase(); // 'false' indicates that it will vote 'Rollback' FakeEnlistmentNotification enlistment = new FakeEnlistmentNotification(false); try { using (TransactionScope tran = new TransactionScope()) { Transaction.Current.EnlistVolatile(enlistment, EnlistmentOptions.EnlistDuringPrepareRequired); database.Members.Insert(new Member { Id = "A" }); tran.Complete(); } } catch { } Assert.AreEqual(0, database.Members.Count); Assert.IsFalse(database.Members.Any(m => m.Id == "A")); Assert.IsTrue(enlistment.WasRollback); Assert.IsFalse(enlistment.WasCommit); }
public void NestedTransaction() { FakeEnlistmentNotification en1 = new FakeEnlistmentNotification(true); FakeEnlistmentNotification en2 = new FakeEnlistmentNotification(true); using (TransactionScope tran1 = new TransactionScope()) { Transaction.Current.EnlistVolatile(en1, EnlistmentOptions.EnlistDuringPrepareRequired); using (TransactionScope tran2 = new TransactionScope()) { Transaction.Current.EnlistVolatile(en2, EnlistmentOptions.EnlistDuringPrepareRequired); tran2.Complete(); } var current = Transaction.Current; tran1.Complete(); } }