Exemplo n.º 1
0
        public async Task ShouldRetrieveDesiredNumberOfPosts()
        {
            var desiredPosts = 30;

            _hackerNewsServiceAgent.Setup(c => c.GetDataFromPage(It.IsAny <int>())).ReturnsAsync("<html></html>");
            _pageParser.Setup(c => c.GetHackerNewsPosts(It.IsAny <string>())).Returns(GenerateData(desiredPosts));
            var posts = await _hackerNewsPostsService.GetPosts(desiredPosts).ConfigureAwait(false);;

            Assert.Equal(desiredPosts, posts.Count);
        }
        public async Task <string> GetPosts(int numberOfPosts)
        {
            var hackerNewsPosts = await _postService.GetPosts(numberOfPosts).ConfigureAwait(false);

            List <Post> posts = hackerNewsPosts.Select(p => _mapper.Map <Post>(p)).ToList();

            return(GetJson(posts));
        }