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