public void Constructor_ValidInput_DetailsCorrect() { // Fixture setup var expectedTitle = "News title"; var expectedText = "News text"; Uri expectedImageSource = null; var expectedPublicationDate = DateTimeOffset.Now; var channelName = "News channel"; var expectedPublicationDetails = expectedPublicationDate.ToString("dd.MM.yyy - HH:mm") + " • " + channelName; var newsChannel = new NewsChannel(channelName, new Uri("http://news.com/rss")); var newsItem = new NewsItem(expectedTitle, expectedText, expectedPublicationDate, expectedImageSource); // Exercise system var viewModel = new NewsDetailsViewModel(newsChannel, newsItem); // Verify outcome Assert.AreEqual(viewModel.Title, expectedTitle); Assert.AreEqual(viewModel.Text, expectedText); Assert.AreEqual(viewModel.PublicationDate, expectedPublicationDate); Assert.AreEqual(viewModel.ImageSource, expectedImageSource); Assert.AreEqual(viewModel.PublicationDetails, expectedPublicationDetails); // Teardown }
public void Constructor_NullNewsChannel_ExceptionThrown() { // Fixture setup NewsChannel newsChannel = null; var newsItem = new NewsItem("News title", "News text", DateTimeOffset.Now, null); // Exercise system // Verify outcome Assert.ThrowsException<ArgumentNullException> (() => new NewsDetailsViewModel(newsChannel, newsItem)); // Teardown }
public async Task GetLatestNewsAsync_MockForTwoNewsChannels_ValidNewsItemsSortingOrder() { // Fixture setup var firstItem = new NewsItem("First item", "News text", DateTimeOffset.Now, null); var secondItem = new NewsItem("Second item", "News text", firstItem.PublicationDate.AddSeconds(1), null); var requestCounter = 0; Func<string, NewsFeed> parsingFunc = rss => { requestCounter++; if (requestCounter == 1) return new NewsFeed(new[] { firstItem }); return new NewsFeed(new[] { secondItem }); }; IHttpClient httpClient = new HttpClientMock(); IRssParser rssParser = new RssParserMock { CustomParsingFunction = parsingFunc }; IProgressIndicator progressIndicator = new ProgressIndicatorMock(); var viewModel = new NewsFeedViewModel(httpClient, rssParser, progressIndicator); var newsChannel = new NewsChannel("News channel", new Uri("http://news.com/rss")); var expectedFirstItemTitle = secondItem.Title; // Exercise system await viewModel.GetLatestNewsAsync(newsChannel, newsChannel); // Verify outcome Assert.AreEqual(viewModel.News[0].Title, expectedFirstItemTitle); // Teardown }
public async Task GetLatestNewsAsync_MockForTwoNewsChannels_ValidItemCount() { // Fixture setup var newsItem = new NewsItem("News item", "News text", DateTimeOffset.Now, null); Func<string, NewsFeed> parsingFunc = rss => new NewsFeed(new[] { newsItem }); IHttpClient httpClient = new HttpClientMock(); IRssParser rssParser = new RssParserMock { CustomParsingFunction = parsingFunc }; IProgressIndicator progressIndicator = new ProgressIndicatorMock(); var viewModel = new NewsFeedViewModel(httpClient, rssParser, progressIndicator); var newsChannel = new NewsChannel("News channel", new Uri("http://news.com/rss")); var expectedNewsCount = 2; // Exercise system await viewModel.GetLatestNewsAsync(newsChannel, newsChannel); // Verify outcome Assert.AreEqual(viewModel.News.Count, expectedNewsCount); // Teardown }