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); } }
private TestableNewsModule CreateTestableNewsModule() { this.container = new MockUnityResolver(); this.controller = new MockNewsController(); container.Bag.Add(typeof(INewsController), controller); container.Bag.Add(typeof(INewsReaderView), null); return new TestableNewsModule(container); }
public void InitCallsRunOnNewsController() { MockUnityResolver container = new MockUnityResolver(); var controller = new MockNewsController(); container.Bag.Add(typeof(INewsController), controller); var newsModule = new NewsModule(container); newsModule.Initialize(); Assert.IsTrue(controller.RunCalled); }
public void ControllerAddsViewIfNotPresent() { var container = new MockUnityResolver(); container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel()); container.Bag.Add(typeof(IOrderCompositePresentationModel), new MockOrderCompositePresentationModel()); var collapsibleRegion = (MockRegion) regionManager.Regions["ActionRegion"]; var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), null); Assert.AreEqual<int>(0, collapsibleRegion.AddedViews.Count); controller.InvokeStartOrder(TransactionType.Buy, "STOCK01"); Assert.AreEqual<int>(1, collapsibleRegion.AddedViews.Count); }
public void ShouldRunControllerOnInitialization() { var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); IModule module = new WatchModule(container, regionManager); var contentRegistry = new MockRegionViewRegistry(); ServiceLocator.SetLocatorProvider( () => new MockServiceLocator( () => contentRegistry)); container.Bag.Add(typeof(IAddWatchPresenter), new MockAddWatchPresenter()); container.Bag.Add(typeof(IWatchListPresentationModel), new MockWatchListPresentationModel()); var controller = new MockWatchListController(); container.Bag.Add(typeof(IWatchListController), controller); regionManager.Regions.Add("MainToolBarRegion", new MockRegion()); module.Initialize(); Assert.IsTrue(controller.RunCalled); }
public void BuyAndSellCommandsInvokeController() { var container = new MockUnityResolver(); container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel()); container.Bag.Add(typeof(IOrderCompositePresentationModel), new MockOrderCompositePresentationModel()); var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), null); controller.BuyCommand.Execute("STOCK01"); Assert.AreEqual("STOCK01", controller.StartOrderArgumentTickerSymbol); Assert.AreEqual(TransactionType.Buy, controller.StartOrderArgumentTransactionType); // Set new CompositePresentationModel to simulate resolution of new instance. container.Bag[typeof (IOrderCompositePresentationModel)] = new MockOrderCompositePresentationModel(); controller.SellCommand.Execute("STOCK02"); Assert.AreEqual("STOCK02", controller.StartOrderArgumentTickerSymbol); Assert.AreEqual(TransactionType.Sell, controller.StartOrderArgumentTransactionType); }
public void ShouldAddTimelineViewToTimelineRegion() { var timelineRegion = new MockRegion(); var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); container.Bag.Add(typeof(ITimelinePresenter), new MockTimelinePresenter()); regionManager.Regions.Add("TimelineRegion", timelineRegion); var module = new TimelineModule(container, regionManager); Assert.AreEqual(0, timelineRegion.AddedViews.Count); module.Initialize(); Assert.AreEqual(1, timelineRegion.AddedViews.Count); Assert.IsInstanceOfType(timelineRegion.AddedViews[0], typeof(ITimelineView)); }
public void ShouldAddMetadataViewToMetadataRegion() { var metadataRegion = new MockRegion(); var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); container.Bag.Add(typeof(IMetadataViewPresentationModel), new MockMetadataViewPresentationModel()); regionManager.Regions.Add("MetadataRegion", metadataRegion); var module = new MetadataModule(container, regionManager); Assert.AreEqual(0, metadataRegion.AddedViews.Count); module.Initialize(); Assert.AreEqual(1, metadataRegion.AddedViews.Count); Assert.IsInstanceOfType(metadataRegion.AddedViews[0], typeof(IMetadataView)); }
public void ShouldAddTitlesViewToToolsRegion() { var toolsRegion = new MockRegion(); var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); container.Bag.Add(typeof(ITitlesViewPresentationModel), new MockTitlesViewPresentationModel()); toolsRegion.Name = "ToolsRegion"; regionManager.Regions.Add(toolsRegion); var module = new TitlesModule(container, regionManager); Assert.AreEqual(0, toolsRegion.AddedViews.Count); module.Initialize(); Assert.AreEqual(1, toolsRegion.AddedViews.Count); Assert.IsInstanceOfType(toolsRegion.AddedViews[0], typeof(ITitlesView)); }
public void ShouldAddNotificationViewToNotificationsRegion() { var toolsRegion = new MockRegion(); var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); container.Bag.Add(typeof(INotificationViewPresenter), new MockNotificationViewPresenter()); container.Bag.Add(typeof(IProjectService), new MockProjectService()); toolsRegion.Name = RegionNames.NotificationsRegion; regionManager.Regions.Add(toolsRegion); var module = new ServicesModule(container, regionManager); Assert.AreEqual(0, toolsRegion.AddedViews.Count); module.Initialize(); Assert.AreEqual(1, toolsRegion.AddedViews.Count); Assert.IsInstanceOfType(toolsRegion.AddedViews[0], typeof(INotificationView)); }
public void ShouldRegisterCommentTimelineBarElementToTimelineBarRegistry() { var timelineBarRegistry = new MockTimelineBarRegistry(); var regionManager = new MockRegionManager(); regionManager.Regions.Add("ToolsRegion", new MockRegion()); var container = new MockUnityResolver(); container.Bag.Add(typeof(ICommentViewPresentationModel), new MockCommentViewPresentationModel()); container.Bag.Add(typeof(ITimelineBarRegistry), timelineBarRegistry); var module = new CommentModule(container, regionManager); Assert.IsFalse(timelineBarRegistry.RegisterTimelineBarElementCalled); module.Initialize(); Assert.IsTrue(timelineBarRegistry.RegisterTimelineBarElementCalled); Assert.AreEqual("Comment", timelineBarRegistry.RegisterTimelineBarElementKeyArgument); Assert.IsNotNull(timelineBarRegistry.RegisterTimelineBarElementValueArgument); }
public void ShouldAddCommentViewToToolsRegion() { var toolsRegion = new MockRegion(); var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); container.Bag.Add(typeof(ICommentViewPresentationModel), new MockCommentViewPresentationModel()); container.Bag.Add(typeof(ITimelineBarRegistry), new MockTimelineBarRegistry()); regionManager.Regions.Add("ToolsRegion", toolsRegion); var module = new CommentModule(container, regionManager); Assert.AreEqual(0, toolsRegion.AddedViews.Count); module.Initialize(); Assert.AreEqual(1, toolsRegion.AddedViews.Count); Assert.IsInstanceOfType(toolsRegion.AddedViews[0], typeof(ICommentView)); }
public void InitAddsAddWatchControlViewToToolbarRegion() { var toolbarRegion = new MockRegion(); var collapsibleRegion = new MockRegion(); var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); container.Bag.Add(typeof(IAddWatchPresenter), new MockAddWatchPresenter()); container.Bag.Add(typeof(IWatchListPresentationModel), new MockWatchListPresentationModel()); IModule module = new WatchModule(container, regionManager); regionManager.Regions.Add("WatchRegion", collapsibleRegion); regionManager.Regions.Add("MainToolbarRegion", toolbarRegion); Assert.AreEqual(0, toolbarRegion.AddedViews.Count); Assert.AreEqual(0, collapsibleRegion.AddedViews.Count); module.Initialize(); Assert.AreEqual(1, toolbarRegion.AddedViews.Count); Assert.AreEqual(1, collapsibleRegion.AddedViews.Count); }
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 BuyAndSellCommandsInvokeController() { var container = new MockUnityResolver(); container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel()); container.Bag.Add(typeof(IOrderCompositePresentationModel), new MockOrderCompositePresentationModel()); var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), null); controller.BuyCommand.Execute("STOCK01"); Assert.AreEqual("STOCK01", controller.StartOrderArgumentTickerSymbol); Assert.AreEqual(TransactionType.Buy, controller.StartOrderArgumentTransactionType); // Set new CompositePresentationModel to simulate resolution of new instance. container.Bag[typeof(IOrderCompositePresentationModel)] = new MockOrderCompositePresentationModel(); controller.SellCommand.Execute("STOCK02"); Assert.AreEqual("STOCK02", controller.StartOrderArgumentTickerSymbol); Assert.AreEqual(TransactionType.Sell, controller.StartOrderArgumentTransactionType); }
public void ShouldAddSettingsMenuButtonViewToMenuRegion() { var windowManager = new MockWindowManager(); var container = new MockUnityResolver(); var regionManager = new MockRegionManager(); var module = new SettingsModule(container, regionManager, windowManager); var menuButtonView = new MockMenuButtonView(); ISettingsViewPresentationModel settingsViewModel = new MockSettingsViewPresentationModel(); container.Bag.Add(typeof(ISettingsViewPresentationModel), settingsViewModel); container.Bag.Add(typeof(IIncreasePersistenceQuotaViewModel), new MockIncreasePersistenceQuotaViewModel()); MockSettingsMenuButtonViewModel menuViewModel = new MockSettingsMenuButtonViewModel(); menuViewModel.View = menuButtonView; container.Bag[typeof(IMenuButtonViewModel)] = menuViewModel; MockRegion menuRegion = new MockRegion { Name = "MenuRegion" }; MockRegion mainRegion = new MockRegion { Name = "MainRegion" }; regionManager.Regions.Add(menuRegion); regionManager.Regions.Add(mainRegion); Assert.AreEqual(0, menuRegion.AddedViews.Count); module.Initialize(); Assert.AreSame(settingsViewModel.View, menuViewModel.ViewToDisplay); Assert.IsTrue(menuViewModel.IsViewActive); Assert.AreEqual(1, menuRegion.AddedViews.Count); Assert.IsNotNull(menuViewModel.View); Assert.AreSame(menuViewModel.View, menuRegion.AddedViews[0]); Assert.AreEqual("Settings", menuViewModel.Text); }
public void ShouldAddSequenceMenuButtonViewToMenuRegion() { var container = new MockUnityResolver(); var regionManager = new MockRegionManager(); var regionViewRegistry = new MockRegionViewRegistry(); var module = new TimelineModule(container, regionManager, regionViewRegistry, this.windowManager); var menuButtonView = new MockMenuButtonView(); MockTimelinePresenter timelinePresenter = new MockTimelinePresenter(); container.Bag[typeof(ITimelinePresenter)] = timelinePresenter; MockTimelineMenuButtonViewModel menuViewModel = new MockTimelineMenuButtonViewModel(); menuViewModel.View = menuButtonView; container.Bag[typeof(IMenuButtonViewModel)] = menuViewModel; container.Bag.Add(typeof(ISequencesViewModel), new MockSequencesViewModel()); MockRegion mainRegion = new MockRegion { Name = "MainRegion" }; MockRegion menuRegion = new MockRegion { Name = "MenuRegion" }; regionManager.Regions.Add(mainRegion); regionManager.Regions.Add(menuRegion); Assert.AreEqual(0, menuRegion.AddedViews.Count); module.Initialize(); Assert.AreSame(timelinePresenter.View, menuViewModel.ViewToDisplay); Assert.IsTrue(menuViewModel.IsViewActive); Assert.AreEqual(1, menuRegion.AddedViews.Count); Assert.IsNotNull(menuViewModel.View); Assert.AreSame(menuViewModel.View, menuRegion.AddedViews[0]); Assert.AreEqual("Sequence", menuViewModel.Text); }
public void InitAddsAddWatchControlViewToToolbarRegion() { var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); IModule module = new WatchModule(container, regionManager); var contentRegistry = new MockRegionViewRegistry(); ServiceLocator.SetLocatorProvider( () => new MockServiceLocator( () => contentRegistry)); container.Bag.Add(typeof(IAddWatchPresenter), new MockAddWatchPresenter()); container.Bag.Add(typeof(IWatchListPresentationModel), new MockWatchListPresentationModel()); container.Bag.Add(typeof(IWatchListController), new MockWatchListController()); regionManager.Regions.Add("MainToolBarRegion", new MockRegion()); Assert.AreEqual(0, contentRegistry.RegisterViewWithRegionRegionNameArg.Count); module.Initialize(); Assert.AreEqual(1, contentRegistry.RegisterViewWithRegionRegionNameArg.Count); Assert.IsTrue(contentRegistry.RegisterViewWithRegionRegionNameArg.Contains("MainToolBarRegion")); }
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); }
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 ShouldAddSequencePreviewMenuButtonViewToMenuRegion() { var container = new MockUnityResolver(); var regionManager = new MockRegionManager(); var module = new PlayerModule(container, regionManager, new MockWindowManager()); var menuButtonView = new MockMenuButtonView(); MockPlayerViewPresenter playerViewPresenter = new MockPlayerViewPresenter(); container.Bag[typeof(IPlayerViewPresenter)] = playerViewPresenter; MockSequencePreviewMenuButtonViewModel menuViewModel = new MockSequencePreviewMenuButtonViewModel(); menuViewModel.View = menuButtonView; container.Bag[typeof(IMenuButtonViewModel)] = menuViewModel; MockRegion mainRegion = new MockRegion { Name = "MainRegion" }; MockRegion menuRegion = new MockRegion { Name = "MenuRegion" }; regionManager.Regions.Add(mainRegion); regionManager.Regions.Add(menuRegion); Assert.AreEqual(0, menuRegion.AddedViews.Count); module.Initialize(); Assert.AreSame(playerViewPresenter.View, menuViewModel.ViewToDisplay); Assert.IsTrue(menuViewModel.IsViewActive); Assert.AreEqual(1, menuRegion.AddedViews.Count); Assert.IsNotNull(menuViewModel.View); Assert.AreSame(menuViewModel.View, menuRegion.AddedViews[0]); Assert.AreEqual("Sequence Preview", menuViewModel.Text); }
public void ShouldRemoveOrdersViewWhenClosingLastOrder() { var container = new MockUnityResolver(); container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel()); var region = (MockRegion)regionManager.Regions["ActionRegion"]; var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), null); var buyOrder = new MockOrderCompositePresentationModel() { Shares = 100 }; container.Bag[typeof(IOrderCompositePresentationModel)] = buyOrder; controller.InvokeStartOrder(TransactionType.Buy, "STOCK1"); Assert.AreEqual <int>(1, region.AddedViews.Count); buyOrder.RaiseCloseViewRequested(); Assert.AreEqual <int>(0, region.AddedViews.Count); }
public void ShouldAddTimelineViewToMainRegion() { var regionViewRegistry = new MockRegionViewRegistry(); var regionManager = new MockRegionManager(); var container = new MockUnityResolver(); var menuButtonView = new MockMenuButtonView(); MockTimelinePresenter timelinePresenter = new MockTimelinePresenter(); container.Bag[typeof(ITimelinePresenter)] = timelinePresenter; MockTimelineMenuButtonViewModel menuViewModel = new MockTimelineMenuButtonViewModel(); menuViewModel.View = menuButtonView; container.Bag[typeof(IMenuButtonViewModel)] = menuViewModel; container.Bag.Add(typeof(ISequencesViewModel), new MockSequencesViewModel()); MockRegion mainRegion = new MockRegion { Name = "MainRegion" }; MockRegion menuRegion = new MockRegion { Name = "MenuRegion" }; regionManager.Regions.Add("MainRegion", mainRegion); regionManager.Regions.Add("MenuRegion", menuRegion); var module = new TimelineModule(container, regionManager, regionViewRegistry, this.windowManager); Assert.AreEqual(0, mainRegion.AddedViews.Count); module.Initialize(); Assert.AreEqual(1, mainRegion.AddedViews.Count); Assert.IsInstanceOfType(mainRegion.AddedViews[0], typeof(ITimelineView)); }
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 CannotSellMoreSharesThanAreOwned() { 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 buyOrder = new MockOrderCompositePresentationModel() { Shares = 100, }; container.Bag.Add(typeof(IOrderCompositePresentationModel), buyOrder); controller.InvokeStartOrder(TransactionType.Buy, "STOCK01"); Assert.IsTrue(controller.SubmitAllVoteOnlyCommand.CanExecute(null)); var sellOrder = new MockOrderCompositePresentationModel() { Shares = 200 }; container.Bag[typeof(IOrderCompositePresentationModel)] = sellOrder; controller.InvokeStartOrder(TransactionType.Sell, "STOCK01"); //Should not be able to sell even though owned shares==100, buy==100 and sell==200 Assert.IsFalse(controller.SubmitAllVoteOnlyCommand.CanExecute(null)); }
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 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 NewOrderIsShownOrder() { var container = new MockUnityResolver(); container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel()); container.Bag.Add(typeof(IOrderCompositePresentationModel), new MockOrderCompositePresentationModel()); var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), null); Assert.AreEqual<int>(0, ordersRegion.AddedViews.Count); controller.InvokeStartOrder(TransactionType.Buy, "STOCK01"); Assert.AreSame(ordersRegion.SelectedItem, ordersRegion.AddedViews[0]); }
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 CannotSellMoreSharesThanAreOwned() { var container = new MockUnityResolver(); container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel()); var accountPositionService = new MockAccountPositionService(); accountPositionService.AddPosition("STOCK01", 10.0M, 100); var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), accountPositionService); var buyOrder = new MockOrderCompositePresentationModel() { Shares = 100, }; container.Bag.Add(typeof(IOrderCompositePresentationModel), buyOrder); controller.InvokeStartOrder(TransactionType.Buy, "STOCK01"); Assert.IsTrue(controller.SubmitAllVoteOnlyCommand.CanExecute(null)); var sellOrder = new MockOrderCompositePresentationModel() { Shares = 200 }; container.Bag[typeof(IOrderCompositePresentationModel)] = sellOrder; controller.InvokeStartOrder(TransactionType.Sell, "STOCK01"); //Should not be able to sell even though owned shares==100, buy==100 and sell==200 Assert.IsFalse(controller.SubmitAllVoteOnlyCommand.CanExecute(null)); }
public void ShouldRemoveOrdersViewWhenClosingLastOrder() { var container = new MockUnityResolver(); container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel()); var region = (MockRegion)regionManager.Regions["ActionRegion"]; var controller = new TestableOrdersController(regionManager, container, new MockStockTraderRICommandProxy(), null); var buyOrder = new MockOrderCompositePresentationModel() { Shares = 100 }; container.Bag[typeof(IOrderCompositePresentationModel)] = buyOrder; controller.InvokeStartOrder(TransactionType.Buy, "STOCK1"); Assert.AreEqual<int>(1, region.AddedViews.Count); buyOrder.RaiseCloseViewRequested(); Assert.AreEqual<int>(0, region.AddedViews.Count); }
public void CannotSellMoreSharesThanAreOwnedInDifferentOrders() { var container = new MockUnityResolver(); container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel()); 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 CannotSellMoreSharesThatAreNotOwned() { var container = new MockUnityResolver(); container.Bag.Add(typeof(IOrdersPresentationModel), new MockOrdersPresentationModel()); 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)); }