public async System.Threading.Tasks.Task GetTopPostsShouldReturnTopPosts()
        {
            var topPostsIds = await hns.GetTopPostsIds(2);

            Assert.IsNotNull(topPostsIds);
            Assert.AreEqual(topPostsIds.Count, 2);
            var topPosts = await hns.GetTopPosts(topPostsIds);

            Assert.IsNotNull(topPosts);
            Assert.AreEqual(topPosts.Count, 2);
            Assert.IsFalse(string.IsNullOrEmpty(topPosts[0].Title));
        }
Example #2
0
        public void GiveAHackerNewsResponse_WhereTopStoryIdsAreNotAvailable_ExpectNoPosts()
        {
            //Arrange
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://hacker-news.firebaseio.com/v0/topstories.json")
            .Respond("application/json", $"[]");
            var client  = new HttpClient(mockHttp);
            var service = new HackerNewsService(client);

            //Act
            var posts = service.GetTopPosts(consoleStream).ToList();

            //Assert
            posts.Count.Should().Be(0);
        }
Example #3
0
        public void GivenAHackerNewsResponse_WhereTwoWellFormedPostsExist_ExpectTwoPostObjectsToBeConstructed()
        {
            //Arrange
            var mockHttp = MockPostHttpMessageHandlerCreator.Create(new List <long> {
                21134540, 21135259
            });
            var client  = new HttpClient(mockHttp);
            var service = new HackerNewsService(client);

            //Act
            var posts = service.GetTopPosts(consoleStream).ToList();

            //Assert
            posts.Count.Should().Be(2);
            posts.FirstOrDefault(p => p.id == 21134540).Should().NotBeNull();
            posts.FirstOrDefault(p => p.id == 21135259).Should().NotBeNull();
        }