public void ControllerAddsViewIfNotPresent()
        {
            try
            {
                Mock<IOrdersViewModel> mockOrdersViewModel = new Mock<IOrdersViewModel>();
                Mock<ServiceLocatorImplBase> mockServiceLocator = new Mock<ServiceLocatorImplBase>();

                var orderCompositeViewModel = new MockOrderCompositeViewModel();
                var commandProxy = new MockStockTraderRICommandProxy();

                IOrdersViewModel ordersViewModel = mockOrdersViewModel.Object;

                mockServiceLocator.Setup(x => x.GetInstance<IOrdersView>()).Returns(new Mock<IOrdersView>().Object);
                mockServiceLocator.Setup(x => x.GetInstance<IOrdersViewModel>()).Returns(ordersViewModel);
                mockServiceLocator.Setup(x => x.GetInstance<IOrderCompositeViewModel>()).Returns(orderCompositeViewModel);
                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);
            }
        }
Exemplo n.º 2
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 MockStockTraderRICommandProxy();

                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);
            }
        }
Exemplo n.º 3
0
 public TestableOrdersController(IRegionManager regionManager, MockStockTraderRICommandProxy commandProxy, IAccountPositionService accountPositionService)
     : base(regionManager, commandProxy, accountPositionService)
 {
 }
Exemplo n.º 4
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 MockStockTraderRICommandProxy();

                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);
            }
        }
Exemplo n.º 5
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 MockStockTraderRICommandProxy();

                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);
            }
        }
Exemplo n.º 6
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 MockStockTraderRICommandProxy();

                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 MockStockTraderRICommandProxy(), new MockAccountPositionService());
                controller.InvokeStartOrder(TransactionType.Sell, "NOTOWNED");

                Assert.IsFalse(controller.SubmitAllVoteOnlyCommand.CanExecute());
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }
Exemplo 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 MockStockTraderRICommandProxy();

                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);
            }
        }
Exemplo n.º 8
0
        public void SubmitAllInstanceCommandHookedToGlobalSubmitAllCommands()
        {
            try
            {
                Mock<IOrdersViewModel> mockOrdersViewModel = new Mock<IOrdersViewModel>();
                Mock<ServiceLocatorImplBase> mockServiceLocator = new Mock<ServiceLocatorImplBase>();

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

                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);
            }

        }
Exemplo n.º 9
0
        public void StartOrderCreatesCompositePMAndPassesCorrectInitInfo()
        {
            try
            {
                Mock<IOrdersViewModel> mockOrdersViewModel = new Mock<IOrdersViewModel>();
                Mock<ServiceLocatorImplBase> mockServiceLocator = new Mock<ServiceLocatorImplBase>();

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

                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);
            }
        }
Exemplo n.º 10
0
        public void OnCloseViewRequestedTheControllerUnhooksGlobalCommands()
        {
            try
            {
                Mock<IOrdersViewModel> mockOrdersViewModel = new Mock<IOrdersViewModel>();
                Mock<ServiceLocatorImplBase> mockServiceLocator = new Mock<ServiceLocatorImplBase>();

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

                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);
            }
        }
Exemplo n.º 11
0
        public void StartOrderHooksInstanceCommandsToGlobalSaveAndCancelCommands()
        {
            try
            {

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

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

                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);
            }
        }
Exemplo n.º 12
0
        public void NewOrderIsShownOrder()
        {
            try
            {
                Mock<IOrdersViewModel> mockOrdersViewModel = new Mock<IOrdersViewModel>();
                Mock<ServiceLocatorImplBase> mockServiceLocator = new Mock<ServiceLocatorImplBase>();

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

                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);
            }
        }
        public void AfterAllOrdersSubmittedSubmitAllCommandShouldBeDisabled()
        {
            var container = new MockUnityResolver();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());
            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 SubmitAllInstanceCommandHookedToGlobalSubmitAllCommands()
        {
            var container = new MockUnityResolver();
            var orderCompositePresenter = new MockOrderCompositePresentationModel();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());
            container.Bag.Add(typeof(IOrderCompositePresentationModel), orderCompositePresenter);
            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 OnCloseViewRequestedTheControllerUnhooksGlobalCommands()
        {
            var container = new MockUnityResolver();
            var orderCompositePresenter = new MockOrderCompositePresentationModel();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());
            container.Bag.Add(typeof(IOrderCompositePresentationModel), orderCompositePresenter);
            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 orderCompositePresenter = new MockOrderCompositePresentationModel();
            container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel());
            container.Bag.Add(typeof(IOrderCompositePresentationModel), orderCompositePresenter);

            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);
        }