public void AllowAccessToInternalProxy() { var session = SessionFactory.OpenSession(); var tpw = new BasicTransactionProtectionWrapper(session, null); var methodInfo = Reflector.PropertyGetter <ISessionProxy>(p => p.InvocationHandler); Assert.That(tpw.Invoke(methodInfo, null), Is.EqualTo(tpw)); session.Close(); }
public void ShouldCallTheDisposeActionInExplictSessionDispose() { bool disposeActionCalled = false; var session = SessionFactory.OpenSession(); var tpw = new BasicTransactionProtectionWrapper(session, null, s => disposeActionCalled = true); var methodInfo = Reflector.MethodInfo <ISession>(s => s.Dispose()); tpw.Invoke(methodInfo, null); Assert.That(disposeActionCalled); }
public void ShouldCallTheCloseActionInExplictSessionClose() { bool closeActionCalled = false; var session = SessionFactory.OpenSession(); var tpw = new BasicTransactionProtectionWrapper(session, s => { closeActionCalled = true; return(s); }); var methodInfo = Reflector.MethodInfo <ISession>(s => s.Close()); tpw.Invoke(methodInfo, null); Assert.That(closeActionCalled); }
public void ShouldNotProtectMethodsNotNeedingTransaction() { var notProtectedMethods = new[] { Reflector.PropertyGetter <ISession>(s => s.Statistics), Reflector.PropertyGetter <ISession>(s => s.IsOpen), Reflector.PropertyGetter <ISession>(s => s.FlushMode) }; var session = SessionFactory.OpenSession(); var tpw = new BasicTransactionProtectionWrapper(session, null); foreach (var notProtectedMethod in notProtectedMethods) { Assert.That(tpw.Invoke(notProtectedMethod, null), Is.EqualTo(BasicTransactionProtectionWrapperCrack.ContinueExecutionMarker)); } session.Close(); }
public void ShouldProtectMethodsNeedingTransaction() { var methods = new Expression <Action <ISession> >[] { s => s.CreateQuery("from System.Object"), s => s.CreateCriteria(typeof(object)), s => s.Load(typeof(object), 0), s => s.Get(typeof(object), 0) }; var session = SessionFactory.OpenSession(); var tpw = new BasicTransactionProtectionWrapper(session, null); foreach (var protectedMethod in Reflector.MethodsInfos(methods)) { Assert.Throws <HibernateException>(() => tpw.Invoke(protectedMethod, null)); } session.Close(); }