Esempio n. 1
0
        public void ExecuteScriptTransactedRollsbackIfNoCommit()
        {
            IDbProvider    dbProvider   = mocks.StrictMock <IDbProvider>();
            IDbConnection  dbConnection = mocks.StrictMock <IDbConnection>();
            IDbTransaction dbTx         = mocks.StrictMock <IDbTransaction>();
            DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();

            Expect.Call(dbProvider.CreateConnection()).Return(dbConnection);
            dbConnection.Open();
            Expect.Call(dbConnection.BeginTransaction(txDefinition.TransactionIsolationLevel)).Return(dbTx);
            dbTx.Rollback();
            dbConnection.Dispose();
            mocks.ReplayAll();

            AdoTemplate          adoOps = new AdoTemplate(dbProvider);
            IPlatformTransaction tx     = SimpleAdoTestUtils.CreateTransaction(dbProvider, txDefinition);

            tx.Dispose();
            mocks.VerifyAll();
        }
        public void ExecuteTransactionManager()
        {
            DefaultTransactionDefinition def = new DefaultTransactionDefinition();

            def.PropagationBehavior = TransactionPropagation.Required;

            ITransactionStatus status = transactionManager.GetTransaction(def);

            ITestObjectDao dao = (ITestObjectDao)ctx["NHTestObjectDao"];
            TestObject     to;

            try
            {
                to = dao.FindByName("Gabriel");
            }
            catch (Exception)
            {
                transactionManager.Rollback(status);
                throw;
            }
            transactionManager.Commit(status);
            Assert.IsNotNull(to, "FindByName for Gabriel should not return null");
            Assert.AreEqual("Gabriel", to.Name);
        }