Implementation of SessionScope that associates a single session within the using scope.

It is recommended to be used in the following type of scenario: using (new SessionScope()) { ... do multiple operation, possibly in multiple transactions. } At the end of "using", the session is automatically closed. All transactions within the scope use the same session, if you are using Spring's HibernateTemplate or using Spring's implementation of NHibernate 1.2's ICurrentSessionContext interface.

It is assumed that the session factory object name is called "SessionFactory". In case that you named the object in different way you can specify your can specify it in the application settings using the key Spring.Data.NHibernate.Support.SessionScope.SessionFactoryObjectName. Values for EntityInterceptorObjectName and SingleSessionMode can be specified similarly.

Note: The session is managed on a per thread basis on the thread that opens the scope instance. This means that you must never pass a reference to a SessionScope instance over to another thread!

상속: IDisposable
예제 #1
0
        public void SingleSessionNestedSessionParticipatesInParentScopeSessionFactory()
        {
            SessionScope scope = null;

            using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true))
            {
                Assert.IsTrue(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);

                using (SessionScope innerScope = new SessionScope(expectedSessionFactory, true))
                {
                    // outer scope didn't change
                    Assert.IsTrue(scope.IsOpen);
                    Assert.IsFalse(scope.IsParticipating);

                    // participating only - no SessionHolder will be registered!
                    Assert.IsTrue(innerScope.IsOpen);
                    Assert.IsTrue(innerScope.IsParticipating);

                    innerScope.Close();

                    Assert.IsFalse(innerScope.IsOpen);
                    Assert.IsFalse(innerScope.IsParticipating);

                    // outer scope didn't change
                    Assert.IsTrue(scope.IsOpen);
                    Assert.IsFalse(scope.IsParticipating);
                    Assert.IsTrue(TransactionSynchronizationManager.HasResource(expectedSessionFactory));
                }
            }

            // ensure scope is closed and sessionHolder is unregistered from TSM
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory));
        }
예제 #2
0
 public void OpeningTwiceThrowsInvalidOperationException()
 {
     using (SessionScope scope = new SessionScope(expectedSessionFactory, true))
     {
         scope.Open();
     }
 }
예제 #3
0
        public void ResolvesEntityInterceptorOnEachOpen()
        {
            TestSessionScopeSettings sss = Fake <TestSessionScopeSettings>(options => options
                                                                           .CallsBaseMethods()
                                                                           .WithArgumentsForConstructor(new[] { expectedSessionFactory })
                                                                           );
            ISession expectedSession = Fake <ISession>();

            sss.DefaultFlushMode = FlushMode.Never;

            SessionScope sc = new SessionScope(sss, false);

            CallTo(() => sss.DoResolveEntityInterceptor()).Returns(expectedEntityInterceptor);
            CallTo(() => expectedSessionFactory.OpenSession(expectedEntityInterceptor)).Returns(expectedSession);

            sc.Open();
            SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);

            sessionHolder.ContainsSession(null); // force opening session
            sc.Close();

            sc.Open();
            sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
            sessionHolder.ContainsSession(null); // force opening session
            sc.Close();

            CallToSet(() => expectedSession.FlushMode).WhenArgumentsMatch(x => x.Get <FlushMode>(0) == FlushMode.Never).MustHaveHappenedTwiceExactly();
            CallTo(() => expectedSession.Close()).MustHaveHappenedTwiceExactly();
        }
예제 #4
0
        public void CanCreateAndCloseSimpleCtor()
        {
            using (mocks.Ordered())
            {
                ISession session = mocks.StrictMock <ISession>();
                Expect.Call(expectedSessionFactory.OpenSession()).Return(session);
                session.FlushMode = FlushMode.Never;
                Expect.Call(session.Close()).Return(null);
            }
            mocks.ReplayAll();
            using (SessionScope scope = new SessionScope(expectedSessionFactory, true))
            {
                // no op - just create & dispose
                Assert.AreSame(expectedSessionFactory, scope.SessionFactory);
                //Assert.AreSame(null, scope.EntityInterceptor);
                Assert.AreEqual(expectedSingleSession, scope.SingleSession);
                Assert.AreEqual(expectedDefaultFlushMode, scope.DefaultFlushMode);

                // ensure SessionHolder object is registered with TSM
                Assert.IsTrue(TransactionSynchronizationManager.HasResource(expectedSessionFactory));

                SessionHolder sessionHolder =
                    (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
                // by default session is lazy, so ask for it.
                Assert.IsNotNull(sessionHolder.Session);
                scope.Close();
            }
            mocks.VerifyAll();
        }
예제 #5
0
        public void CanCreateAndCloseSimpleCtor()
        {
            ISession session = Fake <ISession>();

            CallTo(() => expectedSessionFactory.OpenSession()).Returns(session);

            using (SessionScope scope = new SessionScope(expectedSessionFactory, true))
            {
                // no op - just create & dispose
                Assert.AreSame(expectedSessionFactory, scope.SessionFactory);
                //Assert.AreSame(null, scope.EntityInterceptor);
                Assert.AreEqual(expectedSingleSession, scope.SingleSession);
                Assert.AreEqual(expectedDefaultFlushMode, scope.DefaultFlushMode);

                // ensure SessionHolder object is registered with TSM
                Assert.IsTrue(TransactionSynchronizationManager.HasResource(expectedSessionFactory));

                SessionHolder sessionHolder =
                    (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
                // by default session is lazy, so ask for it.
                Assert.IsNotNull(sessionHolder.Session);
                scope.Close();
            }

            CallToSet(() => session.FlushMode).WhenArgumentsMatch(x => x.Get <FlushMode>(0) == FlushMode.Never).MustHaveHappenedOnceExactly();
            CallTo(() => session.Close()).MustHaveHappenedOnceExactly();
        }
예제 #6
0
        public void CanCreateAndCloseSimpleCtor()
        {
            using (mocks.Ordered())
            {
                ISession session = mocks.StrictMock<ISession>();
                Expect.Call(expectedSessionFactory.OpenSession()).Return(session);
                session.FlushMode = FlushMode.Never;
                Expect.Call(session.Close()).Return(null);
            }
            mocks.ReplayAll();            
            using (SessionScope scope = new SessionScope(expectedSessionFactory, true))
            {
                // no op - just create & dispose
                Assert.AreSame(expectedSessionFactory, scope.SessionFactory);
                //Assert.AreSame(null, scope.EntityInterceptor);
                Assert.AreEqual(expectedSingleSession, scope.SingleSession);
                Assert.AreEqual(expectedDefaultFlushMode, scope.DefaultFlushMode);

                // ensure SessionHolder object is registered with TSM
                Assert.IsTrue(TransactionSynchronizationManager.HasResource(expectedSessionFactory));

                SessionHolder sessionHolder =
                    (SessionHolder) TransactionSynchronizationManager.GetResource(expectedSessionFactory);
                // by default session is lazy, so ask for it.
                Assert.IsNotNull(sessionHolder.Session);
                scope.Close();
            }
            mocks.VerifyAll();
        }
예제 #7
0
        public void DoesOpenImmediatelyOnOpenIsTrue()
        {
            SessionScope scope = null;

            using (scope = new SessionScope(expectedSessionFactory, true))
            {
                // ensure is open
                Assert.IsTrue(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);

                scope.Close();
                // ensure is closed
                Assert.IsFalse(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);
            }
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(scope.IsParticipating);

            using (scope = new SessionScope(expectedSessionFactory, true))
            {
                // ensure is open
                Assert.IsTrue(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);
            }
            // ensure dispose closes scope
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(scope.IsParticipating);
        }
예제 #8
0
 /// <summary>
 /// Initialize a new instance.
 /// </summary>
 public LazySessionHolder(SessionScope owner)
 {
     if (log.IsDebugEnabled)
     {
         log.Debug("Created LazySessionHolder");
     }
     this.owner = owner;
 }
예제 #9
0
 public void ClosingTwiceIsIgnored()
 {
     using (SessionScope scope = new SessionScope(expectedSessionFactory, true))
     {
         scope.Close();
         scope.Close();
     }
 }
예제 #10
0
        public void DisposeClosesScope()
        {
            SessionScope scope = new SessionScope(expectedSessionFactory, true);

            Assert.IsTrue(scope.IsOpen);
            scope.Dispose();
            Assert.IsFalse(scope.IsOpen);
        }
예제 #11
0
        public virtual void Init()
        {
            Log = LogManager.GetCurrentClassLogger();

            Log.Debug("初始化必须的对象 ----->");
            HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
            //HibernatingRhinos.NHibernate.Profiler.Appender.NHibernateProfiler.Initialize();

            var config = new AspMvcConfig();
            //MvcConfig.RootContext.
               Scope = new SessionScope("MySessionFactory".GetInstance<ISessionFactory>(), true);

            Log.Debug("测试开始 ----->");
        }
예제 #12
0
 /// <summary>
 /// Ensure session is closed (if any) and remove circular references to avoid memory leaks!
 /// </summary>
 public void Close()
 {
     owner = null;
     if (session != null)
     {
         ISession tmpSession = session;
         session = null;
         SessionFactoryUtils.CloseSession(tmpSession);
     }
     if (log.IsDebugEnabled)
     {
         log.Debug("Closed LazySessionHolder");
     }
 }
예제 #13
0
        public void CanCreateAndClose()
        {
            using (SessionScope scope = new SessionScope(expectedSessionFactory, expectedEntityInterceptor, expectedSingleSession, expectedDefaultFlushMode, false))
            {
                // no op - just create & dispose
                Assert.AreSame(expectedSessionFactory, scope.SessionFactory);
                Assert.AreSame(expectedEntityInterceptor, scope.EntityInterceptor);
                Assert.AreEqual(expectedSingleSession, scope.SingleSession);
                Assert.AreEqual(expectedDefaultFlushMode, scope.DefaultFlushMode);

                // ensure nothing got registered with TSM
                Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory));

                scope.Close();
            }
        }
예제 #14
0
        public void CanCreateAndClose()
        {
            using (SessionScope scope = new SessionScope(expectedSessionFactory, expectedEntityInterceptor, expectedSingleSession, expectedDefaultFlushMode, false))
            {
                // no op - just create & dispose
                Assert.AreSame(expectedSessionFactory, scope.SessionFactory);
                Assert.AreSame(expectedEntityInterceptor, scope.EntityInterceptor);
                Assert.AreEqual(expectedSingleSession, scope.SingleSession);
                Assert.AreEqual(expectedDefaultFlushMode, scope.DefaultFlushMode);

                // ensure nothing got registered with TSM
                Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory));

                scope.Close();
            }
        }
예제 #15
0
        public void SingleSessionAppliesDefaultFlushModeOnOpenSessionAndClosesSession()
        {
            ISession expectedSession = Fake <ISession>();

            CallTo(() => expectedSessionFactory.OpenSession()).Returns(expectedSession);

            SessionScope scope = null;

            using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true))
            {
                SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
                Assert.IsTrue(sessionHolder.ContainsSession(expectedSession));
            }
            // ensure scope is closed and sessionHolder is unregistered from TSM
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory));

            CallToSet(() => expectedSession.FlushMode).WhenArgumentsMatch(x => x.Get <FlushMode>(0) == FlushMode.Auto).MustHaveHappenedOnceExactly();
            CallTo(() => expectedSession.Close()).MustHaveHappenedOnceExactly();
        }
예제 #16
0
        public void SingleSessionRegistersSessionHolderWithTSM()
        {
            SessionScope scope = null;

            using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true))
            {
                // ensure is open
                Assert.IsTrue(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);

                // ensure registered sessionholder with TSM
                Assert.IsTrue(TransactionSynchronizationManager.HasResource(expectedSessionFactory));
                // ensure a sessionHolder is registered
                SessionHolder sessionHolder = TransactionSynchronizationManager.GetResource(expectedSessionFactory) as SessionHolder;
                Assert.IsNotNull(sessionHolder);
            }
            // ensure scope is closed and sessionHolder is unregistered from TSM
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory));
        }
예제 #17
0
        public void SingleSessionAppliesDefaultFlushModeOnOpenSessionAndClosesSession()
        {
            ISession expectedSession = mocks.StrictMock <ISession>();

            Expect.Call(expectedSessionFactory.OpenSession()).Return(expectedSession);
            expectedSession.FlushMode = FlushMode.Auto;
            Expect.Call(expectedSession.Close()).Return(null);
            mocks.ReplayAll();

            SessionScope scope = null;

            using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true))
            {
                SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
                Assert.IsTrue(sessionHolder.ContainsSession(expectedSession));
            }
            // ensure scope is closed and sessionHolder is unregistered from TSM
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory));

            mocks.VerifyAll();
        }
예제 #18
0
        public void DoesNotOpenImmediatelyOnOpenIsFalse()
        {
            SessionScope scope = null;

            using (scope = new SessionScope(expectedSessionFactory, false))
            {
                // ensure is *not* open
                Assert.IsFalse(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);

                scope.Open();
                // ensure is open now
                Assert.IsTrue(scope.IsOpen);

                scope.Close();
                // ensure is closed
                Assert.IsFalse(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);
            }
            // ensure is closed
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(scope.IsParticipating);
        }
예제 #19
0
        public void ResolvesEntityInterceptorOnEachOpen()
        {
            TestSessionScopeSettings sss =
                (TestSessionScopeSettings)mocks.PartialMock(typeof(TestSessionScopeSettings), expectedSessionFactory);
            ISession expectedSession = mocks.StrictMock <ISession>();

            sss.DefaultFlushMode = FlushMode.Never;

            SessionScope sc = new SessionScope(sss, false);

            using (mocks.Ordered())
            {
                Expect.Call(sss.DoResolveEntityInterceptor()).Return(expectedEntityInterceptor);
                Expect.Call(expectedSessionFactory.OpenSession(expectedEntityInterceptor)).Return(expectedSession);
                expectedSession.FlushMode = FlushMode.Never;
                Expect.Call(expectedSession.Close()).Return(null);

                Expect.Call(sss.DoResolveEntityInterceptor()).Return(expectedEntityInterceptor);
                Expect.Call(expectedSessionFactory.OpenSession(expectedEntityInterceptor)).Return(expectedSession);
                expectedSession.FlushMode = FlushMode.Never;
                Expect.Call(expectedSession.Close()).Return(null);
            }
            mocks.ReplayAll();

            sc.Open();
            SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);

            sessionHolder.ContainsSession(null); // force opening session
            sc.Close();

            sc.Open();
            sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
            sessionHolder.ContainsSession(null); // force opening session
            sc.Close();

            mocks.VerifyAll();
        }
예제 #20
0
 /// <summary>
 /// Ensure session is closed (if any) and remove circular references to avoid memory leaks!
 /// </summary>
 public void Close()
 {
     owner = null;
     if (session != null)
     {
         ISession tmpSession = session;
         session = null;
         SessionFactoryUtils.CloseSession(tmpSession);
     }
     if (log.IsDebugEnabled) log.Debug("Closed LazySessionHolder");
 }
예제 #21
0
        public void MultipleDBAccessUsingMultipleSessionScopes()
        {
            SessionScope scope1 = new SessionScope( (ISessionFactory) ctx["SessionFactory1"], false );
            SessionScope scope2 = new SessionScope( (ISessionFactory) ctx["SessionFactory2"], false );

            scope1.Open();
            scope2.Open();

            // do something
            MultipleDBAccess();

            scope1.Close();
            scope2.Close();
        }
예제 #22
0
 /// <summary>
 /// Initialize a new instance.
 /// </summary>
 public LazySessionHolder(SessionScope owner)
 {
     if (log.IsDebugEnabled) log.Debug("Created LazySessionHolder");
     this.owner = owner;
 }
예제 #23
0
 public void ClosingTwiceIsIgnored()
 {
     using (SessionScope scope = new SessionScope(expectedSessionFactory, true))
     {
         scope.Close();
         scope.Close();
     }
 }
예제 #24
0
 public void OpeningTwiceThrowsInvalidOperationException()
 {
     using (SessionScope scope = new SessionScope(expectedSessionFactory, true))
     {
         scope.Open();
     }
 }
예제 #25
0
        public void DoesOpenImmediatelyOnOpenIsTrue()
        {
            SessionScope scope = null;
            using (scope = new SessionScope(expectedSessionFactory, true))
            {
                // ensure is open
                Assert.IsTrue(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);

                scope.Close();
                // ensure is closed
                Assert.IsFalse(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);
            }
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(scope.IsParticipating);

            using (scope = new SessionScope(expectedSessionFactory, true))
            {
                // ensure is open
                Assert.IsTrue(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);
            }
            // ensure dispose closes scope
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(scope.IsParticipating);
        }
예제 #26
0
 public void DisposeClosesScope()
 {
     SessionScope scope = new SessionScope(expectedSessionFactory, true);
     Assert.IsTrue(scope.IsOpen);
     scope.Dispose();
     Assert.IsFalse(scope.IsOpen);
 }
예제 #27
0
        public void DoesNotOpenImmediatelyOnOpenIsFalse()
        {
            SessionScope scope = null;
            using (scope = new SessionScope(expectedSessionFactory, false))
            {
                // ensure is *not* open
                Assert.IsFalse(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);

                scope.Open();
                // ensure is open now
                Assert.IsTrue(scope.IsOpen);

                scope.Close();
                // ensure is closed
                Assert.IsFalse(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);
            }
            // ensure is closed
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(scope.IsParticipating);
        }
예제 #28
0
        public void SingleSessionRegistersSessionHolderWithTSM()
        {
            SessionScope scope = null;
            using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true))
            {
                // ensure is open
                Assert.IsTrue(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);

                // ensure registered sessionholder with TSM
                Assert.IsTrue(TransactionSynchronizationManager.HasResource(expectedSessionFactory));
                // ensure a sessionHolder is registered
                SessionHolder sessionHolder = TransactionSynchronizationManager.GetResource(expectedSessionFactory) as SessionHolder;
                Assert.IsNotNull(sessionHolder);
            }
            // ensure scope is closed and sessionHolder is unregistered from TSM
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory));
        }
예제 #29
0
        public void SingleSessionAppliesDefaultFlushModeOnOpenSessionAndClosesSession()
        {
            ISession expectedSession = mocks.StrictMock<ISession>();

            Expect.Call(expectedSessionFactory.OpenSession()).Return(expectedSession);
            expectedSession.FlushMode = FlushMode.Auto;
            Expect.Call(expectedSession.Close()).Return(null);
            mocks.ReplayAll();

            SessionScope scope = null;
            using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true))
            {
                SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
                Assert.IsTrue(sessionHolder.ContainsSession(expectedSession));
            }
            // ensure scope is closed and sessionHolder is unregistered from TSM
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory));

            mocks.VerifyAll();
        }
예제 #30
0
        public void SingleSessionNestedSessionParticipatesInParentScopeSessionFactory()
        {
            SessionScope scope = null;
            using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true))
            {
                Assert.IsTrue(scope.IsOpen);
                Assert.IsFalse(scope.IsParticipating);

                using (SessionScope innerScope = new SessionScope(expectedSessionFactory, true))
                {
                    // outer scope didn't change
                    Assert.IsTrue(scope.IsOpen);
                    Assert.IsFalse(scope.IsParticipating);

                    // participating only - no SessionHolder will be registered!
                    Assert.IsTrue(innerScope.IsOpen);
                    Assert.IsTrue(innerScope.IsParticipating);

                    innerScope.Close();

                    Assert.IsFalse(innerScope.IsOpen);
                    Assert.IsFalse(innerScope.IsParticipating);

                    // outer scope didn't change
                    Assert.IsTrue(scope.IsOpen);
                    Assert.IsFalse(scope.IsParticipating);
                    Assert.IsTrue(TransactionSynchronizationManager.HasResource(expectedSessionFactory));
                }
            }

            // ensure scope is closed and sessionHolder is unregistered from TSM
            Assert.IsFalse(scope.IsOpen);
            Assert.IsFalse(TransactionSynchronizationManager.HasResource(expectedSessionFactory));
        }
예제 #31
0
        public void ResolvesEntityInterceptorOnEachOpen()
        {
            TestSessionScopeSettings sss =
                (TestSessionScopeSettings)mocks.PartialMock(typeof(TestSessionScopeSettings), expectedSessionFactory);
            ISession expectedSession = mocks.StrictMock<ISession>();
            sss.DefaultFlushMode = FlushMode.Never;

            SessionScope sc = new SessionScope(sss, false);

            using (mocks.Ordered())
            {
                Expect.Call(sss.DoResolveEntityInterceptor()).Return(expectedEntityInterceptor);
                Expect.Call(expectedSessionFactory.OpenSession(expectedEntityInterceptor)).Return(expectedSession);
                expectedSession.FlushMode = FlushMode.Never;
                Expect.Call(expectedSession.Close()).Return(null);

                Expect.Call(sss.DoResolveEntityInterceptor()).Return(expectedEntityInterceptor);
                Expect.Call(expectedSessionFactory.OpenSession(expectedEntityInterceptor)).Return(expectedSession);
                expectedSession.FlushMode = FlushMode.Never;
                Expect.Call(expectedSession.Close()).Return(null);
            }
            mocks.ReplayAll();

            sc.Open();
            SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
            sessionHolder.ContainsSession(null); // force opening session
            sc.Close();

            sc.Open();
            sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
            sessionHolder.ContainsSession(null); // force opening session
            sc.Close();

            mocks.VerifyAll();
        }