Ejemplo n.º 1
0
        public void MarketUpdatesPresenterPositionUpdatesButCollectionDoesNot()
        {
            var accountPositionService = new MockAccountPositionService();
            var marketFeedService = new MockMarketFeedService();
            var eventAggregator = CreateEventAggregator();
            var marketPricesUpdatedEvent = eventAggregator.GetEvent<MarketPricesUpdatedEvent>() as MockMarketPricesUpdatedEvent;
            marketFeedService.SetPrice("FUND1", 20.00m);
            accountPositionService.AddPosition("FUND1", 15.00m, 100);

            ObservablePosition position = new ObservablePosition(accountPositionService, marketFeedService, eventAggregator);

            bool itemsCollectionUpdated = false;
            position.Items.CollectionChanged += delegate
            {
                itemsCollectionUpdated = true;
            };

            bool itemUpdated = false;
            position.Items.First(p => p.TickerSymbol == "FUND1").PropertyChanged += delegate
            {
                itemUpdated = true;
            };

            marketPricesUpdatedEvent.SubscribeArgumentAction(new Dictionary<string, decimal> { { "FUND1", 50m } });

            Assert.IsFalse(itemsCollectionUpdated);
            Assert.IsTrue(itemUpdated);
        }
 public void SetUp()
 {
     view = new MockPositionSummaryView();
     accountPositionService = new MockAccountPositionService();
     marketFeedService = new MockMarketFeedService();
     marketHistoryService = new MockMarketHistoryService();
     trendLinePresenter = new MockTrendLinePresenter();
     ordersController = new MockOrdersController();
     this.eventAggregator = new MockEventAggregator();
 }
Ejemplo n.º 3
0
        public void GeneratesModelFromPositionAndMarketFeeds()
        {
            var accountPositionService = new MockAccountPositionService();
            var marketFeedService = new MockMarketFeedService();
            accountPositionService.AddPosition(new AccountPosition("FUND0", 300m, 1000));
            accountPositionService.AddPosition(new AccountPosition("FUND1", 200m, 100));
            marketFeedService.SetPrice("FUND0", 30.00m);
            marketFeedService.SetPrice("FUND1", 20.00m);

            ObservablePosition position = new ObservablePosition(accountPositionService, marketFeedService, CreateEventAggregator());

            Assert.AreEqual<decimal>(30.00m, position.Items.First(x => x.TickerSymbol == "FUND0").CurrentPrice);
            Assert.AreEqual<long>(1000, position.Items.First(x => x.TickerSymbol == "FUND0").Shares);
            Assert.AreEqual<decimal>(20.00m, position.Items.First(x => x.TickerSymbol == "FUND1").CurrentPrice);
            Assert.AreEqual<long>(100, position.Items.First(x => x.TickerSymbol == "FUND1").Shares);
        }
Ejemplo n.º 4
0
        public void ShouldUpdateDataWithMarketUpdates()
        {
            var accountPositionService = new MockAccountPositionService();
            var marketFeedService = new MockMarketFeedService();
            var eventAggregator = CreateEventAggregator();
            var marketPricesUpdatedEvent = eventAggregator.GetEvent<MarketPricesUpdatedEvent>() as MockMarketPricesUpdatedEvent;
            marketFeedService.SetPrice("FUND0", 30.00m);
            accountPositionService.AddPosition("FUND0", 25.00m, 1000);
            marketFeedService.SetPrice("FUND1", 20.00m);
            accountPositionService.AddPosition("FUND1", 15.00m, 100);
            ObservablePosition position = new ObservablePosition(accountPositionService, marketFeedService, eventAggregator);

            var updatedPriceList = new Dictionary<string, decimal> { { "FUND0", 50.00m } };
            Assert.IsNotNull(marketPricesUpdatedEvent.SubscribeArgumentAction);
            Assert.AreEqual(ThreadOption.UIThread, marketPricesUpdatedEvent.SubscribeArgumentThreadOption);

            marketPricesUpdatedEvent.SubscribeArgumentAction(updatedPriceList);

            Assert.AreEqual<decimal>(50.00m, position.Items.First(x => x.TickerSymbol == "FUND0").CurrentPrice);
        }
Ejemplo n.º 5
0
        public void AccountPositionModificationUpdatesPM()
        {
            var accountPositionService = new MockAccountPositionService();
            var marketFeedService = new MockMarketFeedService();
            marketFeedService.SetPrice("FUND0", 20.00m);
            accountPositionService.AddPosition("FUND0", 150.00m, 100);
            ObservablePosition position = new ObservablePosition(accountPositionService, marketFeedService, CreateEventAggregator());

            bool itemUpdated = false;
            position.Items.First(p => p.TickerSymbol == "FUND0").PropertyChanged += delegate
            {
                itemUpdated = true;
            };

            AccountPosition accountPosition = accountPositionService.GetAccountPositions().First<AccountPosition>(p => p.TickerSymbol == "FUND0");
            accountPosition.Shares += 11;
            accountPosition.CostBasis = 25.00m;

            Assert.IsTrue(itemUpdated);
            Assert.AreEqual(111, position.Items.First(p => p.TickerSymbol == "FUND0").Shares);
            Assert.AreEqual(25.00m, position.Items.First(p => p.TickerSymbol == "FUND0").CostBasis);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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);
            }

        }
        public void SharesIsHigherThanCurrentPositionOnSellThrows()
        {
            var accountPositionService = new MockAccountPositionService();
            accountPositionService.AddPosition(new AccountPosition("TESTFUND", 10m, 15));
            var viewModel = CreateViewModel(accountPositionService);

            viewModel.TickerSymbol = "TESTFUND";
            viewModel.TransactionType = TransactionType.Sell;

            try
            {
                viewModel.Shares = 16;
            }
            catch (InputValidationException)
            {
                return;
            }
            Assert.Fail("Exception not thrown.");
        }
        public void CannotSubmitIfStopLimitZero()
        {
            var accountPositionService = new MockAccountPositionService();
            accountPositionService.AddPosition(new AccountPosition("TESTFUND", 10m, 15));
            var viewModel = CreateViewModel(accountPositionService);

            viewModel.TickerSymbol = "TESTFUND";
            viewModel.TransactionType = TransactionType.Sell;
            viewModel.Shares = 5;
            viewModel.StopLimitPrice = 1;
            Assert.IsTrue(viewModel.SubmitCommand.CanExecute(null));

            try
            {
                viewModel.StopLimitPrice = 0;
            }
            catch (InputValidationException) { }

            Assert.IsFalse(viewModel.SubmitCommand.CanExecute(null));
        }
        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 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 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 CannotSubmitOnSellWhenSharesIsHigherThanCurrentPosition()
        {
            var accountPositionService = new MockAccountPositionService();
            accountPositionService.AddPosition(new AccountPosition("TESTFUND", 10m, 15));
            var presenter = CreatePresentationModel(accountPositionService);

            presenter.TickerSymbol = "TESTFUND";
            presenter.TransactionType = TransactionType.Sell;
            presenter.Shares = 5;
            presenter.StopLimitPrice = 1;
            Assert.IsTrue(presenter.SubmitCommand.CanExecute(null));

            try
            {
                presenter.Shares = 16;
            }
            catch (InputValidationException) { }
            Assert.IsFalse(presenter.SubmitCommand.CanExecute(null));
        }
Ejemplo n.º 14
0
        public void CannotSubmitIfStopLimitZero()
        {
            var accountPositionService = new MockAccountPositionService();
            accountPositionService.AddPosition(new AccountPosition("TESTFUND", 10m, 15));
            var presenter = CreatePresentationModel(new MockOrderDetailsView(), accountPositionService);

            presenter.TickerSymbol = "TESTFUND";
            presenter.TransactionType = TransactionType.Sell;
            presenter.Shares = 5;
            presenter.StopLimitPrice = 1;
            Assert.IsTrue(presenter.SubmitCommand.CanExecute(null));

            try
            {
                presenter.StopLimitPrice = 0;
            }
            catch (InputValidationException) { }

            Assert.IsFalse(presenter.SubmitCommand.CanExecute(null));
        }
        public void ShouldSetStopLimitPriceInModel()
        {
            var accountPositionService = new MockAccountPositionService();
            accountPositionService.AddPosition(new AccountPosition("TESTFUND", 10m, 15));
            var presenter = new TestableOrderDetailsPresenter(new MockOrderDetailsView(), accountPositionService);

            presenter.TickerSymbol = "TESTFUND";
            presenter.TransactionType = TransactionType.Sell;
            presenter.Shares = 5;
            presenter.StopLimitPrice = 0;

            Assert.AreEqual<string>("The stop limit price must be greater than 0", presenter["StopLimitPrice"]);
        }
        public void CannotSubmitIfStopLimitZero()
        {
            var accountPositionService = new MockAccountPositionService();
            accountPositionService.AddPosition(new AccountPosition("TESTFUND", 10m, 15));
            var presenter = new TestableOrderDetailsPresenter(new MockOrderDetailsView(), accountPositionService);

            presenter.TickerSymbol = "TESTFUND";
            presenter.TransactionType = TransactionType.Sell;
            presenter.Shares = 5;
            presenter.StopLimitPrice = 1;
            Assert.IsTrue(presenter.SubmitCommand.CanExecute(null));

            presenter.StopLimitPrice = 0;
            Assert.IsFalse(presenter.SubmitCommand.CanExecute(null));
        }