Пример #1
0
        public async Task GetPageComments_ShouldReturnOneComment_WhenCommentsListHasOneComment()
        {
            // Arrange
            var comments = new FacebookCommentsPage
            {
                Comments = new List <FacebookComment>
                {
                    new FacebookComment {
                        Id = "id"
                    }
                }
            };

            _httpMockHandler.When(FacebookOkCommentsUrlPattern)
            .Respond(HttpStatusCode.OK, "application/json", "{}");
            _jsonParser.ParseJsonResponse <FacebookCommentsPage>(Arg.Any <string>())
            .Returns(comments, null, null);     // null stops recursion
            var wrapper = new FacebookCommentsApiWrapper(_httpClientFactory, _jsonParser);

            // Act
            var result = await wrapper.GetPageCommentsAsync("accessToken", "pageId");

            // Assert
            result.Should().HaveCount(1);
            result.FirstOrDefault().Children.Should().BeEmpty();
        }
Пример #2
0
        public async Task GetPageComments_ShouldReturnOneCommentWithOneChild_WhenCommentsListHasOneCommentWithReply()
        {
            // Arrange
            const string commentId = "comment";
            const string replyId   = "reply";
            var          comments  = new FacebookCommentsPage
            {
                Comments = new List <FacebookComment>
                {
                    new FacebookComment
                    {
                        Id = commentId
                    }
                }
            };

            var comments2 = new FacebookCommentsPage
            {
                Comments = new List <FacebookComment>
                {
                    new FacebookComment
                    {
                        Id = replyId
                    }
                }
            };

            _httpMockHandler.When(FacebookOkCommentsUrlPattern)
            .Respond(HttpStatusCode.OK, "application/json", "{}");
            _jsonParser.ParseJsonResponse <FacebookCommentsPage>(Arg.Any <string>())
            .Returns(comments, comments2, null);     // second call returns reply, and null stops recursion
            var wrapper = new FacebookCommentsApiWrapper(_httpClientFactory, _jsonParser);

            // Act
            var result = await wrapper.GetPageCommentsAsync("accessToken", "pageId");

            // Assert
            result.Should().HaveCount(1);
            result.FirstOrDefault().Id.Should().Be(commentId);
            result.FirstOrDefault().Children.Should().HaveCount(1);
            result.FirstOrDefault().Children.FirstOrDefault().Id.Should().Be(replyId);
        }