public void TestMultiTransactionsWithRollback() { using (ISessionProvider provider = new SessionCacheProvider(this.SessionFactory.OpenSession, true, true)) { provider.BeginTransaction("first"); Assert.IsTrue(provider.InProgress); provider.BeginTransaction("second"); Assert.IsTrue(provider.InProgress); provider.BeginTransaction("third"); Assert.IsTrue(provider.InProgress); provider.CommitTransaction(); /* commit the third transaction. */ Assert.IsTrue(provider.InProgress); provider.RollbackTransaction(); /* this throws an exception because there are another inner transaction in progress. */ } }
public void SessionCachedWithNewSessionAfterCommitOrRollback() { using (ISessionProvider provider = new SessionCacheProvider(this.SessionFactory.OpenSession, true, true)) { INhPagedDAO dao = new EnterprisePagedDAO(provider); provider.BeginTransaction("first"); var res1 = dao.Load<Salesman>(1L, LockMode.Read); Assert.IsTrue(dao.IsCached(res1)); /* res1 is associated into the current session, so it's cached */ provider.CommitTransaction(); Assert.IsFalse(dao.IsCached(res1)); /* after commit the current session was closed and unreferenced, so res1 is not present in the new / next session to open. */ provider.BeginTransaction("second"); var res2 = dao.Load<Salesman>(1L, LockMode.Read); Assert.IsTrue(dao.IsCached(res2)); Assert.IsFalse(dao.IsCached(res1)); provider.RollbackTransaction(); Assert.IsFalse(dao.IsCached(res2)); provider.BeginTransaction("third"); var res3 = dao.Load<Salesman>(1L, LockMode.Read); Assert.AreNotSame(res1, res2); Assert.AreNotSame(res1, res3); Assert.AreNotSame(res2, res3); Assert.IsTrue(dao.IsCached(res3)); provider.CommitTransaction(); Assert.IsFalse(dao.IsCached(res3)); } }