public void TransactionCommit()
        {
            ITransactionScopeAdapter txAdapter = A.Fake <ITransactionScopeAdapter>();

            A.CallTo(() => txAdapter.IsExistingTransaction).Returns(false);

            A.CallTo(() => txAdapter.RollbackOnly).Returns(false);

            TxScopeTransactionManager tm = new TxScopeTransactionManager(txAdapter);

            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.Execute(status =>
            {
                Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
                Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                return(null);
            });

            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);

            TransactionOptions txOptions = new TransactionOptions();

            txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
            txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, TransactionScopeAsyncFlowOption.Enabled);
            txAdapter.Complete();
            txAdapter.Dispose();
        }
        public void TransactionCommit()
        {
            ITransactionScopeAdapter txAdapter = (ITransactionScopeAdapter)mocks.CreateMock(typeof(ITransactionScopeAdapter));

            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsExistingTransaction).Return(false);
                TransactionOptions txOptions = new TransactionOptions();
                txOptions.IsolationLevel = IsolationLevel.Unspecified;
                txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, EnterpriseServicesInteropOption.None);

                Expect.Call(txAdapter.RollbackOnly).Return(false);
                txAdapter.Complete();
                txAdapter.Dispose();
            }
            mocks.ReplayAll();

            TxScopeTransactionManager tm = new TxScopeTransactionManager(txAdapter);

            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.Execute(status =>
            {
                Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
                Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                return(null);
            });

            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);

            mocks.VerifyAll();
        }
        public void TransactionCommit()
        {
            ITransactionScopeAdapter txAdapter = (ITransactionScopeAdapter) mocks.CreateMock(typeof(ITransactionScopeAdapter));

            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsExistingTransaction).Return(false);
                TransactionOptions txOptions = new TransactionOptions();
                txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
                txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, EnterpriseServicesInteropOption.None);

                Expect.Call(txAdapter.RollbackOnly).Return(false);
                txAdapter.Complete();
                txAdapter.Dispose();
            }
            mocks.ReplayAll();

            TxScopeTransactionManager tm = new TxScopeTransactionManager(txAdapter);
            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.Execute(status =>
                           {
                               Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
                               Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                               return null;
                           });

            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);   

            mocks.VerifyAll();


        }
        public void Rollback()
        {
            ITransactionSynchronization sync =
                (ITransactionSynchronization) mocks.DynamicMock(typeof (ITransactionSynchronization));
            sync.BeforeCompletion();
            LastCall.On(sync).Repeat.Once();
            sync.AfterCompletion(TransactionSynchronizationStatus.Rolledback);
            LastCall.On(sync).Repeat.Once();
            mocks.ReplayAll();

            TxScopeTransactionManager tm = new TxScopeTransactionManager();
            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.TransactionTimeout = 10;
            tt.Name = "txName";

            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
            tt.Execute(delegate (ITransactionStatus status)
                           {
                               Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
                               TransactionSynchronizationManager.RegisterSynchronization(sync);
                               Assert.AreEqual("txName", TransactionSynchronizationManager.CurrentTransactionName);
                               Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                               status.SetRollbackOnly();
                               return null;
                           }
            );

            mocks.VerifyAll();
        }
Beispiel #5
0
        public void Rollback()
        {
            ITransactionSynchronization sync = A.Fake <ITransactionSynchronization>();

            TxScopeTransactionManager tm = new TxScopeTransactionManager();

            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.TransactionTimeout = 10;
            tt.Name = "txName";

            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
            tt.Execute(status =>
            {
                Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
                TransactionSynchronizationManager.RegisterSynchronization(sync);
                Assert.AreEqual("txName", TransactionSynchronizationManager.CurrentTransactionName);
                Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                status.SetRollbackOnly();
                return(null);
            }
                       );

            A.CallTo(() => sync.BeforeCompletion()).MustHaveHappenedOnceExactly();
            A.CallTo(() => sync.AfterCompletion(TransactionSynchronizationStatus.Rolledback)).MustHaveHappenedOnceExactly();
        }
Beispiel #6
0
        public void Rollback()
        {
            ITransactionSynchronization sync =
                (ITransactionSynchronization)mocks.DynamicMock(typeof(ITransactionSynchronization));

            sync.BeforeCompletion();
            LastCall.On(sync).Repeat.Once();
            sync.AfterCompletion(TransactionSynchronizationStatus.Rolledback);
            LastCall.On(sync).Repeat.Once();
            mocks.ReplayAll();


            TxScopeTransactionManager tm = new TxScopeTransactionManager();
            TransactionTemplate       tt = new TransactionTemplate(tm);

            tt.TransactionTimeout = 10;
            tt.Name = "txName";

            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
            tt.Execute(delegate(ITransactionStatus status)
            {
                Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
                TransactionSynchronizationManager.RegisterSynchronization(sync);
                Assert.AreEqual("txName", TransactionSynchronizationManager.CurrentTransactionName);
                Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                status.SetRollbackOnly();
                return(null);
            }
                       );

            mocks.VerifyAll();
        }
Beispiel #7
0
        public void TransactionInformation()
        {
            TxScopeTransactionManager tm = new TxScopeTransactionManager();
            TransactionTemplate       tt = new TransactionTemplate(tm);

            tt.TransactionIsolationLevel = System.Data.IsolationLevel.ReadUncommitted;
            tt.Execute(TransactionInformationTxDelegate);
        }
        public void PropagationRequiresNewWithExistingTransaction()
        {
            ITransactionScopeAdapter txAdapter = (ITransactionScopeAdapter)mocks.CreateMock(typeof(ITransactionScopeAdapter));

            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsExistingTransaction).Return(false);
                TransactionOptions txOptions = new TransactionOptions();
                txOptions.IsolationLevel = IsolationLevel.Unspecified;
                txAdapter.CreateTransactionScope(TransactionScopeOption.RequiresNew, txOptions, EnterpriseServicesInteropOption.None);

                //inner tx actions
                Expect.Call(txAdapter.IsExistingTransaction).Return(true);
                txAdapter.CreateTransactionScope(TransactionScopeOption.RequiresNew, txOptions, EnterpriseServicesInteropOption.None);
                txAdapter.Dispose();
                //end inner tx actions

                Expect.Call(txAdapter.RollbackOnly).Return(false);
                txAdapter.Complete();
                txAdapter.Dispose();
            }
            mocks.ReplayAll();

            TxScopeTransactionManager tm = new TxScopeTransactionManager(txAdapter);

            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(status =>
            {
                Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
                Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
                Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);

                tt.Execute(status2 =>
                {
                    Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
                    Assert.IsTrue(status2.IsNewTransaction, "Is new transaction");
                    Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                    Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
                    status2.SetRollbackOnly();
                    return(null);
                });


                Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
                Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
                return(null);
            });

            mocks.VerifyAll();
        }
        public void PropagationRequiresNewWithExistingTransaction()
        {
            ITransactionScopeAdapter txAdapter = (ITransactionScopeAdapter)mocks.CreateMock(typeof(ITransactionScopeAdapter));

            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsExistingTransaction).Return(false);
                TransactionOptions txOptions = new TransactionOptions();
                txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
                txAdapter.CreateTransactionScope(TransactionScopeOption.RequiresNew, txOptions, EnterpriseServicesInteropOption.None);

                //inner tx actions
                Expect.Call(txAdapter.IsExistingTransaction).Return(true);
                txAdapter.CreateTransactionScope(TransactionScopeOption.RequiresNew, txOptions, EnterpriseServicesInteropOption.None);
                txAdapter.Dispose();
                //end inner tx actions

                Expect.Call(txAdapter.RollbackOnly).Return(false);
                txAdapter.Complete();
                txAdapter.Dispose();

            }
            mocks.ReplayAll();

            TxScopeTransactionManager tm = new TxScopeTransactionManager(txAdapter);
            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(delegate(ITransactionStatus status)
                           {
                               Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
                               Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
                               Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                               Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);

                               tt.Execute(delegate(ITransactionStatus status2)
                                              {
                                                  Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
                                                  Assert.IsTrue(status2.IsNewTransaction, "Is new transaction");
                                                  Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                                                  Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
                                                  status2.SetRollbackOnly();
                                                  return null;
                                              });

                               Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
                               Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                               Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
                               return null;
                           });

            mocks.VerifyAll();
        }
        public void PropagationRequiresNewWithExistingTransaction()
        {
            ITransactionScopeAdapter txAdapter = A.Fake <ITransactionScopeAdapter>();

            A.CallTo(() => txAdapter.IsExistingTransaction).Returns(false).Once();

            TransactionOptions txOptions = new TransactionOptions();

            txOptions.IsolationLevel = IsolationLevel.ReadCommitted;

            //inner tx actions
            A.CallTo(() => txAdapter.IsExistingTransaction).Returns(true).Once();
            //end inner tx actions

            A.CallTo(() => txAdapter.RollbackOnly).Returns(false);

            TxScopeTransactionManager tm = new TxScopeTransactionManager(txAdapter);

            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(status =>
            {
                Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
                Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
                Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);

                tt.Execute(status2 =>
                {
                    Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
                    Assert.IsTrue(status2.IsNewTransaction, "Is new transaction");
                    Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                    Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
                    status2.SetRollbackOnly();
                    return(null);
                });


                Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
                Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
                return(null);
            });

            A.CallTo(() => txAdapter.CreateTransactionScope(TransactionScopeOption.RequiresNew, txOptions, TransactionScopeAsyncFlowOption.Enabled)).MustHaveHappenedTwiceExactly();
            A.CallTo(() => txAdapter.Dispose()).MustHaveHappenedTwiceExactly();
            A.CallTo(() => txAdapter.Complete()).MustHaveHappenedOnceExactly();
        }
        public void TransactionRollback()
        {
            ITransactionScopeAdapter txAdapter = (ITransactionScopeAdapter)mocks.CreateMock(typeof(ITransactionScopeAdapter));

            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsExistingTransaction).Return(false);
                TransactionOptions txOptions = new TransactionOptions();
                txOptions.IsolationLevel = IsolationLevel.Unspecified;
                txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, EnterpriseServicesInteropOption.None);
                txAdapter.Dispose();
            }
            mocks.ReplayAll();

            TxScopeTransactionManager tm = new TxScopeTransactionManager(txAdapter);

            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);

            Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");

            Exception ex = new ArgumentException("test exception");

            try
            {
                tt.Execute(status =>
                {
                    Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
                    Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                    Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
                    if (ex != null)
                    {
                        throw ex;
                    }
                    return(null);
                });
                Assert.Fail("Should have thrown exception");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ex, e);
            }

            Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");


            mocks.VerifyAll();
        }
Beispiel #12
0
        public void Commit()
        {
            TxScopeTransactionManager tm = new TxScopeTransactionManager();
            TransactionTemplate       tt = new TransactionTemplate(tm);

            //tt.Name = "txName";

            Assert.AreEqual(TransactionSynchronizationState.Always, tm.TransactionSynchronization);
            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
            tt.Execute(CommitTxDelegate);
            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
        }
        public void Commit()
        {
            TxScopeTransactionManager tm = new TxScopeTransactionManager();
            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);

            //tt.Name = "txName";

            Assert.AreEqual(TransactionSynchronizationState.Always, tm.TransactionSynchronization);
            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
            tt.Execute(CommitTxDelegate);
            Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
            Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
            Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
        }
        public void TransactionRollback()
        {
            ITransactionScopeAdapter txAdapter = A.Fake <ITransactionScopeAdapter>();

            A.CallTo(() => txAdapter.IsExistingTransaction).Returns(false);
            TransactionOptions txOptions = new TransactionOptions();

            txOptions.IsolationLevel = IsolationLevel.ReadCommitted;

            TxScopeTransactionManager tm = new TxScopeTransactionManager(txAdapter);

            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);

            Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");

            Exception ex = new ArgumentException("test exception");

            try
            {
                tt.Execute(status =>
                {
                    Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
                    Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                    Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
                    if (ex != null)
                    {
                        throw ex;
                    }
                    return(null);
                });
                Assert.Fail("Should have thrown exception");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ex, e);
            }

            Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");
            A.CallTo(() => txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, TransactionScopeAsyncFlowOption.Enabled)).MustHaveHappenedOnceExactly();
            A.CallTo(() => txAdapter.Dispose()).MustHaveHappenedOnceExactly();
        }
 private static void SendUsingMessageTxScope(MessageQueueTemplate q)
 {
     IPlatformTransactionManager txManager = new TxScopeTransactionManager();
     TransactionTemplate transactionTemplate = new TransactionTemplate(txManager);
     transactionTemplate.Execute(status =>
                                     {
                                         q.ConvertAndSend("Hello World 1");
                                         q.ConvertAndSend("Hello World 2");
                                         q.ConvertAndSend("Hello World 3");
                                         return null;
                                     });
 }
 private void DoTxScopeBegin(TxScopeTransactionManager.PromotableTxScopeTransactionObject txObject,
                             Spring.Transaction.ITransactionDefinition definition)
 {
     TransactionScopeOption txScopeOption = CreateTransactionScopeOptions(definition);
     TransactionOptions txOptions = CreateTransactionOptions(definition);
     txObject.TxScopeAdapter.CreateTransactionScope(txScopeOption, txOptions, definition.EnterpriseServicesInteropOption);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HibernateTxScopeTransactionManager"/> class.
 /// </summary>
 public HibernateTxScopeTransactionManager()
 {
     txScopeTranactionManager = new TxScopeTransactionManager();
 }
        public void TransactionRollback()
        {
            ITransactionScopeAdapter txAdapter = (ITransactionScopeAdapter)mocks.CreateMock(typeof(ITransactionScopeAdapter));

            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsExistingTransaction).Return(false);
                TransactionOptions txOptions = new TransactionOptions();
                txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
                txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, EnterpriseServicesInteropOption.None);
                txAdapter.Dispose();
            }
            mocks.ReplayAll();

            TxScopeTransactionManager tm = new TxScopeTransactionManager(txAdapter);
            tm.TransactionSynchronization = TransactionSynchronizationState.Always;
            
            TransactionTemplate tt = new TransactionTemplate(tm);

            Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");

            Exception ex = new ArgumentException("test exception");
            try
            {
                tt.Execute(status =>
                               {
                                   Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
                                   Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
                                   Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
                                   if (ex != null) throw ex;
                                   return null;
                               });
                Assert.Fail("Should have thrown exception");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ex, e);
            }

            Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");


            mocks.VerifyAll();
        }
        public void TransactionInformation()
        {
            TxScopeTransactionManager tm = new TxScopeTransactionManager();
            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.TransactionIsolationLevel = System.Data.IsolationLevel.ReadUncommitted;
            tt.Execute(TransactionInformationTxDelegate);
        }