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();
        }
Beispiel #2
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();
        }