コード例 #1
0
        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();
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        public async Task <IActionResult> Get(string token)
        {
            using (var service = new FaceBookService(this.configuration)){
                var result = await service.GetMeAsync(token);

                return(Json(result));
            }
        }
コード例 #4
0
ファイル: UserController.cs プロジェクト: jcpc91/fb-loginpage
        public async Task <IActionResult> Post([FromForm] string token)
        {
            using (var fbservice = new FaceBookService(this.configuration)){
                Models.User me = await fbservice.GetMeAsync(token);

                var    userservice = new UserService(this.configuration);
                string tokenapp    = userservice.GenerateToken(me);
                return(Json(tokenapp));
            }
        }
コード例 #5
0
ファイル: LoginViewModel.cs プロジェクト: Akinnagbe/crawlApp
        public async Task CallFaceBookGraphAPI(string accessToken)
        {
            IsSuccess = false;
            FaceBookService faceBookService = new FaceBookService();

            //var facebookServices = customerRestService.FacebookServices();

            FacebookProfile = await faceBookService.GetFacebookProfileAsync(accessToken);

            if (FacebookProfile != null)
            {
                IsSuccess = true;
            }
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        public async Task GetPagesAsyncTest()
        {
            // Mock
            var httpMock = new Mock <ISafeHttpClient>(MockBehavior.Strict);

            httpMock.Setup(x => x.GetAsync <Facebook.PagesResponse>(It.Is <string>(s => checkApiCall(s, "/v2.10/search", null))))
            .ReturnsAsync(_mockPagesResponse);
            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 pages   = await service.GetPagesAsync("PageName1");

            // Assert
            Assert.IsNotNull(pages);
            Assert.AreEqual(3, pages.Count);

            // Verify
            httpMock.VerifyAll();
        }