public void CannotCommitTransaction()
        {
            ITransactionAttribute txatt = new DefaultTransactionAttribute();
            MethodInfo m = typeof (ITestObject).GetMethod("GetDescription");
            MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();
            tas.AddTransactionalMethod(m, txatt);


            IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction();

            ITransactionStatus status = TransactionStatusForNewTransaction();
            Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status);
            UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null);
            ptm.Commit(status);
            LastCall.On(ptm).Throw(ex);
            mocks.ReplayAll();

            TestObject to = new TestObject();
            ITestObject ito = (ITestObject) Advised(to, ptm, tas);

            try
            {
                ito.GetDescription();
                Assert.Fail("Shouldn't have succeeded");
            } catch (UnexpectedRollbackException thrown)
            {
                Assert.IsTrue(thrown == ex);
            }

            mocks.VerifyAll();


            
        }
        public void DefaultTransactionAttributeToString()
        {
            DefaultTransactionAttribute source = new DefaultTransactionAttribute( );

            source.PropagationBehavior       = TransactionPropagation.Supports;
            source.TransactionIsolationLevel = IsolationLevel.RepeatableRead;
            source.TransactionTimeout        = 10;
            source.ReadOnly = true;

            TransactionAttributeEditor editor = new TransactionAttributeEditor( );

            editor.SetAsText(source.ToString( ));
            ITransactionAttribute ta = editor.Value;

            Assert.AreEqual(source, ta);
            Assert.AreEqual(ta.PropagationBehavior, TransactionPropagation.Supports);
            Assert.AreEqual(ta.TransactionIsolationLevel, IsolationLevel.RepeatableRead);
            Assert.AreEqual(ta.TransactionTimeout, 10);
            Assert.IsTrue(ta.ReadOnly);
            Assert.IsTrue(ta.RollbackOn(new SystemException( )));
            //mlp 3/17 changed rollback to rollback on all exceptions.
            Assert.IsTrue(ta.RollbackOn(new ApplicationException( )));

            source.TransactionTimeout = 9;
            Assert.IsFalse(ta == source);
            source.TransactionTimeout = 10;
            Assert.AreEqual(ta, source);
        }
        public void ProgrammaticRollback()
        {
            ITransactionAttribute txatt = new DefaultTransactionAttribute();
            MethodInfo            m     = typeof(RollbackTestObject).GetMethod("GetDescription");

            MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();

            tas.AddTransactionalMethod(m, txatt);

            ITransactionStatus status = TransactionStatusForNewTransaction();

            IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction();

            Expect.Call(ptm.GetTransaction(txatt)).Return(status).Repeat.Once();
            ptm.Commit(status);
            LastCall.On(ptm).Repeat.Once();

            mocks.ReplayAll();

            RollbackTestObject to = new RollbackTestObject();

            ITestObject ito = (ITestObject)Advised(to, ptm, tas);

            Assert.AreEqual("test description", ito.GetDescription());

            mocks.VerifyAll();
        }
        public void CannotCommitTransaction()
        {
            ITransactionAttribute txatt             = new DefaultTransactionAttribute();
            MethodInfo            m                 = typeof(ITestObject).GetMethod("GetDescription");
            MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();

            tas.AddTransactionalMethod(m, txatt);


            IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction();

            ITransactionStatus status = TransactionStatusForNewTransaction();

            Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status);
            UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null);

            ptm.Commit(status);
            LastCall.On(ptm).Throw(ex);
            mocks.ReplayAll();

            TestObject  to  = new TestObject();
            ITestObject ito = (ITestObject)Advised(to, ptm, tas);

            try
            {
                ito.GetDescription();
                Assert.Fail("Shouldn't have succeeded");
            } catch (UnexpectedRollbackException thrown)
            {
                Assert.IsTrue(thrown == ex);
            }

            mocks.VerifyAll();
        }
		public void RollbackOnTests()
		{
			DefaultTransactionAttribute dta = new DefaultTransactionAttribute();
			Assert.IsTrue( dta.RollbackOn( new SystemException()));
            //mlp 3/17 changed rollback to rollback on all exceptions.
			Assert.IsTrue( dta.RollbackOn( new TransactionSystemException()));
		}
        public void CannotCommitTransaction()
        {
            ITransactionAttribute txatt             = new DefaultTransactionAttribute();
            MethodInfo            m                 = typeof(ITestObject).GetMethod("GetDescription");
            MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();

            tas.AddTransactionalMethod(m, txatt);

            IPlatformTransactionManager ptm    = A.Fake <IPlatformTransactionManager>();
            ITransactionStatus          status = A.Fake <ITransactionStatus>();

            A.CallTo(() => ptm.GetTransaction(txatt)).Returns(status);
            UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null);

            A.CallTo(() => ptm.Commit(status)).Throws(ex);

            TestObject  to  = new TestObject();
            ITestObject ito = (ITestObject)Advised(to, ptm, tas);

            try
            {
                ito.GetDescription();
                Assert.Fail("Shouldn't have succeeded");
            }
            catch (UnexpectedRollbackException thrown)
            {
                Assert.IsTrue(thrown == ex);
            }
        }
        public void DefaultTransactionAttributeToString()
        {
            DefaultTransactionAttribute source = new DefaultTransactionAttribute( );
            source.PropagationBehavior = TransactionPropagation.Supports;
            source.TransactionIsolationLevel = IsolationLevel.RepeatableRead;
            source.TransactionTimeout = 10;
            source.ReadOnly = true;

            TransactionAttributeEditor editor = new TransactionAttributeEditor( );
            editor.SetAsText( source.ToString( ) );
            ITransactionAttribute ta = editor.Value;
            Assert.AreEqual( source, ta );
            Assert.AreEqual( ta.PropagationBehavior, TransactionPropagation.Supports );
            Assert.AreEqual( ta.TransactionIsolationLevel, IsolationLevel.RepeatableRead );
            Assert.AreEqual( ta.TransactionTimeout, 10 );
            Assert.IsTrue( ta.ReadOnly );
            Assert.IsTrue( ta.RollbackOn( new SystemException( ) ) );
            //mlp 3/17 changed rollback to rollback on all exceptions.
            Assert.IsTrue( ta.RollbackOn( new ApplicationException( ) ) );

            source.TransactionTimeout = 9;
            Assert.IsFalse( ta == source );
            source.TransactionTimeout = 10;
            Assert.AreEqual( ta, source );
        }
        public void RollbackOnTests()
        {
            DefaultTransactionAttribute dta = new DefaultTransactionAttribute();

            Assert.IsTrue(dta.RollbackOn(new SystemException()));
            //mlp 3/17 changed rollback to rollback on all exceptions.
            Assert.IsTrue(dta.RollbackOn(new TransactionSystemException()));
        }
        public void ProgrammaticRollback()
        {
            ITransactionAttribute txatt = new DefaultTransactionAttribute();
            MethodInfo            m     = typeof(RollbackTestObject).GetMethod("GetDescription");

            MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();

            tas.AddTransactionalMethod(m, txatt);

            ITransactionStatus status = A.Fake <ITransactionStatus>();

            IPlatformTransactionManager ptm = A.Fake <IPlatformTransactionManager>();

            A.CallTo(() => ptm.GetTransaction(txatt)).Returns(status).Once();

            RollbackTestObject to = new RollbackTestObject();

            ITestObject ito = (ITestObject)Advised(to, ptm, tas);

            Assert.AreEqual("test description", ito.GetDescription());

            A.CallTo(() => ptm.Commit(status)).MustHaveHappenedOnceExactly();
        }
        public void ProgrammaticRollback()
        {
            ITransactionAttribute txatt = new DefaultTransactionAttribute();
            MethodInfo m = typeof(RollbackTestObject).GetMethod("GetDescription");

            MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();
            tas.AddTransactionalMethod(m, txatt);

            ITransactionStatus status = TransactionStatusForNewTransaction();

            IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction();

            Expect.Call(ptm.GetTransaction(txatt)).Return(status).Repeat.Once();
            ptm.Commit(status);
            LastCall.On(ptm).Repeat.Once();

            mocks.ReplayAll();
            
            RollbackTestObject to = new RollbackTestObject();

            ITestObject ito = (ITestObject) Advised(to, ptm, tas);

            Assert.AreEqual("test description", ito.GetDescription());

            mocks.VerifyAll();


        }
        public void ToStringTests()
        {
            DefaultTransactionAttribute dta = new DefaultTransactionAttribute();

            Assert.AreEqual("PROPAGATION_Required,ISOLATION_Unspecified,-System.Exception", dta.ToString());
        }
		public void ToStringTests()
		{
			DefaultTransactionAttribute dta = new DefaultTransactionAttribute();
			Assert.AreEqual( "PROPAGATION_Required,ISOLATION_ReadCommitted,-System.Exception", dta.ToString());
		}