コード例 #1
0
        public void ParticipatingTransactionWithCommit()
        {
            IConnectionFactory connectionFactory = mocks.StrictMock<IConnectionFactory>();
            IConnection connection = mocks.StrictMock<IConnection>();
            ISession session = mocks.StrictMock<ISession>();

            using (mocks.Ordered())
            {
                SetupCommitExpectations(connection, connectionFactory, session);
            }

            mocks.ReplayAll();

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate nt = new NmsTemplate(connectionFactory);
            nt.Execute(new AssertSessionCallback(session));

            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.Execute(delegate(ITransactionStatus status)
                           {
                               nt.Execute(new AssertSessionCallback(session));
                               return null;
                           });

            tm.Commit(ts);

            mocks.VerifyAll();
        }
コード例 #2
0
        public void ParticipatingTransactionWithCommit()
        {
            IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>();
            IConnection        connection        = A.Fake <IConnection>();
            ISession           session           = A.Fake <ISession>();

            SetupCreateSession(connection, connectionFactory, session);

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate           nt = new NmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.Execute(status =>
            {
                nt.Execute(new AssertSessionCallback(session));
                return(null);
            });

            tm.Commit(ts);

            AssertCommitExpectations(connection, connectionFactory, session);
        }
コード例 #3
0
        public void ParticipatingTransactionWithCommit()
        {
            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            IConnection        connection        = (IConnection)mocks.CreateMock(typeof(IConnection));
            ISession           session           = (ISession)mocks.CreateMock(typeof(ISession));

            using (mocks.Ordered())
            {
                SetupCommitExpectations(connection, connectionFactory, session);
            }

            mocks.ReplayAll();


            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate           nt = new NmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.Execute(delegate(ITransactionStatus status)
            {
                nt.Execute(new AssertSessionCallback(session));
                return(null);
            });

            tm.Commit(ts);

            mocks.VerifyAll();
        }
コード例 #4
0
        public void TransactionSuspension()
        {
            IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>();
            IConnection        connection        = A.Fake <IConnection>();
            ISession           session           = A.Fake <ISession>();
            ISession           session2          = A.Fake <ISession>();

            A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection).Twice();
            A.CallTo(() => connection.CreateSession(AcknowledgementMode.Transactional))
            .Returns(session).Once()
            .Then.Returns(session2).Once();

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate           nt = new NmsTemplate(connectionFactory);

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(status =>
            {
                nt.Execute(new AssertNotSameSessionCallback(session));
                return(null);
            });

            nt.Execute(new AssertSessionCallback(session));

            tm.Commit(ts);

            A.CallTo(() => session.Commit()).MustHaveHappenedOnceExactly();
            A.CallTo(() => session2.Commit()).MustHaveHappenedOnceExactly();
            A.CallTo(() => session.Close()).MustHaveHappenedOnceExactly();
            A.CallTo(() => session2.Close()).MustHaveHappenedOnceExactly();
            A.CallTo(() => connection.Close()).MustHaveHappenedTwiceExactly();
        }
コード例 #5
0
        public void ParticipatingTransactionWithRollback()
        {
            IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>();
            IConnection        connection        = A.Fake <IConnection>();
            ISession           session           = A.Fake <ISession>();

            SetupCreateSession(connection, connectionFactory, session);

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate           nt = new NmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.Execute(status =>
            {
                nt.Execute(new AssertSessionCallback(session));
                status.SetRollbackOnly();
                return(null);
            });
            try
            {
                tm.Commit(ts);
                Assert.Fail("Should have thrown UnexpectedRollbackException");
            } catch (UnexpectedRollbackException)
            {
            }

            AssertRollbackExpectations(connection, connectionFactory, session);
        }
コード例 #6
0
        public void TransactionSuspension()
        {
            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            IConnection        connection        = (IConnection)mocks.CreateMock(typeof(IConnection));
            ISession           session           = (ISession)mocks.CreateMock(typeof(ISession));
            ISession           session2          = (ISession)mocks.CreateMock(typeof(ISession));


            Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Twice();
            Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session).Repeat.Once();
            Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session2).Repeat.Once();

            session.Commit();
            LastCall.On(session).Repeat.Once();
            session2.Commit();
            LastCall.On(session2).Repeat.Once();

            session.Close();
            LastCall.On(session).Repeat.Once();
            session2.Close();
            LastCall.On(session2).Repeat.Once();

            connection.Close();
            LastCall.On(connection).Repeat.Twice();

            mocks.ReplayAll();

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate           nt = new NmsTemplate(connectionFactory);


            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(delegate(ITransactionStatus status)
            {
                nt.Execute(new AssertNotSameSessionCallback(session));
                return(null);
            });

            nt.Execute(new AssertSessionCallback(session));

            tm.Commit(ts);

            mocks.VerifyAll();
        }
コード例 #7
0
        public void TransactionCommit()
        {
            IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>();
            IConnection        connection        = A.Fake <IConnection>();
            ISession           session           = A.Fake <ISession>();

            SetupCreateSession(connection, connectionFactory, session);

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate           nt = new NmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));
            tm.Commit(ts);

            AssertCommitExpectations(connection, connectionFactory, session);
        }
コード例 #8
0
        public void SuspendedTransaction()
        {
            IConnectionFactory connectionFactory = mocks.StrictMock <IConnectionFactory>();
            IConnection        connection        = mocks.StrictMock <IConnection>();
            ISession           session           = mocks.StrictMock <ISession>();
            ISession           session2          = mocks.StrictMock <ISession>();

            Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Twice();
            Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session).Repeat.Once();
            Expect.Call(connection.CreateSession(AcknowledgementMode.AutoAcknowledge)).Return(session2).Repeat.Once();

            session.Commit();
            LastCall.On(session).Repeat.Once();
            session.Close();
            LastCall.On(session).Repeat.Once();

            session2.Close();
            LastCall.On(session2).Repeat.Once();

            connection.Close();
            LastCall.On(connection).Repeat.Twice();

            mocks.ReplayAll();

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate           nt = new NmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.PropagationBehavior = TransactionPropagation.NotSupported;
            tt.Execute(status =>
            {
                nt.Execute(new AssertNotSameSessionCallback(session));
                return(null);
            });

            nt.Execute(new AssertSessionCallback(session));

            tm.Commit(ts);

            mocks.VerifyAll();
        }
コード例 #9
0
        public void TransactionCommit()
        {
            IConnectionFactory connectionFactory = mocks.StrictMock<IConnectionFactory>();
            IConnection connection = mocks.StrictMock<IConnection>();
            ISession session = mocks.StrictMock<ISession>();

            using (mocks.Ordered())
            {
                SetupCommitExpectations(connection, connectionFactory, session);
            }

            mocks.ReplayAll();

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate nt = new NmsTemplate(connectionFactory);
            nt.Execute(new AssertSessionCallback(session));
            tm.Commit(ts);

            mocks.VerifyAll();
                
        }
コード例 #10
0
        public void TransactionCommit()
        {
            IConnectionFactory connectionFactory = mocks.StrictMock <IConnectionFactory>();
            IConnection        connection        = mocks.StrictMock <IConnection>();
            ISession           session           = mocks.StrictMock <ISession>();

            using (mocks.Ordered())
            {
                SetupCommitExpectations(connection, connectionFactory, session);
            }

            mocks.ReplayAll();

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate           nt = new NmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));
            tm.Commit(ts);

            mocks.VerifyAll();
        }
コード例 #11
0
        public void ParticipatingTransactionWithRollback()
        {
            IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            IConnection        connection        = (IConnection)mocks.CreateMock(typeof(IConnection));
            ISession           session           = (ISession)mocks.CreateMock(typeof(ISession));

            using (mocks.Ordered())
            {
                SetupRollbackExpectations(connection, connectionFactory, session);
            }

            mocks.ReplayAll();

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus    ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate           nt = new NmsTemplate(connectionFactory);

            nt.Execute(new AssertSessionCallback(session));

            TransactionTemplate tt = new TransactionTemplate(tm);

            tt.Execute(delegate(ITransactionStatus status)
            {
                nt.Execute(new AssertSessionCallback(session));
                status.SetRollbackOnly();
                return(null);
            });
            try
            {
                tm.Commit(ts);
                Assert.Fail("Should have thrown UnexpectedRollbackException");
            } catch (UnexpectedRollbackException)
            {
            }

            mocks.VerifyAll();
        }
コード例 #12
0
        public void ParticipatingTransactionWithRollback()
        {
            IConnectionFactory connectionFactory = mocks.StrictMock<IConnectionFactory>();
            IConnection connection = mocks.StrictMock<IConnection>();
            ISession session = mocks.StrictMock<ISession>();

            using (mocks.Ordered())
            {
                SetupRollbackExpectations(connection, connectionFactory, session);
            }

            mocks.ReplayAll();

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate nt = new NmsTemplate(connectionFactory);
            nt.Execute(new AssertSessionCallback(session));

            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.Execute(delegate(ITransactionStatus status)
                           {
                               nt.Execute(new AssertSessionCallback(session));
                               status.SetRollbackOnly();
                               return null;
                           });
            try
            {
                tm.Commit(ts);
                Assert.Fail("Should have thrown UnexpectedRollbackException");
            } catch (UnexpectedRollbackException)
            {

            }

            mocks.VerifyAll();
        }
コード例 #13
0
        public void TransactionSuspension()
        {
            IConnectionFactory connectionFactory = mocks.StrictMock<IConnectionFactory>();
            IConnection connection = mocks.StrictMock<IConnection>();
            ISession session = mocks.StrictMock<ISession>();
            ISession session2 = mocks.StrictMock<ISession>();

            Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Twice();
            Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session).Repeat.Once();
            Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session2).Repeat.Once();

            session.Commit();
            LastCall.On(session).Repeat.Once();
            session2.Commit();
            LastCall.On(session2).Repeat.Once();

            session.Close();
            LastCall.On(session).Repeat.Once();
            session2.Close();
            LastCall.On(session2).Repeat.Once();

            connection.Close();
            LastCall.On(connection).Repeat.Twice();

            mocks.ReplayAll();

            NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
            ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
            NmsTemplate nt = new NmsTemplate(connectionFactory);

            TransactionTemplate tt = new TransactionTemplate(tm);
            tt.PropagationBehavior = TransactionPropagation.RequiresNew;
            tt.Execute(delegate(ITransactionStatus status)
                           {
                               nt.Execute(new AssertNotSameSessionCallback(session));
                               return null;
                           });

            nt.Execute(new AssertSessionCallback(session));

            tm.Commit(ts);

            mocks.VerifyAll();
        }