Пример #1
0
 public void SetUp()
 {
     regionManager = new MockRegionManager();
     regionManager.Regions.Add("ActionRegion", new MockRegion());
     ordersRegion = new MockRegion();
     regionManager.Regions.Add("OrdersRegion", ordersRegion);
 }
        public void InitRegistersOrdersToolbarViewToToolbarRegion()
        {
            try
            {
                MockRegion toolbarRegion = new MockRegion();
                MockRegion mainRegion = new MockRegion();
                MockRegionManager regionManager = new MockRegionManager();
                var container = new MockUnityResolver();
                container.Bag.Add(typeof(IOrdersController), new MockOrdersController());
                container.Bag.Add(typeof(IPositionSummaryPresentationModel), new MockPositionSummaryPresenter());

                var contentRegistry = new MockRegionViewRegistry();
                ServiceLocator.SetLocatorProvider(
                   () => new MockServiceLocator(
                           () => contentRegistry));

                PositionModule module = new PositionModule(container, regionManager);
                regionManager.Regions.Add("MainRegion", mainRegion);
                regionManager.Regions.Add("CollapsibleRegion", new MockRegion());

                Assert.AreEqual(0, contentRegistry.RegisterViewWithRegionRegionNameArg.Count);

                module.Initialize();

                Assert.AreEqual(2, contentRegistry.RegisterViewWithRegionRegionNameArg.Count);
                Assert.IsTrue(contentRegistry.RegisterViewWithRegionRegionNameArg.Contains("ResearchRegion"));
                Assert.IsTrue(contentRegistry.RegisterViewWithRegionRegionNameArg.Contains("MainRegion"));
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(null);
            }
        }
        public void ControllerAddsANewOrderOnStartOrder()
        {
            IUnityContainer container = new UnityContainer();
            var regionManager = new MockRegionManager();
            container.RegisterType<IOrdersPresentationModel, MockOrdersPresentationModel>();
            container.RegisterType<IOrderCompositePresentationModel, MockOrderCompositePresentationModel>();

            var ordersRegion = new MockRegion();
            regionManager.Regions.Add("OrdersRegion", ordersRegion);
            regionManager.Regions.Add("MainRegion", new MockRegion());

            var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), null);

            Assert.AreEqual<int>(0, ordersRegion.AddedViews.Count);
            controller.InvokeStartOrder(TransactionType.Buy, "STOCK01");
            Assert.AreEqual<int>(1, ordersRegion.AddedViews.Count);
        }
        public void BuyAndSellCommandsInvokeController()
        {
            IUnityContainer container = new UnityContainer();
            var regionManager = new MockRegionManager();
            container.RegisterType<IOrdersPresentationModel, MockOrdersPresentationModel>();
            container.RegisterType<IOrderCompositePresentationModel, MockOrderCompositePresentationModel>();

            regionManager.Regions.Add("OrdersRegion", new MockRegion());
            regionManager.Regions.Add("MainRegion", new MockRegion());

            var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), null);
            controller.BuyCommand.Execute("STOCK01");

            Assert.AreEqual("STOCK01", controller.StartOrderArgumentTickerSymbol);
            Assert.AreEqual(TransactionType.Buy, controller.StartOrderArgumentTransactionType);

            controller.SellCommand.Execute("STOCK02");

            Assert.AreEqual("STOCK02", controller.StartOrderArgumentTickerSymbol);
            Assert.AreEqual(TransactionType.Sell, controller.StartOrderArgumentTransactionType);
        }
        public void InitAddsOrdersToolbarViewToToolbarRegion()
        {
            MockRegion toolbarRegion = new MockRegion();
            MockRegion mainRegion = new MockRegion();
            MockRegionManager regionManager = new MockRegionManager();
            var container = new MockUnityResolver();
            container.Bag.Add(typeof(IOrdersController), new MockOrdersController());
            container.Bag.Add(typeof(IPositionSummaryPresentationModel), new MockPositionSummaryPresenter());
            PositionModule module = new PositionModule(container, regionManager);
            regionManager.Regions.Add("MainRegion", mainRegion);
            regionManager.Regions.Add("CollapsibleRegion", new MockRegion());
            regionManager.Regions.Add("MainToolbarRegion", toolbarRegion);

            Assert.AreEqual(0, toolbarRegion.AddedViews.Count);
            Assert.AreEqual(0, mainRegion.AddedViews.Count);

            module.Initialize();

            Assert.AreEqual(1, mainRegion.AddedViews.Count);
            Assert.AreEqual(1, toolbarRegion.AddedViews.Count);

        }
        public void CannotSellMoreSharesThatAreNOTOwned()
        {
            var container = new MockUnityResolver();
            var regionManager = new MockRegionManager();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());

            var ordersRegion = new MockRegion();
            regionManager.Regions.Add("OrdersRegion", ordersRegion);
            regionManager.Regions.Add("MainRegion", new MockRegion());

            var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), new MockAccountPositionService());

            var sellOrder = new MockOrderCompositePresentationModel() { Shares = 1};
            container.Bag.Add(typeof(IOrderCompositePresentationModel), sellOrder);

            controller.InvokeStartOrder(TransactionType.Sell, "NOTOWNED");

            Assert.IsFalse(controller.SubmitAllVoteOnlyCommand.CanExecute(null));
        }
        public void AfterAllOrdersSubmittedSubmitAllCommandShouldBeDisabled()
        {
            var container = new MockUnityResolver();
            var regionManager = new MockRegionManager();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());

            var ordersRegion = new MockRegion();
            regionManager.Regions.Add("OrdersRegion", ordersRegion);
            regionManager.Regions.Add("MainRegion", new MockRegion());
            var commandProxy = new MockStockTraderRICommandProxy();

            var controller = new TestableOrdersController(regionManager, container, commandProxy, new MockAccountPositionService());

            var buyOrder = new MockOrderCompositePresentationModel() { Shares = 100 };
            container.Bag[typeof (IOrderCompositePresentationModel)] = buyOrder;
            controller.InvokeStartOrder(TransactionType.Buy, "STOCK1");

            bool canExecuteChangedCalled = false;
            bool canExecuteResult = false;

            commandProxy.SubmitAllOrdersCommand.CanExecuteChanged += delegate
                                                                 {
                                                                     canExecuteChangedCalled = true;
                                                                     canExecuteResult =
                                                                         controller.SubmitAllVoteOnlyCommand.CanExecute(null);
                                                                 };
            buyOrder.RaiseCloseViewRequested();

            Assert.IsTrue(canExecuteChangedCalled);
            Assert.IsFalse(canExecuteResult);
        }
        public void CannotSellMoreSharesThanAreOwnedInDifferentOrders()
        {
            var container = new MockUnityResolver();
            var regionManager = new MockRegionManager();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());

            var ordersRegion = new MockRegion();
            regionManager.Regions.Add("OrdersRegion", ordersRegion);
            regionManager.Regions.Add("MainRegion", new MockRegion());
            var accountPositionService = new MockAccountPositionService();
            accountPositionService.AddPosition("STOCK01", 10.0M, 100);

            var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), accountPositionService);
            var sellOrder1 = new MockOrderCompositePresentationModel() { Shares = 100 };

            container.Bag.Add(typeof(IOrderCompositePresentationModel), sellOrder1);
            controller.InvokeStartOrder(TransactionType.Sell, "STOCK01");

            Assert.IsTrue(controller.SubmitAllVoteOnlyCommand.CanExecute(null));

            var sellOrder2 = new MockOrderCompositePresentationModel() { Shares = 100 };
            container.Bag[typeof(IOrderCompositePresentationModel)] = sellOrder2;
            controller.InvokeStartOrder(TransactionType.Sell, "stock01");

            Assert.IsFalse(controller.SubmitAllVoteOnlyCommand.CanExecute(null));
        }
        public void SubmitAllInstanceCommandHookedToGlobalSubmitAllCommands()
        {
            var container = new MockUnityResolver();
            var regionManager = new MockRegionManager();
            var orderCompositePresenter = new MockOrderCompositePresentationModel();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());
            container.Bag.Add(typeof(IOrderCompositePresentationModel), orderCompositePresenter);

            var ordersRegion = new MockRegion();
            regionManager.Regions.Add("OrdersRegion", ordersRegion);
            regionManager.Regions.Add("MainRegion", new MockRegion());
            var commandProxy = new MockStockTraderRICommandProxy();
            
            var accountPositionService = new MockAccountPositionService();
            accountPositionService.AddPosition("STOCK01", 10.0M, 100);

            var controller = new TestableOrdersController(regionManager, container, commandProxy, accountPositionService);
            controller.InvokeStartOrder(TransactionType.Buy, "STOCK01");

            Assert.IsFalse(controller.SubmitAllCommandCalled);
            commandProxy.SubmitAllOrdersCommand.CanExecute(null);
            Assert.IsTrue(controller.SubmitAllCommandCalled);
        }
        public void StartOrderCreatesCompositePMAndPassesCorrectInitInfo()
        {
            IUnityContainer container = new UnityContainer();
            var regionManager = new MockRegionManager();
            container.RegisterType<IOrdersPresentationModel, MockOrdersPresentationModel>();
            var presentationModel = new MockOrderCompositePresentationModel();
            container.RegisterInstance<IOrderCompositePresentationModel>(presentationModel);

            regionManager.Regions.Add("OrdersRegion", new MockRegion());
            regionManager.Regions.Add("MainRegion", new MockRegion());

            var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), null);
            controller.InvokeStartOrder(TransactionType.Buy, "STOCK01");

            Assert.AreEqual("STOCK01", presentationModel.TransactionInfo.TickerSymbol);
            Assert.AreEqual(TransactionType.Buy, presentationModel.TransactionInfo.TransactionType);
        }
        public void OnCloseViewRequestedTheControllerUnhooksGlobalCommands()
        {
            var container = new MockUnityResolver();
            var regionManager = new MockRegionManager();
            var orderCompositePresenter = new MockOrderCompositePresentationModel();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());
            container.Bag.Add(typeof(IOrderCompositePresentationModel), orderCompositePresenter);

            var ordersRegion = new MockRegion();
            regionManager.Regions.Add("OrdersRegion", ordersRegion);
            regionManager.Regions.Add("MainRegion", new MockRegion());
            var commandProxy = new MockStockTraderRICommandProxy();

            var controller = new TestableOrdersController(regionManager, container, commandProxy, null);
            controller.InvokeStartOrder(TransactionType.Buy, "STOCK01");

            Assert.AreEqual(1, ordersRegion.AddedViews.Count);
            orderCompositePresenter.RaiseCloseViewRequested();

            Assert.AreEqual(0, ordersRegion.AddedViews.Count);

            commandProxy.SubmitAllOrdersCommand.Execute(null);
            Assert.IsFalse(orderCompositePresenter.MockSubmitCommand.ExecuteCalled);

            commandProxy.CancelAllOrdersCommand.Execute(null);
            Assert.IsFalse(orderCompositePresenter.MockCancelCommand.ExecuteCalled);

            commandProxy.SubmitOrderCommand.Execute(null);
            Assert.IsFalse(orderCompositePresenter.MockSubmitCommand.ExecuteCalled);

            commandProxy.CancelOrderCommand.Execute(null);
            Assert.IsFalse(orderCompositePresenter.MockCancelCommand.ExecuteCalled);
        }
        public void StartOrderHooksInstanceCommandsToGlobalSaveAndCancelCommands()
        {
            var container = new MockUnityResolver();
            var regionManager = new MockRegionManager();
            var orderCompositePresenter = new MockOrderCompositePresentationModel();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());
            container.Bag.Add(typeof(IOrderCompositePresentationModel), orderCompositePresenter);

            var ordersRegion = new MockRegion();
            regionManager.Regions.Add("OrdersRegion", ordersRegion);
            regionManager.Regions.Add("MainRegion", new MockRegion());
            var commandProxy = new MockStockTraderRICommandProxy();

            var controller = new TestableOrdersController(regionManager, container, commandProxy, null);
            controller.InvokeStartOrder(TransactionType.Buy, "STOCK01");

            Assert.IsFalse(orderCompositePresenter.MockSubmitCommand.ExecuteCalled);
            commandProxy.SubmitOrderCommand.Execute(null);
            Assert.IsTrue(orderCompositePresenter.MockSubmitCommand.ExecuteCalled);

            Assert.IsFalse(orderCompositePresenter.MockCancelCommand.ExecuteCalled);
            commandProxy.CancelOrderCommand.Execute(null);
            Assert.IsTrue(orderCompositePresenter.MockCancelCommand.ExecuteCalled);
        }