public void WhenArticleViewModelSelectedArticleChanged_NewsReaderViewModelNewsArticleUpdated() { // Prepare INewsFeedService newsFeedService = new Mock <INewsFeedService>().Object; IRegionManager regionManager = new Mock <IRegionManager>().Object; var tickerSymbolSelectedEvent = new Mock <TickerSymbolSelectedEvent>().Object; var mockEventAggregator = new Mock <IEventAggregator>(); mockEventAggregator.Setup(x => x.GetEvent <TickerSymbolSelectedEvent>()).Returns(tickerSymbolSelectedEvent); IEventAggregator eventAggregator = mockEventAggregator.Object; ArticleViewModel articleViewModel = new ArticleViewModel(newsFeedService, regionManager, eventAggregator); NewsReaderViewModel newsReaderViewModel = new NewsReaderViewModel(); var controller = new NewsController(articleViewModel, newsReaderViewModel); NewsArticle newsArticle = new NewsArticle() { Title = "SomeTitle", Body = "Newsbody" }; // Act articleViewModel.SelectedArticle = newsArticle; // Verify Assert.AreSame(newsArticle, newsReaderViewModel.NewsArticle); }
public NewsController(ArticleViewModel articleViewModel, NewsReaderViewModel newsReaderViewModel) { this.articleViewModel = articleViewModel; this.newsReaderViewModel = newsReaderViewModel; if (articleViewModel != null) { this.articleViewModel.PropertyChanged += this.ArticleViewModel_PropertyChanged; } }
public void ShouldViewModelBeInitializedAndAssociated() { //arrange viewModel = new NewsReaderViewModel(DataManager); //act //assert Assert.IsNotNull(viewModel); }
public void ShouldExecuteTextSizeDecreaseTextSize() { //arrange viewModel = new NewsReaderViewModel(DataManager); double titleTextSize = viewModel.TitleTextSize; double textSize = viewModel.TextSize; //act Task.Run(async() => { await viewModel.ExecuteDecreaseTextSizeCommandAsync(); }).GetAwaiter().GetResult(); //assert viewModel.TitleTextSize.ShouldBeLessThan(titleTextSize); viewModel.TextSize.ShouldBeLessThan(textSize); }
public void ShouldInitMethodLoadNewsData() { //arrange viewModel = new NewsReaderViewModel(DataManager); NewsViewModel newsViewModel = new NewsViewModel() { ItemTitle = "Sample Title", Text = "This is a sample text to showcase features of news reader.", Image = "sampleOne", Date = DateTime.Now }; //act viewModel.Init(newsViewModel); //assert viewModel.NewsViewModel.ItemTitle.ShouldBe(newsViewModel.ItemTitle); viewModel.NewsViewModel.Text.ShouldBe(newsViewModel.Text); viewModel.NewsViewModel.Image.ShouldBe(newsViewModel.Image); Assert.AreEqual(viewModel.NewsViewModel.Date, newsViewModel.Date); }
public void SetNewsArticleUpdatesProperty() { var target = new NewsReaderViewModel(); bool propertyChangedRaised = false; target.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "NewsArticle") { propertyChangedRaised = true; } }; NewsArticle article = new NewsArticle() { Title = "My Title", Body = "My Body" }; target.NewsArticle = article; Assert.AreSame(article, target.NewsArticle); Assert.IsTrue(propertyChangedRaised); }