Esempio n. 1
0
 public void DistinctDbTransactionCommitt()
 {
     using (GlobalTransactionManager.BeginTransaction())
     {
         Int32 count = DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test')").ExecuteNonQuery();
         Assert.That(count, Is.EqualTo(1));
         count = DataAccess.OnDb("secondary")
                 .CreateQuery("Insert into SecondaryFirstTable (field1, field2) values (1, 'test')")
                 .ExecuteNonQuery();
         Assert.That(count, Is.EqualTo(1));
     }
     DbAssert.OnQuery("Select count(*) cnt from FirstTable").That("cnt", Is.EqualTo(1)).ExecuteAssert();
     DbAssert.OnDb("secondary").WithQuery("Select count(*) cnt from SecondaryFirstTable").That("cnt", Is.EqualTo(1)).ExecuteAssert();
 }
Esempio n. 2
0
 public void DistinctDbTransactionAccessInTransaction()
 {
     using (GlobalTransactionManager.BeginTransaction())
     {
         DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test')")
         .ExecuteNonQuery();
         DataAccess.OnDb("secondary")
         .CreateQuery("Insert into SecondaryFirstTable (field1, field2) values (1, 'test')")
         .ExecuteNonQuery();
         //VErify that in transaction all data is queryable
         DbAssert.OnQuery("Select count(*) cnt from FirstTable").That("cnt", Is.EqualTo(1)).ExecuteAssert();
         DbAssert.OnDb("secondary").WithQuery("Select count(*) cnt from SecondaryFirstTable").That("cnt", Is.EqualTo(1)).ExecuteAssert();
         GlobalTransactionManager.DoomCurrentTransaction();
     }
 }
        public void TestEnlistInGlobalTransactionRead()
        {
            Int32 insertedId;

            using (GlobalTransactionManager.BeginTransaction())
            {
                using (ISession session = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml"))
                {
                    AnEntity e = AnEntity.CreateSome();
                    insertedId = (Int32)session.Save(e);
                }
                //We are still in the transaction, ensure we can read the db in the same transaction
                DbAssert.OnDb("main").WithQuery("select count(*) cnt from AnEntity where id = {id}")
                .SetInt32Param("id", insertedId)
                .That("cnt", Is.EqualTo(1)).ExecuteAssert();
            }
        }