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