Ejemplo n.º 1
0
        public async Task TestCommentsFaceBookService()
        {
            var service = new FaceBookService(new SafeHttpClient(), new FaceBookConfiguration {
                AppId = _appId, AppSecret = _appSecret
            });

            var pageIds = await service.GetPagesAsync("WorldsBestOfTheBest");

            Assert.IsNotNull(pageIds);
            Assert.IsNotEmpty(pageIds);

            var postIds = await service.GetPostsAsync(pageIds.FirstOrDefault().Id);

            Assert.IsNotNull(postIds);
            Assert.IsNotEmpty(postIds);

            var comments = await service.GetCommentsAsync(postIds.FirstOrDefault().Id);

            Assert.IsNotNull(comments);
            Assert.IsNotEmpty(comments);

            TestContext.WriteLine($"Comments: {comments.Count}");
            foreach (var comment in comments.Take(100))
            {
                Assert.IsNotNull(comment.Content);
                Assert.IsNotNull(comment.Author);
                Assert.AreEqual("Facebook", comment.Source);
            }
        }
        public async Task GetCommentsAsyncPagingTest()
        {
            // Model Setup
            _mockCommentsResponse.Paging = new Facebook.Paging
            {
                Next = $"https://graph.facebook.com/v2.10/Post1/comments?access_token={_mockAccessTokenResponse.AccessToken}"
            };

            // Mock
            var httpMock = new Mock <ISafeHttpClient>(MockBehavior.Strict);

            httpMock.SetupSequence(x => x.GetAsync <Facebook.CommentsResponse>(It.Is <string>(s => checkApiCall(s, "/v2.10/Post1/comments", null))))
            .ReturnsAsync(_mockCommentsResponse)
            .ReturnsAsync(_mockCommentsResponseSecondPage);
            httpMock.Setup(x => x.GetAsync <Facebook.AccessTokenResponse>(It.Is <string>(s => s.Contains("https://graph.facebook.com/oauth/access_token"))))
            .ReturnsAsync(_mockAccessTokenResponse);

            // Run
            var service  = new FaceBookService(httpMock.Object, config);
            var comments = await service.GetCommentsAsync("Post1");

            // Assert
            Assert.IsNotNull(comments);
            Assert.AreEqual(4, comments.Count);

            // Verify
            httpMock.VerifyAll();
        }
        public async Task GGetCommentsAsyncNullTest()
        {
            // Mock
            var httpMock = new Mock <ISafeHttpClient>(MockBehavior.Strict);

            httpMock.Setup(x => x.GetAsync <Facebook.CommentsResponse>(It.Is <string>(s => checkApiCall(s, "/v2.10/Post1/comments", null))))
            .ReturnsAsync(null as Facebook.CommentsResponse);
            httpMock.Setup(x => x.GetAsync <Facebook.AccessTokenResponse>(It.Is <string>(s => s.Contains("https://graph.facebook.com/oauth/access_token"))))
            .ReturnsAsync(_mockAccessTokenResponse);

            // Run
            var service  = new FaceBookService(httpMock.Object, config);
            var comments = await service.GetCommentsAsync("Post1");

            // Assert
            Assert.IsNotNull(comments);
            Assert.IsEmpty(comments);

            // Verify
            httpMock.VerifyAll();
        }