public void ResourcesAndCommit() { ITransaction transaction = tm.CreateTransaction(TransactionMode.Unspecified, IsolationMode.Unspecified); ResourceImpl resource = new ResourceImpl(); transaction.Enlist( resource ); Assert.IsFalse( resource.Started ); Assert.IsFalse( resource.Committed ); Assert.IsFalse( resource.Rolledback ); transaction.Begin(); Assert.IsTrue( resource.Started ); Assert.IsFalse( resource.Committed ); Assert.IsFalse( resource.Rolledback ); transaction.Commit(); Assert.IsTrue( resource.Started ); Assert.IsTrue( resource.Committed ); Assert.IsFalse( resource.Rolledback ); }
public void ResourcesAndCommit() { ITransaction transaction = tm.CreateTransaction(TransactionMode.Unspecified, IsolationMode.Unspecified); ResourceImpl resource = new ResourceImpl(); transaction.Enlist(resource); Assert.IsFalse(resource.Started); Assert.IsFalse(resource.Committed); Assert.IsFalse(resource.Rolledback); transaction.Begin(); Assert.IsTrue(resource.Started); Assert.IsFalse(resource.Committed); Assert.IsFalse(resource.Rolledback); transaction.Commit(); Assert.IsTrue(resource.Started); Assert.IsTrue(resource.Committed); Assert.IsFalse(resource.Rolledback); }
public void TransactionRolledBackEvent() { bool transactionCommittedEventTriggered = false; bool transactionRolledBackEventTriggered = false; bool transactionFailedEventTriggered = false; tm.TransactionCompleted += delegate { transactionCommittedEventTriggered = true; }; tm.TransactionRolledBack += delegate { transactionRolledBackEventTriggered = true; }; tm.TransactionFailed += delegate { transactionFailedEventTriggered = true; }; ITransaction transaction = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified); ResourceImpl resource = new ResourceImpl(); transaction.Enlist(resource); Assert.IsFalse(transactionCommittedEventTriggered); Assert.IsFalse(transactionRolledBackEventTriggered); Assert.IsFalse(transactionFailedEventTriggered); transaction.Begin(); Assert.IsFalse(transactionCommittedEventTriggered); Assert.IsFalse(transactionRolledBackEventTriggered); Assert.IsFalse(transactionFailedEventTriggered); transaction.Rollback(); Assert.IsFalse(transactionCommittedEventTriggered); Assert.IsTrue(transactionRolledBackEventTriggered); Assert.IsFalse(transactionFailedEventTriggered); }
public void DontStartResource_IfTransactionIsNotActive_WhenEnlisting() { var t = tm.CreateTransaction(TransactionMode.Unspecified, IsolationMode.Unspecified); var r = new ResourceImpl(); t.Enlist(r); Assert.That(r.Started, Is.False); t.Begin(); Assert.That(r.Started, Is.True); }
public void TransactionResources_AreDisposed() { var resource = new ResourceImpl(); using (var tx = _Tm.CreateTransaction(new DefaultTransactionOptions()).Value.Transaction) { tx.Inner.EnlistVolatile(resource, EnlistmentOptions.EnlistDuringPrepareRequired); tx.Rollback(); } Assert.That(resource.RolledBack); }
public void TransactionResources_AreDisposed() { var t = tm.CreateTransaction(TransactionMode.Requires, IsolationMode.Unspecified); var resource = new ResourceImpl(); t.Enlist(resource); t.Begin(); // lalala t.Rollback(); tm.Dispose(t); Assert.That(resource.wasDisposed); }
public void SameResourcesShared_BetweenParentAndChild_ParentsResponsibility() { var resource = new ResourceImpl(); ITransaction root = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified ); root.Begin(); root.Enlist(resource); var child1 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified ); Assert.IsTrue( child1 is ChildTransaction ); child1.Enlist(resource); child1.Begin(); child1.Commit(); root.Commit(); }
public void SameResources() { ResourceImpl resource = new ResourceImpl(); ITransaction root = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified ); root.Begin(); root.Enlist(resource); ITransaction child1 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified ); Assert.IsTrue( child1 is ChildTransaction ); child1.Enlist(resource); child1.Begin(); child1.Commit(); root.Commit(); }
public void SameResourcesShared_BetweenParentAndChild_ParentsResponsibility() { var resource = new ResourceImpl(); ITransaction root = tm.CreateTransaction(TransactionMode.Requires, IsolationMode.Unspecified); root.Begin(); root.Enlist(resource); var child1 = tm.CreateTransaction(TransactionMode.Requires, IsolationMode.Unspecified); Assert.IsTrue(child1 is ChildTransaction); child1.Enlist(resource); child1.Begin(); child1.Commit(); root.Commit(); }
public void SameResources() { ResourceImpl resource = new ResourceImpl(); ITransaction root = tm.CreateTransaction(TransactionMode.Requires, IsolationMode.Unspecified); root.Begin(); root.Enlist(resource); ITransaction child1 = tm.CreateTransaction(TransactionMode.Requires, IsolationMode.Unspecified); Assert.IsTrue(child1 is ChildTransaction); child1.Enlist(resource); child1.Begin(); child1.Commit(); root.Commit(); }
public void WhenOneResourceFails_OtherResourcesAreNotCommitted() { var first = new ResourceImpl(); var rfail = new ThrowsExceptionResourceImpl(true, false); var rsucc = new ResourceImpl(); var t = tm.CreateTransaction(TransactionMode.Requires, IsolationMode.Unspecified); t.Enlist(first); t.Enlist(rfail); t.Enlist(rsucc); t.Begin(); Assert.That(rfail.Started); Assert.That(rsucc.Started); Assert.Throws(typeof(CommitResourceException), t.Commit); Assert.That(first.Committed); Assert.That(rfail.Committed, Is.False); Assert.That(rsucc.Committed, Is.False); }