public void NewTransactionBeforeUsingStatelessSession()
        {
            ISessionManager manager = container.Resolve <ISessionManager>();

            ITransactionManager tmanager = container.Resolve <ITransactionManager>();

            ITransaction transaction = tmanager.CreateTransaction(
                TransactionMode.Requires,
                IsolationMode.Serializable);

            transaction.Begin();

            IStatelessSession session = manager.OpenStatelessSession();

            Assert.IsNotNull(session);
            Assert.IsNotNull(session.Transaction);

            transaction.Commit();

            // TODO: Assert transaction was committed
            // Assert.IsTrue(session.Transaction.WasCommitted);
            // Assert.IsTrue(session.IsConnected);

            session.Dispose();

            Assert.IsTrue(container.Resolve <ISessionStore>().IsCurrentActivityEmptyFor(Constants.DefaultAlias));
        }
        public void NewTransactionAfterUsingStatelessSession()
        {
            ISessionManager manager = container.Resolve <ISessionManager>();

            IStatelessSession session1 = manager.OpenStatelessSession();

            ITransactionManager tmanager = container.Resolve <ITransactionManager>();

            ITransaction transaction = tmanager.CreateTransaction(
                TransactionMode.Requires,
                IsolationMode.Serializable);

            transaction.Begin();

            // Nested
            using (IStatelessSession session2 = manager.OpenStatelessSession())
            {
                Assert.IsNotNull(session2);

                Assert.IsNotNull(session1);
                Assert.IsNotNull(session1.Transaction,
                                 "After requesting compatible session, first session is enlisted in transaction too.");
                Assert.IsTrue(session1.Transaction.IsActive,
                              "After requesting compatible session, first session is enlisted in transaction too.");

                using (ISession session3 = manager.OpenSession())
                {
                    Assert.IsNotNull(session3);
                    Assert.IsNotNull(session3.Transaction);
                    Assert.IsTrue(session3.Transaction.IsActive);
                }

                StatelessSessionDelegate delagate1 = (StatelessSessionDelegate)session1;
                StatelessSessionDelegate delagate2 = (StatelessSessionDelegate)session2;
                Assert.AreSame(delagate1.InnerSession, delagate2.InnerSession);
            }

            transaction.Commit();

            // TODO: Assert transaction was committed
            // Assert.IsTrue(session1.Transaction.WasCommitted);
            Assert.IsTrue(session1.IsConnected);

            session1.Dispose();

            Assert.IsTrue(container.Resolve <ISessionStore>().IsCurrentActivityEmptyFor(Constants.DefaultAlias));
        }
        public void SecondDatabaseStatelessSessionEnlistedOnlyOnceInActualTransaction()
        {
            ISessionManager manager = container.Resolve <ISessionManager>();

            ITransactionManager tmanager = container.Resolve <ITransactionManager>();

            ITransaction transaction = tmanager.CreateTransaction(
                TransactionMode.Requires,
                IsolationMode.Serializable);

            transaction.Begin();

            // open connection to first database and enlist session in running transaction
            IStatelessSession session1 = manager.OpenStatelessSession();

            // open connection to second database and enlist session in running transaction
            using (IStatelessSession session2 = manager.OpenStatelessSession("db2"))
            {
                Assert.IsNotNull(session2);
                Assert.IsNotNull(session2.Transaction);
            }
            // "real" NH session2 was not disposed because its in active transaction

            // request compatible session for db2 --> we must get existing NH session to db2 which should be already enlisted in active transaction
            using (IStatelessSession session3 = manager.OpenStatelessSession("db2"))
            {
                Assert.IsNotNull(session3);
                Assert.IsTrue(session3.Transaction.IsActive);
            }

            transaction.Commit();

            // TODO: Assert transaction was committed
            // Assert.IsTrue(session1.Transaction.WasCommitted);
            // Assert.IsTrue(session1.IsConnected);

            session1.Dispose();

            Assert.IsTrue(container.Resolve <ISessionStore>().IsCurrentActivityEmptyFor(Constants.DefaultAlias));
        }