IsFollowingAsync() public method

public IsFollowingAsync ( string user, Action callback, Action onError ) : GitHubRequestAsyncHandle
user string
callback Action
onError Action
return GitHubRequestAsyncHandle
コード例 #1
0
ファイル: UserServiceTests.cs プロジェクト: ninjaAB/NGitHub
        public void IsFollowingAsync_ShouldCallbackWithFalse_WhenResponseIsNotFound()
        {
            var mockResponse = new Mock<IGitHubResponse<object>>(MockBehavior.Strict);
            var mockClient = new Mock<IGitHubClient>(MockBehavior.Strict);
            mockResponse.Setup(r => r.ErrorException)
                        .Returns(new Exception());
            mockResponse.Setup(r => r.StatusCode)
                        .Returns(HttpStatusCode.NotFound);
            mockClient.Setup(c => c.CallApiAsync<object>(It.IsAny<GitHubRequest>(),
                                                         It.IsAny<Action<IGitHubResponse<object>>>(),
                                                         It.IsAny<Action<GitHubException>>()))
                      .Callback<GitHubRequest,
                                Action<IGitHubResponse<object>>,
                                Action<GitHubException>>((req, c, e) => {
                                    e(new GitHubException(mockResponse.Object, ErrorType.ResourceNotFound));
                                })
                      .Returns(TestHelpers.CreateTestHandle());
            var userService = new UserService(mockClient.Object);

            var isFollowing = true;
            userService.IsFollowingAsync("akilb",
                                         fl => isFollowing = fl,
                                         e => { });

            Assert.IsFalse(isFollowing);
        }
コード例 #2
0
ファイル: UserServiceTests.cs プロジェクト: ninjaAB/NGitHub
        public void IsFollowingAsync_ShouldCallbackWithError_WhenResponseIsSomeRandomError()
        {
            var mockResponse = new Mock<IGitHubResponse<object>>(MockBehavior.Strict);
            var mockClient = new Mock<IGitHubClient>(MockBehavior.Strict);
            mockResponse.Setup(r => r.ErrorException)
                        .Returns(new Exception());
            mockResponse.Setup(r => r.StatusCode)
                        .Returns(HttpStatusCode.Forbidden);
            var expectedException = new GitHubException(mockResponse.Object,
                                                        ErrorType.Unauthorized);
            mockClient.Setup(c => c.CallApiAsync<object>(It.IsAny<GitHubRequest>(),
                                                         It.IsAny<Action<IGitHubResponse<object>>>(),
                                                         It.IsAny<Action<GitHubException>>()))
                      .Callback<GitHubRequest,
                                Action<IGitHubResponse<object>>,
                                Action<GitHubException>>((req, c, e) => {
                                    e(expectedException);
                                })
                      .Returns(TestHelpers.CreateTestHandle());
            var userService = new UserService(mockClient.Object);

            GitHubException actualException = null;
            userService.IsFollowingAsync("akilb",
                                         c => { },
                                         e => actualException = e);

            Assert.AreSame(expectedException, actualException);
        }