Пример #1
0
        public void TestBasicOperationsWithInterfaceService()
        {
            WindsorContainer container = new WindsorContainer(new DefaultConfigurationStore());

            container.AddFacility(new AutoTxFacility());
            container.Register(Component.For <ITransactionManager>().ImplementedBy <MockTransactionManager>().Named("transactionmanager"));
            container.Register(Component.For <ICustomerService>().ImplementedBy <AnotherCustomerService>().Named("services.customer"));

            ICustomerService service = container.Resolve <ICustomerService>("services.customer");

            service.Insert("TestCustomer", "Rua P Leite, 33");

            MockTransactionManager transactionManager = container.Resolve <MockTransactionManager>("transactionmanager");

            Assert.AreEqual(1, transactionManager.TransactionCount);
            Assert.AreEqual(1, transactionManager.CommittedCount);
            Assert.AreEqual(0, transactionManager.RolledBackCount);

            try
            {
                service.Delete(1);
            }
            catch (Exception)
            {
                // Expected
            }

            Assert.AreEqual(2, transactionManager.TransactionCount);
            Assert.AreEqual(1, transactionManager.CommittedCount);
            Assert.AreEqual(1, transactionManager.RolledBackCount);
        }
Пример #2
0
        public void TestBasicOperationsWithGenericService()
        {
            WindsorContainer container = new WindsorContainer(new DefaultConfigurationStore());

            container.AddFacility(new AutoTxFacility());
            container.Register(Component.For <ITransactionManager>().ImplementedBy <MockTransactionManager>().Named("transactionmanager"));
            container.Register(Component.For(typeof(GenericService <>)).Named("generic.services"));

            GenericService <string> genericService = container.Resolve <GenericService <string> >();

            genericService.Foo();

            MockTransactionManager transactionManager = container.Resolve <MockTransactionManager>("transactionmanager");

            Assert.AreEqual(1, transactionManager.TransactionCount);
            Assert.AreEqual(1, transactionManager.CommittedCount);
            Assert.AreEqual(0, transactionManager.RolledBackCount);

            try
            {
                genericService.Throw();
            }
            catch (Exception)
            {
                // Expected
            }

            Assert.AreEqual(2, transactionManager.TransactionCount);
            Assert.AreEqual(1, transactionManager.CommittedCount);
            Assert.AreEqual(1, transactionManager.RolledBackCount);

            genericService.Bar <int>();

            Assert.AreEqual(3, transactionManager.TransactionCount);
            Assert.AreEqual(2, transactionManager.CommittedCount);
            Assert.AreEqual(1, transactionManager.RolledBackCount);

            try
            {
                genericService.Throw <float>();
            }
            catch
            {
                //exepected
            }

            Assert.AreEqual(4, transactionManager.TransactionCount);
            Assert.AreEqual(2, transactionManager.CommittedCount);
            Assert.AreEqual(2, transactionManager.RolledBackCount);
        }
Пример #3
0
        public void TestReportedBug()
        {
            WindsorContainer container = new WindsorContainer(new DefaultConfigurationStore());

            container.AddFacility(new AutoTxFacility());

            container.Register(Component.For <ITransactionManager>().ImplementedBy <MockTransactionManager>().Named("transactionmanager"));
            container.Register(Component.For <SubTransactionalComp>().Named("comp"));

            SubTransactionalComp service = container.Resolve <SubTransactionalComp>("comp");

            service.BaseMethod();

            MockTransactionManager transactionManager = container.Resolve <MockTransactionManager>("transactionmanager");

            Assert.AreEqual(1, transactionManager.TransactionCount);
            Assert.AreEqual(1, transactionManager.CommittedCount);
            Assert.AreEqual(0, transactionManager.RolledBackCount);
        }
Пример #4
0
        public void RollBackExplicitOnClass()
        {
            WindsorContainer container = new WindsorContainer();

            container.AddFacility(new AutoTxFacility());

            container.Register(Component.For <ITransactionManager>().ImplementedBy <MockTransactionManager>().Named("transactionmanager"));

            container.Register(Component.For <CustomerService>().Named("mycomp"));

            CustomerService serv = container.Resolve <CustomerService>("mycomp");

            serv.Update(1);

            MockTransactionManager transactionManager = container.Resolve <MockTransactionManager>("transactionmanager");

            Assert.AreEqual(1, transactionManager.TransactionCount);
            Assert.AreEqual(1, transactionManager.RolledBackCount);
            Assert.AreEqual(0, transactionManager.CommittedCount);
        }
Пример #5
0
        public void TestBasicOperationsWithConfigComponent()
        {
            WindsorContainer container = new WindsorContainer("HasConfiguration.xml");

            container.Register(Component.For <ITransactionManager>().ImplementedBy <MockTransactionManager>().Named("transactionmanager"));

            TransactionalComp1 comp1 = container.Resolve <TransactionalComp1>();

            comp1.Create();

            comp1.Delete();

            comp1.Save();

            MockTransactionManager transactionManager = container.Resolve <MockTransactionManager>("transactionmanager");

            Assert.AreEqual(3, transactionManager.TransactionCount);
            Assert.AreEqual(3, transactionManager.CommittedCount);
            Assert.AreEqual(0, transactionManager.RolledBackCount);
        }