예제 #1
0
        public void WhenCurrentWatchItemSet_PropertyIsUpdated()
        {
            // Prepare
            MockMarketPricesUpdatedEvent     marketPricesUpdatedEvent      = new MockMarketPricesUpdatedEvent();
            Mock <TickerSymbolSelectedEvent> mockTickerSymbolSelectedEvent = new Mock <TickerSymbolSelectedEvent>();

            ObservableCollection <string> watchList = new ObservableCollection <string>();

            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock <IWatchListService> mockWatchListService = new Mock <IWatchListService>();

            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock <IMarketFeedService> mockMarketFeedService = new Mock <IMarketFeedService>();

            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock <IRegionManager> mockRegionManager = new Mock <IRegionManager>();

            Mock <IEventAggregator> mockEventAggregator = new Mock <IEventAggregator>();

            mockEventAggregator.Setup(x => x.GetEvent <MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);
            mockEventAggregator.Setup(x => x.GetEvent <TickerSymbolSelectedEvent>()).Returns(mockTickerSymbolSelectedEvent.Object);

            IWatchListService  watchListService  = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager     regionManager     = mockRegionManager.Object;
            IEventAggregator   eventAggregator   = mockEventAggregator.Object;

            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            bool propertyChangedRaised = false;

            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "CurrentWatchItem")
                {
                    propertyChangedRaised = true;
                }
            };


            // Act
            target.CurrentWatchItem = target.WatchListItems[1];

            // Verify
            Assert.AreSame(target.WatchListItems[1], target.CurrentWatchItem);
            Assert.IsTrue(propertyChangedRaised);
        }
예제 #2
0
        public void WhenMarketPriceChagnes_PriceUpdated()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection <string> watchList = new ObservableCollection <string>();

            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock <IWatchListService> mockWatchListService = new Mock <IWatchListService>();

            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock <IMarketFeedService> mockMarketFeedService = new Mock <IMarketFeedService>();

            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock <IRegionManager> mockRegionManager = new Mock <IRegionManager>();

            Mock <IEventAggregator> mockEventAggregator = new Mock <IEventAggregator>();

            mockEventAggregator.Setup(x => x.GetEvent <MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService  watchListService  = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager     regionManager     = mockRegionManager.Object;
            IEventAggregator   eventAggregator   = mockEventAggregator.Object;

            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            Dictionary <string, decimal> newPrices = new Dictionary <string, decimal>()
            {
                { "A", 10 },
                { "B", 20 },
                { "C", 30 },
            };

            // Act
            marketPricesUpdatedEvent.Publish(newPrices);

            // Verify
            Assert.AreEqual(3, target.WatchListItems.Count);
            Assert.AreEqual(10, target.WatchListItems[0].CurrentPrice);
            Assert.AreEqual(20, target.WatchListItems[1].CurrentPrice);
            Assert.AreEqual(30, target.WatchListItems[2].CurrentPrice);
        }
        public void WhenCurrentWatchItemSet_PropertyIsUpdated()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();
            Mock<TickerSymbolSelectedEvent> mockTickerSymbolSelectedEvent = new Mock<TickerSymbolSelectedEvent>();

            ObservableCollection<string> watchList = new ObservableCollection<string>();
            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock<IWatchListService> mockWatchListService = new Mock<IWatchListService>();
            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock<IMarketFeedService> mockMarketFeedService = new Mock<IMarketFeedService>();
            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock<IRegionManager> mockRegionManager = new Mock<IRegionManager>();

            Mock<IEventAggregator> mockEventAggregator = new Mock<IEventAggregator>();
            mockEventAggregator.Setup(x => x.GetEvent<MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);
            mockEventAggregator.Setup(x => x.GetEvent<TickerSymbolSelectedEvent>()).Returns(mockTickerSymbolSelectedEvent.Object);

            IWatchListService watchListService = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager regionManager = mockRegionManager.Object;
            IEventAggregator eventAggregator = mockEventAggregator.Object;
            
            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            bool propertyChangedRaised = false;
            target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "CurrentWatchItem")
                {
                    propertyChangedRaised = true;
                }
            };

            
            // Act
            target.CurrentWatchItem = target.WatchListItems[1];

            // Verify
            Assert.AreSame(target.WatchListItems[1], target.CurrentWatchItem);
            Assert.IsTrue(propertyChangedRaised);
        }
예제 #4
0
        public void WhenWatchListItemAdded_NavigatesToWatchListView()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection <string> watchList = new ObservableCollection <string>();

            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock <IWatchListService> mockWatchListService = new Mock <IWatchListService>();

            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock <IMarketFeedService> mockMarketFeedService = new Mock <IMarketFeedService>();

            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock <IRegion> mockMainRegion = new Mock <IRegion>();

            mockMainRegion.Setup(x => x.RequestNavigate(new Uri("/WatchListView", UriKind.RelativeOrAbsolute), It.IsAny <Action <NavigationResult> >())).Verifiable();

            Mock <IRegionManager> mockRegionManager = new Mock <IRegionManager>();

            mockRegionManager.Setup(x => x.Regions[RegionNames.MainRegion]).Returns(mockMainRegion.Object);

            Mock <IEventAggregator> mockEventAggregator = new Mock <IEventAggregator>();

            mockEventAggregator.Setup(x => x.GetEvent <MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService  watchListService  = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager     regionManager     = mockRegionManager.Object;
            IEventAggregator   eventAggregator   = mockEventAggregator.Object;

            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Act
            target.WatchListItems.Add(new WatchItem("D", 20));

            // Verify
            mockMainRegion.Verify(x => x.RequestNavigate(new Uri("/WatchListView", UriKind.RelativeOrAbsolute), It.IsAny <Action <NavigationResult> >()), Times.Once());
        }
예제 #5
0
        public void WhenRemoveCommandExecuted_RemovesWatchEntry()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection <string> watchList = new ObservableCollection <string>();

            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock <IWatchListService> mockWatchListService = new Mock <IWatchListService>();

            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock <IMarketFeedService> mockMarketFeedService = new Mock <IMarketFeedService>();

            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock <IRegion> mockMainRegion = new Mock <IRegion>();

            Mock <IRegionManager> mockRegionManager = new Mock <IRegionManager>();

            mockRegionManager.Setup(x => x.Regions[RegionNames.MainRegion]).Returns(mockMainRegion.Object);

            Mock <IEventAggregator> mockEventAggregator = new Mock <IEventAggregator>();

            mockEventAggregator.Setup(x => x.GetEvent <MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService  watchListService  = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager     regionManager     = mockRegionManager.Object;
            IEventAggregator   eventAggregator   = mockEventAggregator.Object;

            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Act
            target.RemoveWatchCommand.Execute("A");

            // Verify
            Assert.AreEqual(2, target.WatchListItems.Count);
        }
예제 #6
0
        public void WhenCurrentWatchItemSet_TickerSymbolSelectedEventRaised()
        {
            // Prepare
            MockMarketPricesUpdatedEvent     marketPricesUpdatedEvent      = new MockMarketPricesUpdatedEvent();
            Mock <TickerSymbolSelectedEvent> mockTickerSymbolSelectedEvent = new Mock <TickerSymbolSelectedEvent>();

            mockTickerSymbolSelectedEvent.Setup(x => x.Publish("B")).Verifiable();

            ObservableCollection <string> watchList = new ObservableCollection <string>();

            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock <IWatchListService> mockWatchListService = new Mock <IWatchListService>();

            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock <IMarketFeedService> mockMarketFeedService = new Mock <IMarketFeedService>();

            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock <IRegionManager> mockRegionManager = new Mock <IRegionManager>();

            Mock <IEventAggregator> mockEventAggregator = new Mock <IEventAggregator>();

            mockEventAggregator.Setup(x => x.GetEvent <MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);
            mockEventAggregator.Setup(x => x.GetEvent <TickerSymbolSelectedEvent>()).Returns(mockTickerSymbolSelectedEvent.Object);

            IWatchListService  watchListService  = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager     regionManager     = mockRegionManager.Object;
            IEventAggregator   eventAggregator   = mockEventAggregator.Object;

            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Act
            target.CurrentWatchItem = target.WatchListItems[1];

            // Verify
            mockTickerSymbolSelectedEvent.VerifyAll();
        }
예제 #7
0
        public void WhenConstructed_IntializesValues()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection <string> watchList = new ObservableCollection <string>();

            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock <IWatchListService> mockWatchListService = new Mock <IWatchListService>();

            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock <IMarketFeedService> mockMarketFeedService = new Mock <IMarketFeedService>();

            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock <IRegionManager> mockRegionManager = new Mock <IRegionManager>();

            Mock <IEventAggregator> mockEventAggregator = new Mock <IEventAggregator>();

            mockEventAggregator.Setup(x => x.GetEvent <MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService  watchListService  = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager     regionManager     = mockRegionManager.Object;
            IEventAggregator   eventAggregator   = mockEventAggregator.Object;

            // Act
            WatchListViewModel actual = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Verify
            Assert.IsNotNull(actual);
            Assert.AreEqual("WATCH LIST", actual.HeaderInfo);
            Assert.AreEqual(3, actual.WatchListItems.Count);
            Assert.IsNull(actual.CurrentWatchItem);
            Assert.IsNotNull(actual.RemoveWatchCommand);
            mockWatchListService.VerifyAll();
        }
예제 #8
0
        public void PresenterObservesMarketFeedAndUpdatesView()
        {
            var marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            eventAggregator.AddMapping <MarketPricesUpdatedEvent>(marketPricesUpdatedEvent);

            marketFeedService.feedData.Add("TESTFUND0", 15.5m);
            watchListService.MockWatchList.Add("TESTFUND0");

            WatchListPresentationModel presentationModel = CreatePresenter();

            Assert.AreEqual <decimal>(15.5m, view.Model.WatchListItems[0].CurrentPrice.Value);

            Assert.IsNotNull(marketPricesUpdatedEvent.SubscribeArgumentAction);
            Assert.AreEqual(ThreadOption.UIThread, marketPricesUpdatedEvent.SubscribeArgumentThreadOption);

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

            Assert.AreEqual <decimal>(25.3m, view.Model.WatchListItems[0].CurrentPrice.Value);
        }
        public void WhenConstructed_IntializesValues()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection<string> watchList = new ObservableCollection<string>();
            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock<IWatchListService> mockWatchListService = new Mock<IWatchListService>();
            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock<IMarketFeedService> mockMarketFeedService = new Mock<IMarketFeedService>();
            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock<IRegionManager> mockRegionManager = new Mock<IRegionManager>();

            Mock<IEventAggregator> mockEventAggregator = new Mock<IEventAggregator>();
            mockEventAggregator.Setup(x => x.GetEvent<MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService watchListService = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager regionManager = mockRegionManager.Object;
            IEventAggregator eventAggregator = mockEventAggregator.Object;

            // Act
            WatchListViewModel actual = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Verify
            Assert.IsNotNull(actual);
            Assert.AreEqual("WATCH LIST", actual.HeaderInfo);
            Assert.AreEqual(3, actual.WatchListItems.Count);
            Assert.IsNull(actual.CurrentWatchItem);
            Assert.IsNotNull(actual.RemoveWatchCommand);
            mockWatchListService.VerifyAll();            
        }
예제 #10
0
        public void WhenMarketPriceNotAvailable_PriceSetToNull()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection <string> watchList = new ObservableCollection <string>();

            watchList.Add("A");

            Mock <IWatchListService> mockWatchListService = new Mock <IWatchListService>();

            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock <IMarketFeedService> mockMarketFeedService = new Mock <IMarketFeedService>();

            mockMarketFeedService.Setup(x => x.GetPrice("A")).Throws(new ArgumentException("tickerSymbol"));

            Mock <IRegionManager> mockRegionManager = new Mock <IRegionManager>();

            Mock <IEventAggregator> mockEventAggregator = new Mock <IEventAggregator>();

            mockEventAggregator.Setup(x => x.GetEvent <MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService  watchListService  = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager     regionManager     = mockRegionManager.Object;
            IEventAggregator   eventAggregator   = mockEventAggregator.Object;

            // Act
            WatchListViewModel actual = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Verify
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.WatchListItems.Count);
            Assert.AreEqual("A", actual.WatchListItems[0].TickerSymbol);
            Assert.AreEqual(null, actual.WatchListItems[0].CurrentPrice);
        }
        public void PresenterObservesMarketFeedAndUpdatesView()
        {
            var marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();
            eventAggregator.AddMapping<MarketPricesUpdatedEvent>(marketPricesUpdatedEvent);

            marketFeedService.feedData.Add("TESTFUND0", 15.5m);
            watchListService.MockWatchList.Add("TESTFUND0");

            WatchListPresentationModel presentationModel = CreatePresenter();

            Assert.AreEqual<decimal>(15.5m, view.Model.WatchListItems[0].CurrentPrice.Value);

            Assert.IsNotNull(marketPricesUpdatedEvent.SubscribeArgumentAction);
            Assert.AreEqual(ThreadOption.UIThread, marketPricesUpdatedEvent.SubscribeArgumentThreadOption);

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

            Assert.AreEqual<decimal>(25.3m, view.Model.WatchListItems[0].CurrentPrice.Value);
        }
        public void WhenMarketPriceChagnes_PriceUpdated()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection<string> watchList = new ObservableCollection<string>();
            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock<IWatchListService> mockWatchListService = new Mock<IWatchListService>();
            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock<IMarketFeedService> mockMarketFeedService = new Mock<IMarketFeedService>();
            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock<IRegionManager> mockRegionManager = new Mock<IRegionManager>();

            Mock<IEventAggregator> mockEventAggregator = new Mock<IEventAggregator>();
            mockEventAggregator.Setup(x => x.GetEvent<MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService watchListService = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager regionManager = mockRegionManager.Object;
            IEventAggregator eventAggregator = mockEventAggregator.Object;

            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            Dictionary<string, decimal> newPrices = new Dictionary<string,decimal>()
            {
                { "A", 10 },
                { "B", 20 },
                { "C", 30 },
            };

            // Act
            marketPricesUpdatedEvent.Publish(newPrices);

            // Verify
            Assert.AreEqual(3, target.WatchListItems.Count);
            Assert.AreEqual(10, target.WatchListItems[0].CurrentPrice);
            Assert.AreEqual(20, target.WatchListItems[1].CurrentPrice);
            Assert.AreEqual(30, target.WatchListItems[2].CurrentPrice);
        }
        public void WhenMarketPriceNotAvailable_PriceSetToNull()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection<string> watchList = new ObservableCollection<string>();
            watchList.Add("A");

            Mock<IWatchListService> mockWatchListService = new Mock<IWatchListService>();
            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock<IMarketFeedService> mockMarketFeedService = new Mock<IMarketFeedService>();
            mockMarketFeedService.Setup(x => x.GetPrice("A")).Throws(new ArgumentException("tickerSymbol"));

            Mock<IRegionManager> mockRegionManager = new Mock<IRegionManager>();

            Mock<IEventAggregator> mockEventAggregator = new Mock<IEventAggregator>();
            mockEventAggregator.Setup(x => x.GetEvent<MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService watchListService = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager regionManager = mockRegionManager.Object;
            IEventAggregator eventAggregator = mockEventAggregator.Object;

            // Act
            WatchListViewModel actual = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Verify
            Assert.IsNotNull(actual);            
            Assert.AreEqual(1, actual.WatchListItems.Count);
            Assert.AreEqual("A", actual.WatchListItems[0].TickerSymbol);
            Assert.AreEqual(null, actual.WatchListItems[0].CurrentPrice);
        }
        public void WhenWatchListItemAdded_NavigatesToWatchListView()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection<string> watchList = new ObservableCollection<string>();
            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock<IWatchListService> mockWatchListService = new Mock<IWatchListService>();
            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock<IMarketFeedService> mockMarketFeedService = new Mock<IMarketFeedService>();
            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock<IRegion> mockMainRegion = new Mock<IRegion>();
            mockMainRegion.Setup(x => x.RequestNavigate(new Uri("/WatchListView", UriKind.RelativeOrAbsolute), It.IsAny<Action<NavigationResult>>())).Verifiable();            

            Mock<IRegionManager> mockRegionManager = new Mock<IRegionManager>();
            mockRegionManager.Setup(x => x.Regions[RegionNames.MainRegion]).Returns(mockMainRegion.Object);

            Mock<IEventAggregator> mockEventAggregator = new Mock<IEventAggregator>();
            mockEventAggregator.Setup(x => x.GetEvent<MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService watchListService = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager regionManager = mockRegionManager.Object;
            IEventAggregator eventAggregator = mockEventAggregator.Object;

            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Act
            target.WatchListItems.Add(new WatchItem("D", 20));

            // Verify
            mockMainRegion.Verify(x => x.RequestNavigate(new Uri("/WatchListView", UriKind.RelativeOrAbsolute), It.IsAny<Action<NavigationResult>>()), Times.Once());
        }
        public void WhenRemoveCommandExecuted_RemovesWatchEntry()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();

            ObservableCollection<string> watchList = new ObservableCollection<string>();
            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock<IWatchListService> mockWatchListService = new Mock<IWatchListService>();
            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock<IMarketFeedService> mockMarketFeedService = new Mock<IMarketFeedService>();
            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock<IRegion> mockMainRegion = new Mock<IRegion>();

            Mock<IRegionManager> mockRegionManager = new Mock<IRegionManager>();
            mockRegionManager.Setup(x => x.Regions[RegionNames.MainRegion]).Returns(mockMainRegion.Object);

            Mock<IEventAggregator> mockEventAggregator = new Mock<IEventAggregator>();
            mockEventAggregator.Setup(x => x.GetEvent<MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);

            IWatchListService watchListService = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager regionManager = mockRegionManager.Object;
            IEventAggregator eventAggregator = mockEventAggregator.Object;

            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Act
            target.RemoveWatchCommand.Execute("A");

            // Verify
            Assert.AreEqual(2, target.WatchListItems.Count);
        }
        public void WhenCurrentWatchItemSet_TickerSymbolSelectedEventRaised()
        {
            // Prepare
            MockMarketPricesUpdatedEvent marketPricesUpdatedEvent = new MockMarketPricesUpdatedEvent();
            Mock<TickerSymbolSelectedEvent> mockTickerSymbolSelectedEvent = new Mock<TickerSymbolSelectedEvent>();
            mockTickerSymbolSelectedEvent.Setup(x => x.Publish("B")).Verifiable();

            ObservableCollection<string> watchList = new ObservableCollection<string>();
            watchList.Add("A");
            watchList.Add("B");
            watchList.Add("C");

            Mock<IWatchListService> mockWatchListService = new Mock<IWatchListService>();
            mockWatchListService.Setup(x => x.RetrieveWatchList()).Returns(watchList).Verifiable();

            Mock<IMarketFeedService> mockMarketFeedService = new Mock<IMarketFeedService>();
            mockMarketFeedService.Setup(x => x.GetPrice("A")).Returns(1);
            mockMarketFeedService.Setup(x => x.GetPrice("B")).Returns(2);
            mockMarketFeedService.Setup(x => x.GetPrice("C")).Returns(3);

            Mock<IRegionManager> mockRegionManager = new Mock<IRegionManager>();

            Mock<IEventAggregator> mockEventAggregator = new Mock<IEventAggregator>();
            mockEventAggregator.Setup(x => x.GetEvent<MarketPricesUpdatedEvent>()).Returns(marketPricesUpdatedEvent);
            mockEventAggregator.Setup(x => x.GetEvent<TickerSymbolSelectedEvent>()).Returns(mockTickerSymbolSelectedEvent.Object);

            IWatchListService watchListService = mockWatchListService.Object;
            IMarketFeedService marketFeedService = mockMarketFeedService.Object;
            IRegionManager regionManager = mockRegionManager.Object;
            IEventAggregator eventAggregator = mockEventAggregator.Object;

            WatchListViewModel target = new WatchListViewModel(watchListService, marketFeedService, regionManager, eventAggregator);

            // Act
            target.CurrentWatchItem = target.WatchListItems[1];

            // Verify
            mockTickerSymbolSelectedEvent.VerifyAll();
        }