public void SameSessionReturnedForConsequentCalls()
        {
            ISession session1 = NHibernateSessionManager.GetSessionFor("files\\NhConfig1.cfg.xml");
            ISession session2 = NHibernateSessionManager.GetSessionFor("files\\NhConfig1.cfg.xml");

            Assert.That(Object.ReferenceEquals(session1, session2));
        }
        public void TwoConfigurationReturnDistinctSessions()
        {
            ISession session1 = NHibernateSessionManager.GetSessionFor("files\\NhConfig1.cfg.xml");
            ISession session2 = NHibernateSessionManager.GetSessionFor("files\\NhConfig2.cfg.xml");

            Assert.That(!ReferenceEquals(session1, session2));
        }
        public void VerifyThatSessionIsDisposedWhenRollbackOccurredEvenIfCreatedOutsideTransaction()
        {
            ISession session1 = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml");

            using (GlobalTransactionManager.BeginTransaction())
            {
                GlobalTransactionManager.DoomCurrentTransaction();
            }
            Assert.That(session1.IsOpen, Is.False);
        }
        public void TestOuterDisposeOfTheSession()
        {
            ISession session1;

            using (session1 = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml"))
            {
            }
            ISession session2 = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml");

            Assert.That(session1, Is.Not.EqualTo(session2), "Same session returned even if we disposed outside the SessionManager");
        }
        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();
            }
        }
        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 TestEnlistInGlobalTransactionReadDataAccessWrittenData()
        {
            Int32 insertedId;

            using (GlobalTransactionManager.BeginTransaction())
            {
                Int32 newId = GetNewId();
                DataAccess.OnDb("main")
                .CreateQuery("insert into AnEntity (id, name, value) values ({pid}, {pname}, {pvalue})")
                .SetInt32Param("pid", newId)
                .SetStringParam("pname", "xxx")
                .SetInt32Param("pvalue", 108)
                .ExecuteNonQuery();
                using (ISession session = NHibernateSessionManager.GetSessionFor("files\\NhConfigFile1.cfg.xml"))
                {
                    AnEntity e = session.Load <AnEntity>(newId);
                    Assert.That(e.Name, Is.EqualTo("xxx"));
                    Assert.That(e.Value, Is.EqualTo(108));
                }
            }
        }
        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();
        }
        public void BasicGetSession()
        {
            ISession session = NHibernateSessionManager.GetSessionFor("files\\NhConfig1.cfg.xml");

            Assert.That(session, Is.Not.Null);
        }
 public void CloseSessionIsNoMoreInContext()
 {
     NHibernateSessionManager.GetSessionFor("files\\NhConfig1.cfg.xml");
     NHibernateSessionManager.CloseSessionFor("files\\NhConfig1.cfg.xml");
     Assert.That(overrideContext.storage.Count, Is.EqualTo(0));
 }
 public void TwoSessionIsInTheContext()
 {
     NHibernateSessionManager.GetSessionFor("files\\NhConfig1.cfg.xml");
     NHibernateSessionManager.GetSessionFor("files\\NhConfig2.cfg.xml");
     Assert.That(overrideContext.storage.Count, Is.EqualTo(2));
 }