Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 10
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);
            }
        }