Exemplo n.º 1
0
 /// <summary>
 /// Instantiate a new GitHub Activities API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public ActivitiesClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Events   = new EventsClient(apiConnection);
     Starring = new StarredClient(apiConnection);
     Watching = new WatchedClient(apiConnection);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Checks for repository stats which are not directly available in
        /// </summary>
        /// <returns></returns>
        private async Task CheckRepositoryStats()
        {
            //Check if repository is starred
            var starredClient = new StarredClient(new ApiConnection(GithubClientService.GetAuthorizedGithubClient().Connection));

            IsRepositoryStarred = await starredClient.CheckStarred(Repository.Owner.Login.ToString(), Repository.Name);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Instantiate a new GitHub Activities API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public ActivitiesClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Events = new EventsClient(apiConnection);
     Starring = new StarredClient(apiConnection);
     Watching = new WatchedClient(apiConnection);
 }
Exemplo n.º 4
0
 public async Task <bool> UnStarRepository(string repositoryOwner, string repositoryName, GitHubClient authorizedGitHubClient)
 {
     if (_StarredClient == null)
     {
         _StarredClient = new StarredClient(new ApiConnection(authorizedGitHubClient.Connection));
     }
     return(await _StarredClient.RemoveStarFromRepo(repositoryOwner, repositoryName));
 }
Exemplo n.º 5
0
 public async Task <IEnumerable <User> > GetStargazersForRepository(long repositoryId, GitHubClient gitHubClient)
 {
     if (_StarredClient == null)
     {
         _StarredClient = new StarredClient(new ApiConnection(gitHubClient.Connection));
     }
     return(await _StarredClient.GetAllStargazers(repositoryId));
 }
 /// <summary>
 /// Instantiate a new GitHub Activities API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public ActivitiesClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Events        = new EventsClient(apiConnection);
     Starring      = new StarredClient(apiConnection);
     Watching      = new WatchedClient(apiConnection);
     Feeds         = new FeedsClient(apiConnection);
     Notifications = new NotificationsClient(apiConnection);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Instantiate a new GitHub Activities API client.
 /// </summary>
 /// <param name="apiConnection">An API connection</param>
 public ActivitiesClient(IApiConnection apiConnection)
     : base(apiConnection)
 {
     Events = new EventsClient(apiConnection);
     Starring = new StarredClient(apiConnection);
     Watching = new WatchedClient(apiConnection);
     Feeds = new FeedsClient(apiConnection);
     Notifications = new NotificationsClient(apiConnection);
 }
Exemplo n.º 8
0
            public async Task RequestsCorrectUrl()
            {
                var endpoint   = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                await client.GetAllForCurrent();

                connection.Received().GetAll <Repository>(endpoint, Args.ApiOptions);
            }
Exemplo n.º 9
0
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var endpoint   = new Uri("repositories/1/stargazers", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                await client.GetAllStargazers(1);

                connection.Received().GetAll <User>(endpoint, Args.ApiOptions);
            }
Exemplo n.º 10
0
            public async Task RequestsCorrectUrl()
            {
                var endpoint = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                await client.GetAllForCurrent();

                connection.Received().GetAll<Repository>(endpoint, Args.ApiOptions);
            }
Exemplo n.º 11
0
            public async Task RequestsCorrectUrlWithTimestamps()
            {
                var endpoint   = new Uri("repos/fake/repo/stargazers", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                await client.GetAllStargazersWithTimestamps("fake", "repo");

                connection.Received().GetAll <UserStar>(endpoint, null, "application/vnd.github.v3.star+json", Args.ApiOptions);
            }
Exemplo n.º 12
0
            public async Task RequestsCorrectUrlWithTimestamps()
            {
                var endpoint   = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                await client.GetAllForCurrentWithTimestamps();

                connection.Received().GetAll <RepositoryStar>(endpoint, null, "application/vnd.github.v3.star+json", Args.ApiOptions);
            }
Exemplo n.º 13
0
            public void RequestsCorrectUrl()
            {
                var endpoint   = new Uri("users/banana/starred", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                client.GetAllForUser("banana");

                connection.Received().GetAll <Repository>(endpoint);
            }
Exemplo n.º 14
0
            public void RequestsCorrectUrl()
            {
                var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                client.GetAllStargazers("fight", "club");

                connection.Received().GetAll<User>(endpoint);
            }
Exemplo n.º 15
0
            public void RequestsCorrectUrl()
            {
                var endpoint = new Uri("users/banana/starred", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                client.GetAllForUser("banana");

                connection.Received().GetAll<Repository>(endpoint);
            }
Exemplo n.º 16
0
            public void RequestsCorrectUrl()
            {
                var endpoint   = new Uri("repos/fight/club/stargazers", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                client.GetAllStargazers("fight", "club");

                connection.Received().GetAll <User>(endpoint);
            }
Exemplo n.º 17
0
            public async Task RequestsCorrectUrlParametrized()
            {
                var endpoint = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                var request = new StarredRequest { SortDirection = SortDirection.Ascending };

                await client.GetAllForCurrent(request);

                connection.Received().GetAll<Repository>(endpoint, Arg.Is<IDictionary<string, string>>(d => d.Count == 2 && d["direction"] == "asc"),
                    Args.ApiOptions);
            }
Exemplo n.º 18
0
            public async Task RequestsCorrectUrlParametrized()
            {
                var endpoint   = new Uri("users/banana/starred", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                var starredRequest = new StarredRequest {
                    SortDirection = SortDirection.Ascending
                };

                await client.GetAllForUser("banana", starredRequest);

                connection.Received().GetAll <Repository>(endpoint, Arg.Is <IDictionary <string, string> >(d => d.Count == 2 && d["direction"] == "asc"), Args.ApiOptions);
            }
Exemplo n.º 19
0
            public async Task RequestsCorrectUrlWithTimestampsParametrized()
            {
                var endpoint   = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                var request = new StarredRequest {
                    SortDirection = SortDirection.Ascending
                };

                await client.GetAllForCurrentWithTimestamps(request);

                connection.Received().GetAll <RepositoryStar>(endpoint, Arg.Is <IDictionary <string, string> >(d => d.Count == 2 && d["direction"] == "asc"),
                                                              "application/vnd.github.v3.star+json", Args.ApiOptions);
            }
Exemplo n.º 20
0
            public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected)
            {
                var response = Task.Factory.StartNew<IResponse<object>>(() =>
                    new ApiResponse<object> { StatusCode = status });
                var connection = Substitute.For<IConnection>();
                connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "user/starred/yes/no"), null, null)
                    .Returns(response);
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);

                var client = new StarredClient(apiConnection);
                var result = await client.CheckStarred("yes", "no");

                Assert.Equal(expected, result);
            }
Exemplo n.º 21
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new StarredClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser(null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser(null, ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser("banana", (ApiOptions)null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser(null, new StarredRequest()));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser("banana", (StarredRequest)null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser(null, new StarredRequest(), ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser("banana", null, ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser("banana", new StarredRequest(), null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null, ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", (ApiOptions)null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null, new StarredRequest()));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", (StarredRequest)null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null, new StarredRequest(), ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", null, ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", new StarredRequest(), null));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUser(""));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUser("", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUser("", new StarredRequest(), ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUserWithTimestamps(""));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUserWithTimestamps("", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUserWithTimestamps("", new StarredRequest(), ApiOptions.None));
            }
Exemplo n.º 22
0
            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var endpoint = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize = 1
                };

                await client.GetAllForCurrent(options);

                connection.Received().GetAll<Repository>(endpoint, options);
            }
Exemplo n.º 23
0
            public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected)
            {
                var response = Task.Factory.StartNew <IApiResponse <object> >(() =>
                                                                              new ApiResponse <object>(new Response(status, null, new Dictionary <string, string>(), "application/json")));
                var connection = Substitute.For <IConnection>();

                connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "user/starred/yes/no"), null, null)
                .Returns(response);
                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Connection.Returns(connection);

                var client = new StarredClient(apiConnection);
                var result = await client.CheckStarred("yes", "no");

                Assert.Equal(expected, result);
            }
Exemplo n.º 24
0
            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var endpoint   = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize  = 1
                };

                await client.GetAllForCurrent(options);

                connection.Received().GetAll <Repository>(endpoint, options);
            }
            public void RequestsCorrectUrlWithTimestampsWithApiOptions()
            {
                var endpoint   = new Uri("repos/fight/club/stargazers", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize  = 1
                };

                client.GetAllStargazersWithTimestamps("fight", "club", options);

                connection.Received().GetAll <UserStar>(endpoint, null, "application/vnd.github.v3.star+json", options);
            }
Exemplo n.º 26
0
            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var endpoint   = new Uri("repos/fight/club/stargazers", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize  = 1
                };

                await client.GetAllStargazers("fight", "club", options);

                connection.Received().GetAll <User>(endpoint, options);
            }
Exemplo n.º 27
0
            public async Task RequestsCorrectUrlWithTimestampsWithApiOptionsWithRepositoryId()
            {
                var endpoint   = new Uri("repositories/1/stargazers", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize  = 1
                };

                await client.GetAllStargazersWithTimestamps(1, options);

                connection.Received().GetAll <UserStar>(endpoint, null, "application/vnd.github.v3.star+json", options);
            }
Exemplo n.º 28
0
            public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected)
            {
                var responseTask = TestSetup.GetApiResponse(status);

                var connection = Substitute.For <IConnection>();

                connection.Put <object>(Arg.Is <Uri>(u => u.ToString() == "user/starred/yes/no"), Args.Object, Args.String)
                .Returns(responseTask);

                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Connection.Returns(connection);

                var client = new StarredClient(apiConnection);
                var result = await client.StarRepo("yes", "no");

                Assert.Equal(expected, result);
            }
Exemplo n.º 29
0
            public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected)
            {
                var response = Task.Factory.StartNew <HttpStatusCode>(() => status);

                var connection = Substitute.For <IConnection>();

                connection.Delete(Arg.Is <Uri>(u => u.ToString() == "user/starred/yes/no"))
                .Returns(response);

                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Connection.Returns(connection);

                var client = new StarredClient(apiConnection);
                var result = await client.RemoveStarFromRepo("yes", "no");

                Assert.Equal(expected, result);
            }
Exemplo n.º 30
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new StarredClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazers(null, "club"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazers("fight", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazers(null, "club", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazers("fight", null, ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazers("fight", "club", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazersWithTimestamps(null, "club"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazersWithTimestamps("fight", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazersWithTimestamps(null, "club", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazersWithTimestamps("fight", null, ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazersWithTimestamps("fight", "club", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazers(1, null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllStargazersWithTimestamps(1, null));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllStargazers("", "club"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllStargazers("fight", ""));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllStargazers("", "club", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllStargazers("fight", "", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllStargazersWithTimestamps("", "club"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllStargazersWithTimestamps("fight", ""));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllStargazersWithTimestamps("", "club", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllStargazersWithTimestamps("fight", "", ApiOptions.None));
            }
Exemplo n.º 31
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new StarredClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrent((ApiOptions)null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrent((StarredRequest)null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps((ApiOptions)null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps((StarredRequest)null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrent(null, new ApiOptions()));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrent(new StarredRequest(), null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps(null, new ApiOptions()));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps(new StarredRequest(), null));
            }
Exemplo n.º 32
0
            public async Task RequestsCorrectUrlParametrizedWithApiOptions()
            {
                var endpoint   = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize  = 1
                };

                var request = new StarredRequest {
                    SortDirection = SortDirection.Ascending
                };

                await client.GetAllForCurrent(request, options);

                connection.Received().GetAll <Repository>(endpoint, Arg.Is <IDictionary <string, string> >(d => d.Count == 2 && d["direction"] == "asc"), options);
            }
Exemplo n.º 33
0
            public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected)
            {
                var response = Task.Factory.StartNew <IResponse <object> >(() =>
                                                                           new ApiResponse <object> {
                    StatusCode = status
                });

                var connection = Substitute.For <IConnection>();

                connection.PutAsync <object>(Arg.Is <Uri>(u => u.ToString() == "user/starred/yes/no"),
                                             Args.Object, Args.String).Returns(response);

                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.Connection.Returns(connection);

                var client = new StarredClient(apiConnection);
                var result = await client.StarRepo("yes", "no");

                Assert.Equal(expected, result);
            }
Exemplo n.º 34
0
            public async Task RequestsCorrectUrlWithTimestampsParametrizedWithApiOptions()
            {
                var endpoint   = new Uri("users/banana/starred", UriKind.Relative);
                var connection = Substitute.For <IApiConnection>();
                var client     = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize  = 1
                };

                var starredRequest = new StarredRequest {
                    SortDirection = SortDirection.Ascending
                };

                await client.GetAllForUserWithTimestamps("banana", starredRequest, options);

                connection.Received().GetAll <RepositoryStar>(endpoint, Arg.Is <IDictionary <string, string> >(d => d.Count == 2 && d["direction"] == "asc"),
                                                              "application/vnd.github.v3.star+json", options);
            }
Exemplo n.º 35
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new StarredClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent((ApiOptions)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent((StarredRequest)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps((ApiOptions)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps((StarredRequest)null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent(null, new ApiOptions()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent(new StarredRequest(), null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps(null, new ApiOptions()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps(new StarredRequest(), null));
            }
Exemplo n.º 36
0
            public async Task RequestsCorrectUrlWithTimestamps()
            {
                var endpoint = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                await client.GetAllForCurrentWithTimestamps();

                connection.Received().GetAll<RepositoryStar>(endpoint, null, "application/vnd.github.v3.star+json", Args.ApiOptions);
            }
Exemplo n.º 37
0
            public async Task RequestsCorrectUrlWithTimestamps()
            {
                var endpoint = new Uri("repos/fake/repo/stargazers", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                await client.GetAllStargazersWithTimestamps("fake", "repo");

                connection.Received().GetAll<UserStar>(endpoint, null, "application/vnd.github.v3.star+json", Args.ApiOptions);
            }
Exemplo n.º 38
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new StarredClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null, ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("banana", (ApiOptions)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null, new StarredRequest()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("banana", (StarredRequest)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null, new StarredRequest(), ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("banana", null, ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("banana", new StarredRequest(), null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null, ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", (ApiOptions)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null, new StarredRequest()));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", (StarredRequest)null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null, new StarredRequest(), ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", null, ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", new StarredRequest(), null));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser(""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("", new StarredRequest(), ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUserWithTimestamps(""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUserWithTimestamps("", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUserWithTimestamps("", new StarredRequest(), ApiOptions.None));
            }
Exemplo n.º 39
0
            public async Task EnsuresNonNullArguments()
            {
                var client = new StarredClient(Substitute.For<IApiConnection>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazers(null, "club"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazers("fight", null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazers(null, "club", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazers("fight", null, ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazers("fight", "club", null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps(null, "club"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps("fight", null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps(null, "club", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps("fight", null, ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps("fight", "club", null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazers(1, null));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps(1, null));

                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllStargazers("", "club"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllStargazers("fight", ""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllStargazers("", "club", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllStargazers("fight", "", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllStargazersWithTimestamps("", "club"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllStargazersWithTimestamps("fight", ""));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllStargazersWithTimestamps("", "club", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllStargazersWithTimestamps("fight", "", ApiOptions.None));
            }
Exemplo n.º 40
0
            public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected)
            {
                var response = Task.Factory.StartNew<IApiResponse<object>>(() =>
                    new ApiResponse<object>(new Response(status, null, new Dictionary<string, string>(), "application/json")));

                var connection = Substitute.For<IConnection>();
                connection.Put<object>(Arg.Is<Uri>(u => u.ToString() == "user/starred/yes/no"),
                    Args.Object, Args.String).Returns(response);

                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);

                var client = new StarredClient(apiConnection);
                var result = await client.StarRepo("yes", "no");

                Assert.Equal(expected, result);
            }
Exemplo n.º 41
0
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var endpoint = new Uri("repositories/1/stargazers", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                await client.GetAllStargazers(1);

                connection.Received().GetAll<User>(endpoint, Args.ApiOptions);
            }
Exemplo n.º 42
0
            public async Task RequestsCorrectUrlWithTimestampsWithApiOptionsWithRepositoryId()
            {
                var endpoint = new Uri("repositories/1/stargazers", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize = 1
                };

                await client.GetAllStargazersWithTimestamps(1, options);

                connection.Received().GetAll<UserStar>(endpoint, null, "application/vnd.github.v3.star+json", options);
            }
Exemplo n.º 43
0
            public async Task RequestsCorrectUrlWithTimestampsParametrizedWithApiOptions()
            {
                var endpoint = new Uri("users/banana/starred", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize = 1
                };

                var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending };

                await client.GetAllForUserWithTimestamps("banana", starredRequest, options);

                connection.Received().GetAll<RepositoryStar>(endpoint, Arg.Is<IDictionary<string, string>>(d => d.Count == 2 && d["direction"] == "asc"),
                    "application/vnd.github.v3.star+json", options);
            }
Exemplo n.º 44
0
            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    StartPage = 1,
                    PageSize = 1
                };

                await client.GetAllStargazers("fight", "club", options);

                connection.Received().GetAll<User>(endpoint, options);
            }
Exemplo n.º 45
0
            public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected)
            {
                var response = Task.Factory.StartNew(() => status);

                var connection = Substitute.For<IConnection>();
                connection.Delete(Arg.Is<Uri>(u => u.ToString() == "user/starred/yes/no"))
                    .Returns(response);

                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.Connection.Returns(connection);

                var client = new StarredClient(apiConnection);
                var result = await client.RemoveStarFromRepo("yes", "no");

                Assert.Equal(expected, result);
            }