Beispiel #1
0
        public async Task ArticlesReturnsListOfArticlesForAllTopics()
        {
            var sources  = TestHelper.GetMockedSources();
            var articles = TestHelper.GetMockedArticles();

            var client = new Mock <IClient>();

            client.Setup(x => x.GetSourcesAsync(null, null, "en")).Returns(Task.FromResult(sources));

            client.Setup(x => x.GetArticlesAsync("ars-technica", Sort.Top)).Returns(Task.FromResult(new Articles
            {
                Items = new List <Article>()
                {
                    articles[0]
                }
            }));

            client.Setup(x => x.GetArticlesAsync("associated-press", Sort.Top)).Returns(Task.FromResult(new Articles
            {
                Items = new List <Article>()
                {
                    articles[1]
                }
            }));

            var controller = new NewsController(client.Object);
            var result     = await controller.Articles(null);

            Assert.AreEqual(articles[0].Title, result[0].Items.First().Title);
            Assert.AreEqual(articles[1].Title, result[1].Items.First().Title);
        }