Example #1
0
        public void DirectSqlPassThroughWithoutTransactionShouldNotCommit()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.LogAdapter  = new TestLogAdapter();
            pm.VerboseMode = true;
            ISqlPassThroughHandler sqlHandler = pm.GetSqlPassThroughHandler();
            var    reader = sqlHandler.Execute("DELETE FROM Mitarbeiter");
            string log    = pm.LogAdapter.ToString();

            Assert.That(log.IndexOf("Completing") == -1, "Transaction should be committed");
            Assert.That(log.IndexOf("Creating a new TransactionScope") == -1, "Transaction should be committed");
            Assert.Null(reader, "Reader should be null");
        }
Example #2
0
        public void DirectSqlPassThroughWithCombinedStatementsDoesNotCommit()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.LogAdapter  = new TestLogAdapter();
            pm.VerboseMode = true;
            using (ISqlPassThroughHandler sqlHandler = pm.GetSqlPassThroughHandler())
            {
                sqlHandler.Execute("DELETE FROM Mitarbeiter");
                sqlHandler.Execute("DELETE FROM Reise");
            }
            string log = pm.LogAdapter.ToString();

            Assert.That(log.IndexOf("Completing") == -1, "Transaction should not be committed");
        }
Example #3
0
        public void DirectSqlPassThroughWithTransactionShouldCommit()
        {
            var pm = PmFactory.NewPersistenceManager();

            pm.LogAdapter  = new TestLogAdapter();
            pm.VerboseMode = true;
            ISqlPassThroughHandler sqlHandler = pm.GetSqlPassThroughHandler();

            sqlHandler.BeginTransaction();
            sqlHandler.Execute("DELETE FROM Mitarbeiter");
            sqlHandler.Execute("DELETE FROM Reise");
            sqlHandler.CommitTransaction();
            string log = pm.LogAdapter.ToString();

            Assert.That(new Regex("Creating a new TransactionScope").Matches(log).Count == 1, "One Transactions should be started");
            Assert.That(new Regex("Completing").Matches(log).Count == 1, "One Transactions should be committed");
        }
Example #4
0
        public void DirectSqlPassWithAbortWorks()
        {
            var pm = PmFactory.NewPersistenceManager();
            var m  = new Mitarbeiter();

            pm.MakePersistent(m);
            pm.Save();
            pm.UnloadCache();
            pm.LogAdapter  = new TestLogAdapter();
            pm.VerboseMode = true;
            using (ISqlPassThroughHandler sqlHandler = pm.GetSqlPassThroughHandler())
            {
                sqlHandler.BeginTransaction();
                sqlHandler.Execute("DELETE FROM Mitarbeiter");
                pm.Abort();
            }
            bool hasRecords = new NDOQuery <Mitarbeiter>(pm).Execute().Count > 0;

            Assert.That(hasRecords, "At least one record should be present");
        }