コード例 #1
0
        public void ControllerAddsViewIfNotPresent()
        {
            try
            {
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel();
                var commandProxy            = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

                var controller = new TestableOrdersController(regionManager, commandProxy, null);

                var collapsibleRegion = (MockRegion)regionManager.Regions["ActionRegion"];

                Assert.AreEqual <int>(0, collapsibleRegion.AddedViews.Count);
                controller.InvokeStartOrder(TransactionType.Buy, "STOCK01");
                Assert.AreEqual <int>(1, collapsibleRegion.AddedViews.Count);
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #2
0
        public void SubmitAllInstanceCommandHookedToGlobalSubmitAllCommands()
        {
            try
            {
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel();
                var commandProxy            = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

                var accountPositionService = new MockAccountPositionService();
                accountPositionService.AddPosition("STOCK01", 10.0M, 100);

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

                Assert.IsFalse(controller.SubmitAllCommandCalled);
                commandProxy.SubmitAllOrdersCommand.CanExecute(null);
                Assert.IsTrue(controller.SubmitAllCommandCalled);
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #3
0
        public void CannotSellMoreSharesThatAreNotOwned()
        {
            try
            {
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel()
                {
                    Shares = 1
                };
                var commandProxy = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

                var controller = new TestableOrdersController(regionManager, new MockTradeSysCommandProxy(), new MockAccountPositionService());
                controller.InvokeStartOrder(TransactionType.Sell, "NOTOWNED");

                Assert.IsFalse(controller.SubmitAllVoteOnlyCommand.CanExecute());
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #4
0
        public void StartOrderCreatesCompositePMAndPassesCorrectInitInfo()
        {
            try
            {
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel();
                var commandProxy            = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

                var controller = new TestableOrdersController(regionManager, commandProxy, null);

                controller.InvokeStartOrder(TransactionType.Buy, "STOCK01");

                Assert.AreEqual("STOCK01", orderCompositePresenter.TransactionInfo.TickerSymbol);
                Assert.AreEqual(TransactionType.Buy, orderCompositePresenter.TransactionInfo.TransactionType);
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #5
0
        public void StartOrderHooksInstanceCommandsToGlobalSaveAndCancelCommands()
        {
            try
            {
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel();
                var commandProxy            = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

                var controller = new TestableOrdersController(regionManager, 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);
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #6
0
        public void NewOrderIsShownOrder()
        {
            try
            {
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel();
                var commandProxy            = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

                var controller = new TestableOrdersController(regionManager, commandProxy, null);

                Assert.AreEqual <int>(0, ordersRegion.AddedViews.Count);
                controller.InvokeStartOrder(TransactionType.Buy, "STOCK01");
                Assert.AreSame(ordersRegion.SelectedItem, ordersRegion.AddedViews[0]);
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #7
0
        public void AfterAllOrdersSubmittedSubmitAllCommandShouldBeDisabled()
        {
            try
            {
                Mock <IOrdersView>            mockOrdersView      = new Mock <IOrdersView>();
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel();
                var commandProxy            = new MockTradeSysCommandProxy();

                IOrdersView      orderCompositeView = mockOrdersView.Object;
                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(orderCompositeView);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

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

                var buyOrder = new MockOrderCompositePresentationModel()
                {
                    Shares = 100
                };
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(buyOrder);

                controller.InvokeStartOrder(TransactionType.Buy, "STOCK1");

                bool canExecuteChangedCalled = false;
                bool canExecuteResult        = false;

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

                Assert.IsTrue(canExecuteChangedCalled);
                Assert.IsFalse(canExecuteResult);
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #8
0
        public void CannotSellMoreSharesThanAreOwnedInDifferentOrders()
        {
            try
            {
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel();
                var commandProxy            = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

                var accountPositionService = new MockAccountPositionService();
                accountPositionService.AddPosition("STOCK01", 10.0M, 100);

                var controller = new TestableOrdersController(regionManager, commandProxy, accountPositionService);
                var sellOrder1 = new MockOrderCompositePresentationModel()
                {
                    Shares = 100
                };
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(sellOrder1);

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

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

                var sellOrder2 = new MockOrderCompositePresentationModel()
                {
                    Shares = 100
                };
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(sellOrder2);

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

                Assert.IsFalse(controller.SubmitAllVoteOnlyCommand.CanExecute());
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #9
0
        public void OnCloseViewRequestedTheControllerUnhooksGlobalCommands()
        {
            try
            {
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel();
                var commandProxy            = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

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

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

                // Act
                orderCompositePresenter.RaiseCloseViewRequested();

                // Verify
                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);
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #10
0
        public void BuyAndSellCommandsInvokeController()
        {
            try
            {
                Mock <IOrdersViewModel>       mockOrdersViewModel = new Mock <IOrdersViewModel>();
                Mock <ServiceLocatorImplBase> mockServiceLocator  = new Mock <ServiceLocatorImplBase>();

                var buyOrderCompositePresenter  = new MockOrderCompositePresentationModel();
                var sellOrderCompositePresenter = new MockOrderCompositePresentationModel();

                var commandProxy = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

                var controller = new TestableOrdersController(regionManager, commandProxy, null);

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(buyOrderCompositePresenter);
                controller.BuyCommand.Execute("STOCK01");

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

                // Set new CompositePresentationModel to simulate resolution of new instance.
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(sellOrderCompositePresenter);
                controller.SellCommand.Execute("STOCK02");

                Assert.AreEqual("STOCK02", controller.StartOrderArgumentTickerSymbol);
                Assert.AreEqual(TransactionType.Sell, controller.StartOrderArgumentTransactionType);
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #11
0
        public void ShouldRemoveOrdersViewWhenClosingLastOrder()
        {
            try
            {
                Mock <IOrdersViewModel> mockOrdersViewModel = new Mock <IOrdersViewModel>();

                Mock <ServiceLocatorImplBase> mockServiceLocator = new Mock <ServiceLocatorImplBase>();

                var orderCompositePresenter = new MockOrderCompositePresentationModel()
                {
                    Shares = 100
                };
                var commandProxy = new MockTradeSysCommandProxy();

                IOrdersViewModel orderCompositePresentationModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance <IOrdersView>()).Returns(new Mock <IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance <IOrdersViewModel>()).Returns(orderCompositePresentationModel);
                mockServiceLocator.Setup(x => x.GetInstance <IOrderCompositeViewModel>()).Returns(orderCompositePresenter);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

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

                var region = (MockRegion)regionManager.Regions["ActionRegion"];

                controller.InvokeStartOrder(TransactionType.Buy, "STOCK1");

                Assert.AreEqual <int>(1, region.AddedViews.Count);

                orderCompositePresenter.RaiseCloseViewRequested();

                Assert.AreEqual <int>(0, region.AddedViews.Count);
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
コード例 #12
0
        public void CannotSubmitAllWhenNothingToSubmit()
        {
            var controller = new TestableOrdersController(new MockRegionManager(), new MockTradeSysCommandProxy(), new MockAccountPositionService());

            Assert.IsFalse(controller.SubmitAllVoteOnlyCommand.CanExecute());
        }