Ejemplo n.º 1
0
        public void InvokeTransactional()
        {
            ITestObject testObject             = TestObject;
            CallCountingTransactionManager ptm = ctx["transactionManager"] as CallCountingTransactionManager;

            Assert.IsNotNull(ptm);

            // try with transactional
            Assert.AreEqual(0, ptm.begun, "Should not have started any transactions");
            testObject.GetDescription();
            Assert.AreEqual(1, ptm.begun, "Should have 1 started transaction");
            Assert.AreEqual(1, ptm.commits, "Should have 1 committed transaction");

            // try with non-transaction
            int i = testObject.Age;

            Assert.IsNotNull(i);
            Assert.AreEqual(1, ptm.begun, "Should not have started another transaction");

            // try with exceptional
            try
            {
                testObject.Exceptional(new ArgumentNullException());
                Assert.Fail("Should not get here");
            } catch (Exception)
            {
                Assert.AreEqual(2, ptm.begun, "Should have another started transaction");
                Assert.AreEqual(1, ptm.rollbacks, "Should have 1 rolled back transaction");
            }
        }
        public void CoordinatorDeclarativeWithAttributes()
        {
            ITestCoord coord = ctx["testCoordinator"] as ITestCoord;

            Assert.IsNotNull(coord);
            CallCountingTransactionManager ccm = ctx["transactionManager"] as CallCountingTransactionManager;

            Assert.IsNotNull(ccm);
            LoggingAroundAdvice advice = (LoggingAroundAdvice)ctx["consoleLoggingAroundAdvice"];

            Assert.IsNotNull(advice);

            ITestObjectMgr testObjectMgr = ctx["testObjectManager"] as ITestObjectMgr;

            Assert.IsNotNull(testObjectMgr);
            //Proxied due to NameMatchMethodPointcutAdvisor
            Assert.IsTrue(AopUtils.IsAopProxy(coord));

            //Proxied due to DefaultAdvisorAutoProxyCreator
            Assert.IsTrue(AopUtils.IsAopProxy(testObjectMgr));


            TestObject to1 = new TestObject("Jack", 7);
            TestObject to2 = new TestObject("Jill", 6);

            Assert.AreEqual(0, ccm.begun);
            Assert.AreEqual(0, ccm.commits);
            Assert.AreEqual(0, advice.numInvoked);

            coord.WorkOn(to1, to2);

            Assert.AreEqual(1, ccm.begun);
            Assert.AreEqual(1, ccm.commits);
            Assert.AreEqual(1, advice.numInvoked);
        }
Ejemplo n.º 3
0
        public void ProxyDataAccessAndServiceLayer()
        {
            Assert.IsFalse(AopUtils.IsAopProxy(ctx["DbProvider"]));
            Assert.IsFalse(AopUtils.IsAopProxy(ctx["SessionFactory"]));
            Assert.IsFalse(AopUtils.IsAopProxy(ctx["hibernateTransactionManager"]));
            Assert.IsFalse(AopUtils.IsAopProxy(ctx["transactionManager"]));
            //Assert.IsTrue(AopUtils.IsAopProxy(ctx["testObjectDaoTransProxy"]));
            Assert.IsTrue(AopUtils.IsAopProxy(ctx["TestObjectDao"]));
            Assert.IsTrue(AopUtils.IsAopProxy(ctx["SimpleService"]));

            CallCountingTransactionManager ccm = ctx["transactionManager"] as CallCountingTransactionManager;

            Assert.IsNotNull(ccm);
            Assert.AreEqual(0, ccm.begun);
            Assert.AreEqual(0, ccm.commits);

            LoggingAroundAdvice caa = ctx["loggingAroundAdvice"] as LoggingAroundAdvice;

            Assert.IsNotNull(caa);
            Assert.AreEqual(0, caa.numInvoked);

            ISimpleService simpleService = ctx["SimpleService"] as ISimpleService;

            Assert.IsNotNull(simpleService);
            simpleService.DoWork(new TestObject());
            Assert.AreEqual(1, ccm.begun);
            Assert.AreEqual(1, ccm.commits);
            Assert.AreEqual(1, caa.numInvoked);
        }