public void TestBasicInsertionQuery() { Int32 count = DataAccess.CreateQuery("Insert into TESTTABLE (field1, field2) values (1, 'test')").ExecuteNonQuery(); Assert.That(count, Is.EqualTo(1)); DbAssert.OnQuery("Select count(*) cnt from testtable").That("cnt", Is.EqualTo(1)).ExecuteAssert(); }
public void NoTransactionCommitt() { Int32 count = DataAccess.CreateQuery("Insert into FirstTable (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(); }
public void BasicTransactionRollback() { using (GlobalTransactionManager.BeginTransaction()) { Int32 count = DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test')").ExecuteNonQuery(); Assert.That(count, Is.EqualTo(1)); GlobalTransactionManager.DoomCurrentTransaction(); } DbAssert.OnQuery("Select count(*) cnt from FirstTable").That("cnt", Is.EqualTo(0)).ExecuteAssert(); }
public void TestSaveSaveAllData() { AnEntity ent = AnEntity.CreateSome(); sut.Save(ent); DbAssert.OnQuery("select Id, Name, Value from AnEntity where Id ={Id}") .SetInt32Param("Id", Invoker.GetProp <Int32>(ent, "Id")) .That("Name", Is.EqualTo(ent.Name)) .That("Value", Is.EqualTo(ent.Value)) .ExecuteAssert(); }
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(); }
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 MultipleTransactionRollbackAndCommit() { using (GlobalTransactionManager.BeginTransaction()) { using (GlobalTransactionManager.BeginTransaction()) { DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test1')").ExecuteNonQuery(); GlobalTransactionManager.DoomCurrentTransaction(); } DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test2')").ExecuteNonQuery(); } //inner transaction is rollbacked, but the external one no, so I should see second row DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); DbAssert.OnQuery("Select field2 from FirstTable") .That("field2", Is.EqualTo("test2")).ExecuteAssert(); }
public void TestEnlistInGlobalTransaction() { Int32 insertedId; using (GlobalTransactionManager.BeginTransaction()) { using (ISession session = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml")) { AnEntity e = AnEntity.CreateSome(); insertedId = (Int32)session.Save(e); } GlobalTransactionManager.DoomCurrentTransaction(); } DbAssert.OnQuery("select count(*) cnt from AnEntity where id = {id}") .SetInt32Param("id", insertedId) .That("cnt", Is.EqualTo(0)).ExecuteAssert(); }
public void MultipleTransactionSeeDataCommittedInNested() { using (GlobalTransactionManager.BeginTransaction()) { using (GlobalTransactionManager.BeginTransaction()) { Int32 count = DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test1')").ExecuteNonQuery(); Assert.That(count, Is.EqualTo(1)); } //First transaction is committed I should see data into db GlobalTransactionManager.DoomCurrentTransaction(); DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); } //Transaction is doomed, so the row disappeared DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(0)).ExecuteAssert(); }
public void MultipleTransactionFirstRollbackThenCommitt() { using (GlobalTransactionManager.BeginTransaction()) { using (GlobalTransactionManager.BeginTransaction()) { DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (1, 'test1')").ExecuteNonQuery(); GlobalTransactionManager.DoomCurrentTransaction(); } using (GlobalTransactionManager.BeginTransaction()) { DataAccess.CreateQuery("Insert into FirstTable (field1, field2) values (2, 'test2')").ExecuteNonQuery(); DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); } DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); } DbAssert.OnQuery("Select count(*) cnt from FirstTable") .That("cnt", Is.EqualTo(1)).ExecuteAssert(); }
public void TestSessionCanWorkWhenTransactionIsClosed() { Int32 insertedId; using (ISession session = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml")) { using (GlobalTransactionManager.BeginTransaction()) { AnEntity e = AnEntity.CreateSome(); session.Save(e); session.Flush(); } //Now the transaction is closed, session still need to work correctly AnEntity e1 = AnEntity.CreateSome(); insertedId = (Int32)session.Save(e1); session.Flush(); } //Need to see the second entity DbAssert.OnQuery("select count(*) cnt from AnEntity where id = {id}") .SetInt32Param("id", insertedId) .That("cnt", Is.EqualTo(1)).ExecuteAssert(); }