Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv2180/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/Support
Modified Files:
SessionScopeTests.cs
Log Message:
fixed SPRNET-785 - removed EntityInterceptor caching
Index: SessionScopeTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/Support/SessionScopeTests.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SessionScopeTests.cs 23 Aug 2007 05:32:54 -0000 1.2
--- SessionScopeTests.cs 21 Mar 2008 01:17:12 -0000 1.3
***************
*** 52,56 ****
expectedEntityInterceptor = (IInterceptor)repository.CreateMock(typeof(IInterceptor));
expectedSingleSession = SessionScopeSettings.SINGLESESSION_DEFAULT;
! expectedDefaultFlushMode = SessionScopeSettings.FLUSHMODE_DEFAULT;
}
--- 52,56 ----
expectedEntityInterceptor = (IInterceptor)repository.CreateMock(typeof(IInterceptor));
expectedSingleSession = SessionScopeSettings.SINGLESESSION_DEFAULT;
! expectedDefaultFlushMode = SessionScopeSettings.FLUSHMODE_DEFAULT;
}
***************
*** 109,113 ****
{
// ensure is open
! Assert.IsTrue( scope.IsOpen );
Assert.IsFalse(scope.IsParticipating);
--- 109,113 ----
{
// ensure is open
! Assert.IsTrue(scope.IsOpen);
Assert.IsFalse(scope.IsParticipating);
***************
*** 189,193 ****
using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true))
{
! SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.GetResource(expectedSessionFactory);
Assert.IsTrue(sessionHolder.ContainsSession(expectedSession));
}
--- 189,193 ----
using (scope = new SessionScope(expectedSessionFactory, null, true, FlushMode.Auto, true))
{
! SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.GetResource(expectedSessionFactory);
Assert.IsTrue(sessionHolder.ContainsSession(expectedSession));
}
***************
*** 205,212 ****
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
--- 205,212 ----
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
***************
*** 235,238 ****
--- 235,292 ----
}
+ public class TestSessionScopeSettings : SessionScopeSettings
+ {
+ public TestSessionScopeSettings(ISessionFactory sessionFactory)
+ : base(sessionFactory)
+ {
+ }
+
+ protected override IInterceptor ResolveEntityInterceptor()
+ {
+ return DoResolveEntityInterceptor();
+ }
+
+ public virtual IInterceptor DoResolveEntityInterceptor()
+ {
+ return base.ResolveEntityInterceptor();
+ }
+ }
+
+ [Test]
+ public void ResolvesEntityInterceptorOnEachOpen()
+ {
+ TestSessionScopeSettings sss =
+ (TestSessionScopeSettings) repository.PartialMock(typeof (TestSessionScopeSettings), expectedSessionFactory);
+ ISession expectedSession = (ISession)repository.CreateMock(typeof(ISession));
+ sss.DefaultFlushMode = FlushMode.Never;
+
+ SessionScope sc = new SessionScope( sss, false );
+
+ using (repository.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);
+ }
+ repository.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();
+
+ repository.VerifyAll();
+ }
}
}
\ No newline at end of file
|