コード例 #1
0
        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
        }
コード例 #2
0
        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
        }
コード例 #3
0
		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
		}
コード例 #4
0
		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
		}