Beispiel #1
0
        public void TransactionCommit()
        {
            IServiceDomainAdapter txAdapter = A.Fake <IServiceDomainAdapter>();

            A.CallTo(() => txAdapter.IsInTransaction).Returns(false).Once().Then.Returns(true).Once();

            //ProcessCommit - status.GlobalRollbackOnly check
            //DoCommit      - status.GlobalRollbackOnly check
            //DoCommit      - check to call SetComplete or SetAbort
            A.CallTo(() => txAdapter.MyTransactionVote).Returns(TransactionVote.Commit).NumberOfTimes(3);

            A.CallTo(() => txAdapter.Leave()).Returns(TransactionStatus.Commited).Once();

            ServiceDomainPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager(txAdapter);
            TransactionTemplate tt = new TransactionTemplate(tm);

            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            tt.Execute(TransactionCommitMethod);

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

            SimpleServiceConfig serviceConfig = new SimpleServiceConfig();

            ConfigureServiceConfig(serviceConfig, true);
            A.CallTo(() => txAdapter.Enter(serviceConfig)).MustHaveHappenedOnceExactly();
            A.CallTo(() => txAdapter.SetComplete()).MustHaveHappenedOnceExactly();
        }
Beispiel #2
0
        public void TransactionCommit()
        {
            #region Mock Setup
            IServiceDomainAdapter txAdapter = (IServiceDomainAdapter)mocks.CreateMock(typeof(IServiceDomainAdapter));
            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsInTransaction).Return(false);
                SimpleServiceConfig serviceConfig = new SimpleServiceConfig();
                ConfigureServiceConfig(serviceConfig, true);
                txAdapter.Enter(serviceConfig);

                //ProcessCommit - status.GlobalRollbackOnly check
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
                //DoCommit      - status.GlobalRollbackOnly check
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);

                Expect.Call(txAdapter.IsInTransaction).Return(true);
                //DoCommit      - check to call SetComplete or SetAbort
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
                txAdapter.SetComplete();
                Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Commited);
            }
            #endregion

            mocks.ReplayAll();

            IPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager(txAdapter);
            TransactionTemplate         tt = new TransactionTemplate(tm);
            tt.Execute(new TransactionDelegate(TransactionCommitMethod));

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

            mocks.VerifyAll();
        }
        public void PropagationRequiresNewWithExistingTransaction()
        {
            #region Mock Setup
            IServiceDomainAdapter txAdapter = (IServiceDomainAdapter)mocks.CreateMock(typeof(IServiceDomainAdapter));
            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsInTransaction).Return(false);
                SimpleServiceConfig serviceConfig = new SimpleServiceConfig();
                ConfigureServiceConfig(serviceConfig, true);
                txAdapter.Enter(serviceConfig);


                Expect.Call(txAdapter.IsInTransaction).Return(true);
                // inner tx
                ConfigureServiceConfig(serviceConfig, false);
                serviceConfig.TransactionOption = TransactionOption.RequiresNew;
                serviceConfig.IsolationLevel    = TransactionIsolationLevel.ReadCommitted;
                txAdapter.Enter(serviceConfig);
                Expect.Call(txAdapter.IsInTransaction).Return(true);
                txAdapter.SetAbort();
                Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Aborted);
                // innter tx aborted


                //ProcessCommit - status.GlobalRollbackOnly check
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
                //DoCommit      - status.GlobalRollbackOnly check
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);

                Expect.Call(txAdapter.IsInTransaction).Return(true);
                //DoCommit      - check to call SetComplete or SetAbort
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
                txAdapter.SetComplete();

                Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Commited);
            }
            #endregion

            mocks.ReplayAll();

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

            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(new PropagationRequiresNewWithExistingTransactionCallbackSD(tt));
            mocks.VerifyAll();
        }
        public void TransactionRollback()
        {
            #region Mock Setup
            IServiceDomainAdapter txAdapter = (IServiceDomainAdapter)mocks.CreateMock(typeof(IServiceDomainAdapter));
            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsInTransaction).Return(false);
                SimpleServiceConfig serviceConfig = new SimpleServiceConfig();
                ConfigureServiceConfig(serviceConfig, true);
                txAdapter.Enter(serviceConfig);
                Expect.Call(txAdapter.IsInTransaction).Return(true);
                txAdapter.SetAbort();
                Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Commited);
            }
            #endregion

            mocks.ReplayAll();

            ServiceDomainPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager(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(new TransactionRollbackTxCallback(ex));
                Assert.Fail("Should have thrown exception");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ex, e);
            }

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


            mocks.VerifyAll();
        }
        public void TransactionCommit()
        {
            #region Mock Setup
            IServiceDomainAdapter txAdapter = (IServiceDomainAdapter) mocks.CreateMock(typeof (IServiceDomainAdapter));
            using (mocks.Ordered())
            {
                Expect.Call(txAdapter.IsInTransaction).Return(false);
                SimpleServiceConfig serviceConfig = new SimpleServiceConfig();
                ConfigureServiceConfig(serviceConfig, true);
                txAdapter.Enter(serviceConfig);

                //ProcessCommit - status.GlobalRollbackOnly check
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
                //DoCommit      - status.GlobalRollbackOnly check
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);

                Expect.Call(txAdapter.IsInTransaction).Return(true);
                //DoCommit      - check to call SetComplete or SetAbort
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
                txAdapter.SetComplete();
                Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Commited);

            }
            #endregion

            mocks.ReplayAll();

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

            tt.Execute(new TransactionDelegate(TransactionCommitMethod));

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

            mocks.VerifyAll();

        }
Beispiel #6
0
        public void PropagationRequiresNewWithExistingTransaction()
        {
            IServiceDomainAdapter txAdapter = A.Fake <IServiceDomainAdapter>();

            A.CallTo(() => txAdapter.IsInTransaction)
            .Returns(false).Once()
            .Then.Returns(true).NumberOfTimes(3);

            A.CallTo(() => txAdapter.Leave())
            .Returns(TransactionStatus.Aborted).Once()
            .Then.Returns(TransactionStatus.Commited).Once();

            A.CallTo(() => txAdapter.MyTransactionVote).Returns(TransactionVote.Commit).NumberOfTimes(3);

            ServiceDomainPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager(txAdapter);

            tm.TransactionSynchronization = TransactionSynchronizationState.Always;

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(new PropagationRequiresNewWithExistingTransactionCallbackSD(tt));

            SimpleServiceConfig serviceConfig = new SimpleServiceConfig();

            ConfigureServiceConfig(serviceConfig, false);
            serviceConfig.TransactionOption = TransactionOption.RequiresNew;
            serviceConfig.IsolationLevel    = TransactionIsolationLevel.ReadCommitted;
            A.CallTo(() => txAdapter.Enter(serviceConfig)).MustHaveHappened();

            ConfigureServiceConfig(serviceConfig, false);
            serviceConfig.TransactionOption = TransactionOption.RequiresNew;
            serviceConfig.IsolationLevel    = TransactionIsolationLevel.ReadCommitted;
            A.CallTo(() => txAdapter.Enter(serviceConfig)).MustHaveHappened();

            A.CallTo(() => txAdapter.SetAbort()).MustHaveHappenedOnceExactly();
            A.CallTo(() => txAdapter.SetComplete()).MustHaveHappenedOnceExactly();
        }
Beispiel #7
0
        public void TransactionRollback()
        {
            SimpleServiceConfig serviceConfig = new SimpleServiceConfig();

            ConfigureServiceConfig(serviceConfig, standardIsolationAndProp: true);

            IServiceDomainAdapter txAdapter = A.Fake <IServiceDomainAdapter>();

            A.CallTo(() => txAdapter.IsInTransaction).Returns(false).Once().Then.Returns(true);
            A.CallTo(() => txAdapter.Leave()).Returns(TransactionStatus.Commited);

            ServiceDomainPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager(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(new TransactionRollbackTxCallback(ex));
                Assert.Fail("Should have thrown exception");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ex, e);
            }

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

            A.CallTo(() => txAdapter.SetAbort()).MustHaveHappenedOnceExactly();
            A.CallTo(() => txAdapter.Enter(serviceConfig)).MustHaveHappenedOnceExactly();
        }
        public void TransactionRollback()
        {
            #region Mock Setup
            IServiceDomainAdapter txAdapter = (IServiceDomainAdapter)mocks.CreateMock(typeof(IServiceDomainAdapter));
            using (mocks.Ordered())
            {

                Expect.Call(txAdapter.IsInTransaction).Return(false);
                SimpleServiceConfig serviceConfig = new SimpleServiceConfig();
                ConfigureServiceConfig(serviceConfig, true);
                txAdapter.Enter(serviceConfig);
                Expect.Call(txAdapter.IsInTransaction).Return(true);
                txAdapter.SetAbort();
                Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Commited);

            }
            #endregion

            mocks.ReplayAll();

            ServiceDomainPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager(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(new TransactionRollbackTxCallback(ex));
                Assert.Fail("Should have thrown exception");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ex, e);
            }

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


            mocks.VerifyAll();
        }
        public void PropagationRequiresNewWithExistingTransaction()
        {
            #region Mock Setup
            IServiceDomainAdapter txAdapter = (IServiceDomainAdapter)mocks.CreateMock(typeof(IServiceDomainAdapter));
            using (mocks.Ordered())
            {

                Expect.Call(txAdapter.IsInTransaction).Return(false);
                SimpleServiceConfig serviceConfig = new SimpleServiceConfig();
                ConfigureServiceConfig(serviceConfig, true);
                txAdapter.Enter(serviceConfig);


                Expect.Call(txAdapter.IsInTransaction).Return(true);
                // inner tx
                ConfigureServiceConfig(serviceConfig, false);
                serviceConfig.TransactionOption = TransactionOption.RequiresNew;
                serviceConfig.IsolationLevel = TransactionIsolationLevel.ReadCommitted;
                txAdapter.Enter(serviceConfig);
                Expect.Call(txAdapter.IsInTransaction).Return(true);
                txAdapter.SetAbort();
                Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Aborted);
                // innter tx aborted


                //ProcessCommit - status.GlobalRollbackOnly check
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
                //DoCommit      - status.GlobalRollbackOnly check
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);

                Expect.Call(txAdapter.IsInTransaction).Return(true);
                //DoCommit      - check to call SetComplete or SetAbort
                Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
                txAdapter.SetComplete();

                Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Commited);

            }
            #endregion 

            mocks.ReplayAll();

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

            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(new PropagationRequiresNewWithExistingTransactionCallbackSD(tt));
            mocks.VerifyAll();
        }