From 85a87dade3fa6ac5f3d81ef66eb1fd6a88a6a228 Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Thu, 2 Jun 2016 17:15:35 +0700 Subject: [PATCH] Add ApiOptions overloads to methods on I(Observable)StarredClient (#1336) --- .../Clients/IObservableStarredClient.cs | 105 +++ .../Clients/ObservableStarredClient.cs | 187 ++++- .../Helpers/ConnectionExtensions.cs | 9 + .../Clients/StarredClientTests.cs | 726 +++++++++++++++++- Octokit.Tests/Clients/StarredClientTests.cs | 383 ++++++++- .../Reactive/ObservableStarredClientTests.cs | 457 ++++++++++- Octokit/Clients/IStarredClient.cs | 109 +++ Octokit/Clients/StarredClient.cs | 191 ++++- 8 files changed, 2101 insertions(+), 66 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableStarredClient.cs b/Octokit.Reactive/Clients/IObservableStarredClient.cs index a1c5c9f6..8938e244 100644 --- a/Octokit.Reactive/Clients/IObservableStarredClient.cs +++ b/Octokit.Reactive/Clients/IObservableStarredClient.cs @@ -13,6 +13,16 @@ namespace Octokit.Reactive /// A of s starring the passed repository IObservable GetAllStargazers(string owner, string name); + /// + /// Retrieves all of the stargazers for the passed repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown if the client is not authenticated + /// A of s starring the passed repository + IObservable GetAllStargazers(string owner, string name, ApiOptions options); + /// /// Retrieves all of the stargazers for the passed repository with star creation timestamps. /// @@ -22,6 +32,16 @@ namespace Octokit.Reactive /// A of s starring the passed repository with star creation timestamps. IObservable GetAllStargazersWithTimestamps(string owner, string name); + /// + /// Retrieves all of the stargazers for the passed repository with star creation timestamps. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository with star creation timestamps. + IObservable GetAllStargazersWithTimestamps(string owner, string name, ApiOptions options); + /// /// Retrieves all of the starred (ies) for the current user /// @@ -30,6 +50,15 @@ namespace Octokit.Reactive /// A of (ies) starred by the current user /// IObservable GetAllForCurrent(); + + /// + /// Retrieves all of the starred (ies) for the current user + /// + /// Thrown if the client is not authenticated + /// + /// A of (ies) starred by the current user + /// + IObservable GetAllForCurrent(ApiOptions options); /// /// Retrieves all of the starred (ies) for the current user with star creation timestamps. @@ -39,6 +68,15 @@ namespace Octokit.Reactive /// A of (ies) starred by the current authenticated user with star creation timestamps. /// IObservable GetAllForCurrentWithTimestamps(); + + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user with star creation timestamps. + /// + IObservable GetAllForCurrentWithTimestamps(ApiOptions options); /// /// Retrieves all of the starred (ies) for the current user @@ -51,6 +89,18 @@ namespace Octokit.Reactive /// IObservable GetAllForCurrent(StarredRequest request); + /// + /// Retrieves all of the starred (ies) for the current user + /// + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters + /// + IObservable GetAllForCurrent(StarredRequest request, ApiOptions options); + /// /// Retrieves all of the starred (ies) for the current user with star creation timestamps. /// @@ -62,6 +112,18 @@ namespace Octokit.Reactive /// IObservable GetAllForCurrentWithTimestamps(StarredRequest request); + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + IObservable GetAllForCurrentWithTimestamps(StarredRequest request, ApiOptions options); + /// /// Retrieves all of the (ies) starred by the specified user /// @@ -70,6 +132,15 @@ namespace Octokit.Reactive /// A starred by the specified user IObservable GetAllForUser(string user); + /// + /// Retrieves all of the (ies) starred by the specified user + /// + /// The login of the user + /// Options for changing the API response + /// Thrown if the client is not authenticated + /// A starred by the specified user + IObservable GetAllForUser(string user, ApiOptions options); + /// /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. /// @@ -80,6 +151,17 @@ namespace Octokit.Reactive /// IObservable GetAllForUserWithTimestamps(string user); + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user with star creation timestamps. + /// + IObservable GetAllForUserWithTimestamps(string user, ApiOptions options); + /// /// Retrieves all of the (ies) starred by the specified user /// @@ -89,6 +171,16 @@ namespace Octokit.Reactive /// A starred by the specified user IObservable GetAllForUser(string user, StarredRequest request); + /// + /// Retrieves all of the (ies) starred by the specified user + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated + /// A starred by the specified user + IObservable GetAllForUser(string user, StarredRequest request, ApiOptions options); + /// /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. /// @@ -101,6 +193,19 @@ namespace Octokit.Reactive /// IObservable GetAllForUserWithTimestamps(string user, StarredRequest request); + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the specified user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + IObservable GetAllForUserWithTimestamps(string user, StarredRequest request, ApiOptions options); + /// /// Check if a repository is starred by the current authenticated user /// diff --git a/Octokit.Reactive/Clients/ObservableStarredClient.cs b/Octokit.Reactive/Clients/ObservableStarredClient.cs index 9f09031f..58e59940 100644 --- a/Octokit.Reactive/Clients/ObservableStarredClient.cs +++ b/Octokit.Reactive/Clients/ObservableStarredClient.cs @@ -29,7 +29,24 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(owner, name)); + return GetAllStargazers(owner, name, ApiOptions.None); + } + + /// + /// Retrieves all of the stargazers for the passed repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown if the client is not authenticated + /// A of s starring the passed repository + public IObservable GetAllStargazers(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(owner, name), options); } /// @@ -44,7 +61,24 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(owner, name), null, AcceptHeaders.StarCreationTimestamps); + return GetAllStargazersWithTimestamps(owner, name, ApiOptions.None); + } + + /// + /// Retrieves all of the stargazers for the passed repository with star creation timestamps. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository with star creation timestamps. + public IObservable GetAllStargazersWithTimestamps(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(owner, name), null, AcceptHeaders.StarCreationTimestamps, options); } /// @@ -56,7 +90,21 @@ namespace Octokit.Reactive /// public IObservable GetAllForCurrent() { - return _connection.GetAndFlattenAllPages(ApiUrls.Starred()); + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Retrieves all of the starred (ies) for the current user + /// + /// Thrown if the client is not authenticated + /// + /// A of (ies) starred by the current user + /// + public IObservable GetAllForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), options); } /// @@ -68,7 +116,21 @@ namespace Octokit.Reactive /// public IObservable GetAllForCurrentWithTimestamps() { - return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), null, AcceptHeaders.StarCreationTimestamps); + return GetAllForCurrentWithTimestamps(ApiOptions.None); + } + + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user with star creation timestamps. + /// + public IObservable GetAllForCurrentWithTimestamps(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), null, AcceptHeaders.StarCreationTimestamps, options); } /// @@ -85,7 +147,25 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNull(request, "request"); - return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), request.ToParametersDictionary()); + return GetAllForCurrent(request, ApiOptions.None); + } + + /// + /// Retrieves all of the starred (ies) for the current user + /// + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters + /// + public IObservable GetAllForCurrent(StarredRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), request.ToParametersDictionary(), options); } /// @@ -102,7 +182,25 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNull(request, "request"); - return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps); + return GetAllForCurrentWithTimestamps(request, ApiOptions.None); + } + + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + public IObservable GetAllForCurrentWithTimestamps(StarredRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps, options); } /// @@ -115,7 +213,22 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user)); + return GetAllForUser(user, ApiOptions.None); + } + + /// + /// Retrieves all of the (ies) starred by the specified user + /// + /// The login of the user + /// Options for changing the API response + /// Thrown if the client is not authenticated + /// A starred by the specified user + public IObservable GetAllForUser(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), options); } /// @@ -130,7 +243,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), null, AcceptHeaders.StarCreationTimestamps); + return GetAllForUserWithTimestamps(user, ApiOptions.None); + } + + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user with star creation timestamps. + /// + public IObservable GetAllForUserWithTimestamps(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), null, AcceptHeaders.StarCreationTimestamps, options); } /// @@ -146,7 +276,24 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(request, "request"); - return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), request.ToParametersDictionary()); + return GetAllForUser(user, request, ApiOptions.None); + } + + /// + /// Retrieves all of the (ies) starred by the specified user + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated + /// A starred by the specified user + public IObservable GetAllForUser(string user, StarredRequest request, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), options); } /// @@ -165,7 +312,27 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(request, "request"); - return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps); + return GetAllForUserWithTimestamps(user, request, ApiOptions.None); + } + + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the specified user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + public IObservable GetAllForUserWithTimestamps(string user, StarredRequest request, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps, options); } /// diff --git a/Octokit.Reactive/Helpers/ConnectionExtensions.cs b/Octokit.Reactive/Helpers/ConnectionExtensions.cs index 5f2aec15..c60ee366 100644 --- a/Octokit.Reactive/Helpers/ConnectionExtensions.cs +++ b/Octokit.Reactive/Helpers/ConnectionExtensions.cs @@ -37,6 +37,15 @@ namespace Octokit.Reactive.Internal return GetPages(url, parameters, (pageUrl, pageParams) => connection.Get>(pageUrl, pageParams, accepts).ToObservable()); } + public static IObservable GetAndFlattenAllPages(this IConnection connection, Uri url, IDictionary parameters, string accepts, ApiOptions options) + { + return GetPagesWithOptions(url, parameters, options, (pageUrl, pageParams, o) => + { + var passingParameters = Pagination.Setup(parameters, options); + return connection.Get>(pageUrl, passingParameters, accepts).ToObservable(); + }); + } + static IObservable GetPages(Uri uri, IDictionary parameters, Func, IObservable>>> getPageFunc) { diff --git a/Octokit.Tests.Integration/Clients/StarredClientTests.cs b/Octokit.Tests.Integration/Clients/StarredClientTests.cs index e55880e8..82f8a2f3 100644 --- a/Octokit.Tests.Integration/Clients/StarredClientTests.cs +++ b/Octokit.Tests.Integration/Clients/StarredClientTests.cs @@ -1,35 +1,739 @@ using System; -using Octokit.Tests.Integration.Helpers; using System.Linq; using System.Threading.Tasks; +using Octokit.Tests.Integration.Helpers; using Xunit; namespace Octokit.Tests.Integration.Clients { - public class StarredClientTests + public class StarredClientTests : IDisposable { private readonly IGitHubClient _client; private readonly IStarredClient _fixture; + private readonly RepositoryContext _repositoryContext; public StarredClientTests() { _client = Helper.GetAuthenticatedClient(); _fixture = _client.Activity.Starring; + + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo1"); + + _repositoryContext = github.CreateRepositoryContext(new NewRepository(repoName)).Result; + + _fixture.RemoveStarFromRepo(_repositoryContext.RepositoryOwner, _repositoryContext.RepositoryName).Wait(); + _fixture.RemoveStarFromRepo("octokit", "octokit.net").Wait(); + _fixture.StarRepo(_repositoryContext.RepositoryOwner, _repositoryContext.RepositoryName).Wait(); + _fixture.StarRepo("octokit", "octokit.net").Wait(); } [IntegrationTest] - public async Task CanCreateAndRetrieveStarsWithTimestamps() + public async Task CanGetAllForCurrent() { - using (var context = await _client.CreateRepositoryContext("public-repo")) + var repositories = await _fixture.GetAllForCurrent(); + Assert.NotEmpty(repositories); + + var repo = repositories.FirstOrDefault(repository => repository.Owner.Login == _repositoryContext.RepositoryOwner && repository.Name == _repositoryContext.RepositoryName); + Assert.NotNull(repo); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartForCurrent() + { + var options = new ApiOptions { - await _fixture.RemoveStarFromRepo(context.RepositoryOwner, context.RepositoryName); - await _fixture.StarRepo(context.RepositoryOwner, context.RepositoryName); - var currentUser = await _client.User.Current(); - var userStars = await _fixture.GetAllStargazersWithTimestamps(context.RepositoryOwner, context.RepositoryName); - var userStar = userStars.SingleOrDefault(x => x.User.Id == currentUser.Id); - Assert.NotNull(userStar); - Assert.True(DateTimeOffset.UtcNow.Subtract(userStar.StarredAt) < TimeSpan.FromMinutes(5)); + PageCount = 1, + PageSize = 1 + }; + + var repositories = await _fixture.GetAllForCurrent(options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartForCurrent() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var repositories = await _fixture.GetAllForCurrent(options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageForCurrent() + { + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllForCurrent(startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllForCurrent(skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().Id, secondPage.First().Id); + } + + [IntegrationTest] + public async Task CanGetAllForCurrentParameterized() + { + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created }; + + var repositories = await _fixture.GetAllForCurrent(starredRequest); + Assert.NotEmpty(repositories); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartForCurrentParameterized() + { + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created }; + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var repositories = await _fixture.GetAllForCurrent(starredRequest, options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartForCurrentParameterized() + { + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created }; + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var repositories = await _fixture.GetAllForCurrent(starredRequest, options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageForCurrentParameterized() + { + var starredRequestFirstPage = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created }; + var starredRequestSecondPage = new StarredRequest { SortDirection = SortDirection.Descending, SortProperty = StarredSort.Updated }; + + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllForCurrent(starredRequestFirstPage, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllForCurrent(starredRequestSecondPage, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().Id, secondPage.First().Id); + } + + [IntegrationTest] + public async Task CanGetAllForCurrentWithTimestamps() + { + var stars = await _fixture.GetAllForCurrentWithTimestamps(); + Assert.NotEmpty(stars); + + var repo = stars.FirstOrDefault(star => star.Repo.Owner.Login == _repositoryContext.RepositoryOwner && star.Repo.Name == _repositoryContext.RepositoryName); + Assert.NotNull(repo); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartForCurrentWithTimestamps() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var repositories = await _fixture.GetAllForCurrentWithTimestamps(options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartForCurrentWithTimestamps() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var repositories = await _fixture.GetAllForCurrentWithTimestamps(options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageForCurrentWithTimestamps() + { + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllForCurrentWithTimestamps(startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllForCurrentWithTimestamps(skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().Repo.Id, secondPage.First().Repo.Id); + } + + [IntegrationTest] + public async Task CanGetAllForCurrentWithTimestampsParameterized() + { + var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Descending }; + + var stars = await _fixture.GetAllForCurrentWithTimestamps(starredRequest); + Assert.NotEmpty(stars); + + var repo = stars.FirstOrDefault(star => star.Repo.Owner.Login == _repositoryContext.RepositoryOwner && star.Repo.Name == _repositoryContext.RepositoryName); + Assert.NotNull(repo); + + for (int i = 1; i < stars.Count; i++) + { + Assert.True(stars[i - 1].StarredAt >= stars[i].StarredAt); } } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartForCurrentWithTimestampsParameterized() + { + var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Descending }; + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var stars = await _fixture.GetAllForCurrentWithTimestamps(starredRequest, options); + Assert.Equal(1, stars.Count); + + for (int i = 1; i < stars.Count; i++) + { + Assert.True(stars[i - 1].StarredAt >= stars[i].StarredAt); + } + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartForCurrentWithTimestampsParameterized() + { + var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Descending }; + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var stars = await _fixture.GetAllForCurrentWithTimestamps(starredRequest, options); + Assert.Equal(1, stars.Count); + + for (int i = 1; i < stars.Count; i++) + { + Assert.True(stars[i - 1].StarredAt >= stars[i].StarredAt); + } + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageForCurrentWithTimestampsParameterized() + { + var starredRequest = new StarredRequest { SortDirection = SortDirection.Descending, SortProperty = StarredSort.Created }; + + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllForCurrentWithTimestamps(starredRequest, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllForCurrentWithTimestamps(starredRequest, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().Repo.Id, secondPage.First().Repo.Id); + + for (int i = 1; i < firstPage.Count; i++) + { + Assert.True(firstPage[i].StarredAt >= secondPage[i].StarredAt); + } + } + + [IntegrationTest] + public async Task CanGetAllForUser() + { + var repositories = await _fixture.GetAllForUser(Helper.UserName); + Assert.NotEmpty(repositories); + + var repo = repositories.FirstOrDefault(repository => repository.Owner.Login == _repositoryContext.RepositoryOwner && repository.Name == _repositoryContext.RepositoryName); + Assert.NotNull(repo); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartForUser() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var repositories = await _fixture.GetAllForUser(Helper.UserName, options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartForUser() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var repositories = await _fixture.GetAllForUser(Helper.UserName, options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageForUser() + { + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllForUser(Helper.UserName, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllForUser(Helper.UserName, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().Id, secondPage.First().Id); + } + + [IntegrationTest] + public async Task CanGetAllForUserParameterized() + { + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created }; + + var repositories = await _fixture.GetAllForUser(Helper.UserName, starredRequest); + Assert.NotEmpty(repositories); + + var repo = repositories.FirstOrDefault(repository => repository.Owner.Login == _repositoryContext.RepositoryOwner && repository.Name == _repositoryContext.RepositoryName); + Assert.NotNull(repo); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartForUserParameterized() + { + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created }; + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var repositories = await _fixture.GetAllForUser(Helper.UserName, starredRequest, options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartForUserParameterized() + { + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created }; + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var repositories = await _fixture.GetAllForUser(Helper.UserName, starredRequest, options); + Assert.Equal(1, repositories.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageForUserParameterized() + { + var starredRequestFirstPage = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created }; + var starredRequestSecondPage = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created }; + + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllForUser(Helper.UserName, starredRequestFirstPage, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllForUser(Helper.UserName, starredRequestSecondPage, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().Id, secondPage.First().Id); + } + + [IntegrationTest] + public async Task CanGetAllForUserWithTimestamps() + { + var stars = await _fixture.GetAllForUserWithTimestamps(Helper.UserName); + Assert.NotEmpty(stars); + + var star = stars.FirstOrDefault(repositoryStar => repositoryStar.Repo.Owner.Login == _repositoryContext.RepositoryOwner && repositoryStar.Repo.Name == _repositoryContext.RepositoryName); + Assert.NotNull(star); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartForUserWithTimestamps() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var stars = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, options); + Assert.Equal(1, stars.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartForUserWithTimestamps() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var stars = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, options); + Assert.Equal(1, stars.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageForUserWithTimestamps() + { + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().Repo.Id, secondPage.First().Repo.Id); + } + + [IntegrationTest] + public async Task CanGetAllForUserWithTimestampsParameterized() + { + var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Descending }; + + var stars = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, starredRequest); + Assert.NotEmpty(stars); + + var repo = stars.FirstOrDefault(repository => repository.Repo.Owner.Login == _repositoryContext.RepositoryOwner && repository.Repo.Name == _repositoryContext.RepositoryName); + Assert.NotNull(repo); + + for (int i = 1; i < stars.Count; i++) + { + Assert.True(stars[i - 1].StarredAt >= stars[i].StarredAt); + } + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartForUserWithTimestampsParameterized() + { + var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Descending }; + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var stars = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, starredRequest, options); + Assert.Equal(1, stars.Count); + + for (int i = 1; i < stars.Count; i++) + { + Assert.True(stars[i - 1].StarredAt >= stars[i].StarredAt); + } + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartForUserWithTimestampsParameterized() + { + var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Ascending }; + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var stars = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, starredRequest, options); + Assert.Equal(1, stars.Count); + + for (int i = 1; i < stars.Count; i++) + { + Assert.True(stars[i - 1].StarredAt >= stars[i].StarredAt); + } + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageForUserWithTimestampsParameterized() + { + var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Descending }; + + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, starredRequest, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, starredRequest, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().Repo.Id, secondPage.First().Repo.Id); + + for (int i = 0; i < firstPage.Count; i++) + { + Assert.True(firstPage[i].StarredAt >= secondPage[i].StarredAt); + } + } + + [IntegrationTest] + public async Task CanGetAllStargazers() + { + var users = await _fixture.GetAllStargazers(_repositoryContext.RepositoryOwner, _repositoryContext.RepositoryName); + Assert.NotEmpty(users); + + var user = users.FirstOrDefault(u => u.Login == Helper.UserName); + Assert.NotNull(user); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartAllStargazers() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var users = await _fixture.GetAllStargazers("octokit", "octokit.net", options); + Assert.Equal(1, users.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartAllStargazers() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var users = await _fixture.GetAllStargazers("octokit", "octokit.net", options); + Assert.Equal(1, users.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageAllStargazers() + { + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllStargazers("octokit", "octokit.net", startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllStargazers("octokit", "octokit.net", skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().Id, secondPage.First().Id); + } + + [IntegrationTest] + public async Task CanGetAllStargazersWithTimestamps() + { + var users = await _fixture.GetAllStargazersWithTimestamps(_repositoryContext.RepositoryOwner, _repositoryContext.RepositoryName); + Assert.NotEmpty(users); + + var userStar = users.FirstOrDefault(star => star.User.Login == _repositoryContext.RepositoryOwner); + Assert.NotNull(userStar); + + Assert.True(DateTimeOffset.UtcNow.Subtract(userStar.StarredAt) < TimeSpan.FromMinutes(5)); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartAllStargazersWithTimestamps() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var userStars = await _fixture.GetAllStargazersWithTimestamps("octokit", "octokit.net", options); + Assert.Equal(1, userStars.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartAllStargazersWithTimestamps() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 2 + }; + + var userStars = await _fixture.GetAllStargazersWithTimestamps("octokit", "octokit.net", options); + Assert.Equal(1, userStars.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoriesBasedOnStartPageAllStargazersWithTimestamps() + { + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var firstPage = await _fixture.GetAllStargazersWithTimestamps("octokit", "octokit.net", startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _fixture.GetAllStargazersWithTimestamps("octokit", "octokit.net", skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage.First().StarredAt, secondPage.First().StarredAt); + } + + public void Dispose() + { + _repositoryContext.Dispose(); + } } } diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index e0543bad..9793dcbd 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -23,30 +23,323 @@ namespace Octokit.Tests.Clients public class TheGetAllForCurrentMethod { [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var endpoint = new Uri("user/starred", UriKind.Relative); var connection = Substitute.For(); var client = new StarredClient(connection); - client.GetAllForCurrent(); + await client.GetAllForCurrent(); - connection.Received().GetAll(endpoint); + connection.Received().GetAll(endpoint, Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForCurrent(options); + + connection.Received().GetAll(endpoint, options); + } + + [Fact] + public async Task RequestsCorrectUrlParametrized() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var request = new StarredRequest { SortDirection = SortDirection.Ascending }; + + await client.GetAllForCurrent(request); + + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlParametrizedWithApiOptions() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + 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(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), options); + } + + [Fact] + public async Task RequestsCorrectUrlWithTimestamps() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + await client.GetAllForCurrentWithTimestamps(); + + connection.Received().GetAll(endpoint, null, "application/vnd.github.v3.star+json", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithTimestampsWithApiOptions() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForCurrentWithTimestamps(options); + + connection.Received().GetAll(endpoint, null, "application/vnd.github.v3.star+json", options); + } + + [Fact] + public async Task RequestsCorrectUrlWithTimestampsParametrized() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var request = new StarredRequest { SortDirection = SortDirection.Ascending }; + + await client.GetAllForCurrentWithTimestamps(request); + + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), + "application/vnd.github.v3.star+json", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithTimestampsParametrizedWithApiOptions() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + var request = new StarredRequest { SortDirection = SortDirection.Ascending }; + + await client.GetAllForCurrentWithTimestamps(request, options); + + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), + "application/vnd.github.v3.star+json", options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new StarredClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetAllForCurrent((ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAllForCurrent((StarredRequest)null)); + await Assert.ThrowsAsync(() => client.GetAllForCurrentWithTimestamps((ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAllForCurrentWithTimestamps((StarredRequest)null)); + + await Assert.ThrowsAsync(() => client.GetAllForCurrent(null, new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAllForCurrent(new StarredRequest(), null)); + await Assert.ThrowsAsync(() => client.GetAllForCurrentWithTimestamps(null, new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAllForCurrentWithTimestamps(new StarredRequest(), null)); } } public class TheGetAllForUserMethod { [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var endpoint = new Uri("users/banana/starred", UriKind.Relative); var connection = Substitute.For(); var client = new StarredClient(connection); - client.GetAllForUser("banana"); + await client.GetAllForUser("banana"); - connection.Received().GetAll(endpoint); + connection.Received().GetAll(endpoint, Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForUser("banana", options); + + connection.Received().GetAll(endpoint, options); + } + + [Fact] + public async Task RequestsCorrectUrlParametrized() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending }; + + await client.GetAllForUser("banana", starredRequest); + + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlParametrizedWithApiOptions() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending }; + + await client.GetAllForUser("banana", starredRequest, options); + + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), options); + } + + [Fact] + public async Task RequestsCorrectUrlWithTimestamps() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + await client.GetAllForUserWithTimestamps("banana"); + + connection.Received().GetAll(endpoint, null, + "application/vnd.github.v3.star+json", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithTimestampsWithApiOptions() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForUserWithTimestamps("banana", options); + + connection.Received().GetAll(endpoint, null, "application/vnd.github.v3.star+json", options); + } + + [Fact] + public async Task RequestsCorrectUrlWithTimestampsParametrized() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending }; + + await client.GetAllForUserWithTimestamps("banana", starredRequest); + + connection.Received().GetAll(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), + "application/vnd.github.v3.star+json", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithTimestampsParametrizedWithApiOptions() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + 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(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), + "application/vnd.github.v3.star+json", options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new StarredClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetAllForUser(null)); + await Assert.ThrowsAsync(() => client.GetAllForUser(null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUser("banana", (ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAllForUser(null, new StarredRequest())); + await Assert.ThrowsAsync(() => client.GetAllForUser("banana", (StarredRequest)null)); + await Assert.ThrowsAsync(() => client.GetAllForUser(null, new StarredRequest(), ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUser("banana", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUser("banana", new StarredRequest(), null)); + + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps(null)); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps(null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps("banana", (ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps(null, new StarredRequest())); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps("banana", (StarredRequest)null)); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps(null, new StarredRequest(), ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps("banana", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps("banana", new StarredRequest(), null)); + + await Assert.ThrowsAsync(() => client.GetAllForUser("")); + await Assert.ThrowsAsync(() => client.GetAllForUser("", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUser("", new StarredRequest(), ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps("")); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps("", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUserWithTimestamps("", new StarredRequest(), ApiOptions.None)); } } @@ -61,7 +354,83 @@ namespace Octokit.Tests.Clients client.GetAllStargazers("fight", "club"); - connection.Received().GetAll(endpoint); + connection.Received().GetAll(endpoint, Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllStargazers("fight", "club", options); + + connection.Received().GetAll(endpoint, options); + } + + [Fact] + public void RequestsCorrectUrlWithTimestamps() + { + var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + client.GetAllStargazersWithTimestamps("fight", "club"); + + connection.Received().GetAll(endpoint, null, "application/vnd.github.v3.star+json", Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithTimestampsWithApiOptions() + { + var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative); + var connection = Substitute.For(); + var client = new StarredClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllStargazersWithTimestamps("fight", "club", options); + + connection.Received().GetAll(endpoint, null, "application/vnd.github.v3.star+json", options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new StarredClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetAllStargazers(null, "club")); + await Assert.ThrowsAsync(() => client.GetAllStargazers("fight", null)); + await Assert.ThrowsAsync(() => client.GetAllStargazers(null, "club", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllStargazers("fight", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllStargazers("fight", "club", null)); + await Assert.ThrowsAsync(() => client.GetAllStargazersWithTimestamps(null, "club")); + await Assert.ThrowsAsync(() => client.GetAllStargazersWithTimestamps("fight", null)); + await Assert.ThrowsAsync(() => client.GetAllStargazersWithTimestamps(null, "club", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllStargazersWithTimestamps("fight", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllStargazersWithTimestamps("fight", "club", null)); + + await Assert.ThrowsAsync(() => client.GetAllStargazers("", "club")); + await Assert.ThrowsAsync(() => client.GetAllStargazers("fight", "")); + await Assert.ThrowsAsync(() => client.GetAllStargazers("", "club", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllStargazers("fight", "", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllStargazersWithTimestamps("", "club")); + await Assert.ThrowsAsync(() => client.GetAllStargazersWithTimestamps("fight", "")); + await Assert.ThrowsAsync(() => client.GetAllStargazersWithTimestamps("", "club", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllStargazersWithTimestamps("fight", "", ApiOptions.None)); } } diff --git a/Octokit.Tests/Reactive/ObservableStarredClientTests.cs b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs index c6924dd6..8d2843fa 100644 --- a/Octokit.Tests/Reactive/ObservableStarredClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs @@ -22,62 +22,463 @@ namespace Octokit.Tests.Reactive public class TheGetAllStargazersMethod { [Fact] - public async Task EnsuresArguments() - { - var client = new ObservableStarredClient(Substitute.For()); - - await Assert.ThrowsAsync(() => client.GetAllStargazers(null, "name").ToTask()); - await Assert.ThrowsAsync(() => client.GetAllStargazers("owner", null).ToTask()); - } - - [Fact] - public void GetsStargazersFromClient() + public void RequestsCorrectUrl() { + var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative); var connection = Substitute.For(); var gitHubClient = Substitute.For(); gitHubClient.Connection.Returns(connection); var client = new ObservableStarredClient(gitHubClient); - client.GetAllStargazers("jugglingnutcase", "katiejamie"); - connection.Received().Get>(ApiUrls.Stargazers("jugglingnutcase", "katiejamie"), null, null); + client.GetAllStargazers("fight", "club"); + + connection.Received().Get>(endpoint, Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllStargazers("fight", "club", options); + + connection.Received().Get>(endpoint, Arg.Is>(d => d.Count == 2), null); + } + + [Fact] + public void RequestsCorrectUrlWithTimestamps() + { + var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + client.GetAllStargazersWithTimestamps("fight", "club"); + + connection.Received().Get>(endpoint, Args.EmptyDictionary, "application/vnd.github.v3.star+json"); + } + + [Fact] + public void RequestsCorrectUrlWithTimestampsWithApiOptions() + { + var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllStargazersWithTimestamps("fight", "club", options); + + connection.Received().Get>(endpoint, Arg.Is>(d => d.Count == 2), "application/vnd.github.v3.star+json"); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableStarredClient(Substitute.For()); + + Assert.Throws(() => client.GetAllStargazers(null, "club")); + Assert.Throws(() => client.GetAllStargazers("fight", null)); + Assert.Throws(() => client.GetAllStargazers(null, "club", ApiOptions.None)); + Assert.Throws(() => client.GetAllStargazers("fight", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllStargazers("fight", "club", null)); + Assert.Throws(() => client.GetAllStargazersWithTimestamps(null, "club")); + Assert.Throws(() => client.GetAllStargazersWithTimestamps("fight", null)); + Assert.Throws(() => client.GetAllStargazersWithTimestamps(null, "club", ApiOptions.None)); + Assert.Throws(() => client.GetAllStargazersWithTimestamps("fight", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllStargazersWithTimestamps("fight", "club", null)); + + Assert.Throws(() => client.GetAllStargazers("", "club")); + Assert.Throws(() => client.GetAllStargazers("fight", "")); + Assert.Throws(() => client.GetAllStargazers("", "club", ApiOptions.None)); + Assert.Throws(() => client.GetAllStargazers("fight", "", ApiOptions.None)); + Assert.Throws(() => client.GetAllStargazersWithTimestamps("", "club")); + Assert.Throws(() => client.GetAllStargazersWithTimestamps("fight", "")); + Assert.Throws(() => client.GetAllStargazersWithTimestamps("", "club", ApiOptions.None)); + Assert.Throws(() => client.GetAllStargazersWithTimestamps("fight", "", ApiOptions.None)); } } public class TheGetAllForCurrentMethod { [Fact] - public void GetsStarsForCurrent() + public void RequestsCorrectUrl() { + var endpoint = new Uri("user/starred", UriKind.Relative); var connection = Substitute.For(); var gitHubClient = Substitute.For(); gitHubClient.Connection.Returns(connection); var client = new ObservableStarredClient(gitHubClient); client.GetAllForCurrent(); - connection.Received().Get>(ApiUrls.Starred(), null, null); + + connection.Received().Get>(endpoint, Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllForCurrent(options); + + connection.Received().Get>(endpoint, Arg.Is>(d => d.Count == 2 && d["per_page"] == "1" && d["page"] == "1"), null); + } + + [Fact] + public void RequestsCorrectUrlParametrized() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var request = new StarredRequest { SortDirection = SortDirection.Ascending }; + + client.GetAllForCurrent(request); + + connection.Received().Get>(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), + null); + } + + [Fact] + public void RequestsCorrectUrlParametrizedWithApiOptions() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + var request = new StarredRequest { SortDirection = SortDirection.Ascending }; + + client.GetAllForCurrent(request, options); + + connection.Received().Get>(endpoint, + Arg.Is>(d => d.Count == 4 && d["direction"] == "asc" && d["per_page"] == "1" && d["page"] == "1"), null); + } + + [Fact] + public void RequestsCorrectUrlWithTimestamps() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + client.GetAllForCurrentWithTimestamps(); + + connection.Received().Get>(endpoint, Args.EmptyDictionary, "application/vnd.github.v3.star+json"); + } + + [Fact] + public void RequestsCorrectUrlWithTimestampsWithApiOptions() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllForCurrentWithTimestamps(options); + + connection.Received().Get>(endpoint, + Arg.Is>(d => d.Count == 2 && d["per_page"] == "1" && d["page"] == "1"), + "application/vnd.github.v3.star+json"); + } + + [Fact] + public void RequestsCorrectUrlWithTimestampsParametrized() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var request = new StarredRequest { SortDirection = SortDirection.Ascending }; + + client.GetAllForCurrentWithTimestamps(request); + + connection.Received().Get>(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), + "application/vnd.github.v3.star+json"); + } + + [Fact] + public void RequestsCorrectUrlWithTimestampsParametrizedWithApiOptions() + { + var endpoint = new Uri("user/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + var request = new StarredRequest { SortDirection = SortDirection.Ascending }; + + client.GetAllForCurrentWithTimestamps(request, options); + + connection.Received().Get>(endpoint, + Arg.Is>(d => d.Count == 4 && d["direction"] == "asc" && d["per_page"] == "1" && d["page"] == "1"), + "application/vnd.github.v3.star+json"); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableStarredClient(Substitute.For()); + + Assert.Throws(() => client.GetAllForCurrent((ApiOptions)null)); + Assert.Throws(() => client.GetAllForCurrent((StarredRequest)null)); + Assert.Throws(() => client.GetAllForCurrentWithTimestamps((ApiOptions)null)); + Assert.Throws(() => client.GetAllForCurrentWithTimestamps((StarredRequest)null)); + + Assert.Throws(() => client.GetAllForCurrent(null, new ApiOptions())); + Assert.Throws(() => client.GetAllForCurrent(new StarredRequest(), null)); + Assert.Throws(() => client.GetAllForCurrentWithTimestamps(null, new ApiOptions())); + Assert.Throws(() => client.GetAllForCurrentWithTimestamps(new StarredRequest(), null)); } } public class TheGetAllForUserMethod { [Fact] - public async Task EnsuresArguments() - { - var client = new ObservableStarredClient(Substitute.For()); - - await Assert.ThrowsAsync(() => client.GetAllForUser(null).ToTask()); - } - - [Fact] - public void GetsStarsForUser() + public void RequestsCorrectUrl() { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); var connection = Substitute.For(); var gitHubClient = Substitute.For(); gitHubClient.Connection.Returns(connection); var client = new ObservableStarredClient(gitHubClient); - client.GetAllForUser("jugglingnutcase"); - connection.Received().Get>(ApiUrls.StarredByUser("jugglingnutcase"), null, null); + client.GetAllForUser("banana"); + + connection.Received().Get>(endpoint, Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllForUser("banana", options); + + connection.Received().Get>(endpoint, + Arg.Is>(d => d.Count == 2 && d["per_page"] == "1" && d["page"] == "1"), null); + } + + [Fact] + public void RequestsCorrectUrlParametrized() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending }; + + client.GetAllForUser("banana", starredRequest); + + connection.Received().Get>(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), null); + } + + [Fact] + public void RequestsCorrectUrlParametrizedWithApiOptions() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending }; + + client.GetAllForUser("banana", starredRequest, options); + + connection.Received().Get>(endpoint, + Arg.Is>(d => d.Count == 4 && d["direction"] == "asc" && d["direction"] == "asc" && d["per_page"] == "1" && d["page"] == "1"), + null); + } + + [Fact] + public void RequestsCorrectUrlWithTimestamps() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + client.GetAllForUserWithTimestamps("banana"); + + connection.Received().Get>(endpoint, Args.EmptyDictionary, + "application/vnd.github.v3.star+json"); + } + + [Fact] + public void RequestsCorrectUrlWithTimestampsWithApiOptions() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllForUserWithTimestamps("banana", options); + + connection.Received().Get>(endpoint, + Arg.Is>(d => d.Count == 2 && d["per_page"] == "1" && d["page"] == "1"), + "application/vnd.github.v3.star+json"); + } + + [Fact] + public void RequestsCorrectUrlWithTimestampsParametrized() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending }; + + client.GetAllForUserWithTimestamps("banana", starredRequest); + + connection.Received().Get>(endpoint, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc"), + "application/vnd.github.v3.star+json"); + } + + [Fact] + public void RequestsCorrectUrlWithTimestampsParametrizedWithApiOptions() + { + var endpoint = new Uri("users/banana/starred", UriKind.Relative); + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending }; + + client.GetAllForUserWithTimestamps("banana", starredRequest, options); + + connection.Received().Get>(endpoint, Arg.Is>(d => d.Count == 4 && d["direction"] == "asc" && d["direction"] == "asc" && d["per_page"] == "1" && d["page"] == "1"), + "application/vnd.github.v3.star+json"); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableStarredClient(Substitute.For()); + + Assert.Throws(() => client.GetAllForUser(null)); + Assert.Throws(() => client.GetAllForUser(null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForUser("banana", (ApiOptions)null)); + Assert.Throws(() => client.GetAllForUser(null, new StarredRequest())); + Assert.Throws(() => client.GetAllForUser("banana", (StarredRequest)null)); + Assert.Throws(() => client.GetAllForUser(null, new StarredRequest(), ApiOptions.None)); + Assert.Throws(() => client.GetAllForUser("banana", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForUser("banana", new StarredRequest(), null)); + + Assert.Throws(() => client.GetAllForUserWithTimestamps(null)); + Assert.Throws(() => client.GetAllForUserWithTimestamps(null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForUserWithTimestamps("banana", (ApiOptions)null)); + Assert.Throws(() => client.GetAllForUserWithTimestamps(null, new StarredRequest())); + Assert.Throws(() => client.GetAllForUserWithTimestamps("banana", (StarredRequest)null)); + Assert.Throws(() => client.GetAllForUserWithTimestamps(null, new StarredRequest(), ApiOptions.None)); + Assert.Throws(() => client.GetAllForUserWithTimestamps("banana", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForUserWithTimestamps("banana", new StarredRequest(), null)); + + Assert.Throws(() => client.GetAllForUser("")); + Assert.Throws(() => client.GetAllForUser("", ApiOptions.None)); + Assert.Throws(() => client.GetAllForUser("", new StarredRequest(), ApiOptions.None)); + Assert.Throws(() => client.GetAllForUserWithTimestamps("")); + Assert.Throws(() => client.GetAllForUserWithTimestamps("", ApiOptions.None)); + Assert.Throws(() => client.GetAllForUserWithTimestamps("", new StarredRequest(), ApiOptions.None)); } } @@ -93,7 +494,7 @@ namespace Octokit.Tests.Reactive } [Fact] - public async Task ChecksStarredForUser() + public void ChecksStarredForUser() { var gitHubClient = Substitute.For(); var client = new ObservableStarredClient(gitHubClient); @@ -115,7 +516,7 @@ namespace Octokit.Tests.Reactive } [Fact] - public async Task ChecksStarredForUser() + public void ChecksStarredForUser() { var gitHubClient = Substitute.For(); var client = new ObservableStarredClient(gitHubClient); @@ -137,7 +538,7 @@ namespace Octokit.Tests.Reactive } [Fact] - public async Task ChecksStarredForUser() + public void ChecksStarredForUser() { var gitHubClient = Substitute.For(); var client = new ObservableStarredClient(gitHubClient); diff --git a/Octokit/Clients/IStarredClient.cs b/Octokit/Clients/IStarredClient.cs index 078f5707..6aeaf127 100644 --- a/Octokit/Clients/IStarredClient.cs +++ b/Octokit/Clients/IStarredClient.cs @@ -20,6 +20,16 @@ namespace Octokit /// A of s starring the passed repository. Task> GetAllStargazers(string owner, string name); + /// + /// Retrieves all of the stargazers for the passed repository. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository. + Task> GetAllStargazers(string owner, string name, ApiOptions options); + /// /// Retrieves all of the stargazers for the passed repository with star creation timestamps. /// @@ -29,6 +39,16 @@ namespace Octokit /// A of s starring the passed repository with star creation timestamps. Task> GetAllStargazersWithTimestamps(string owner, string name); + /// + /// Retrieves all of the stargazers for the passed repository with star creation timestamps. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository with star creation timestamps. + Task> GetAllStargazersWithTimestamps(string owner, string name, ApiOptions options); + /// /// Retrieves all of the starred (ies) for the current user. /// @@ -38,6 +58,16 @@ namespace Octokit /// Task> GetAllForCurrent(); + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user. + /// + Task> GetAllForCurrent(ApiOptions options); + /// /// Retrieves all of the starred (ies) for the current user with star creation timestamps. /// @@ -47,6 +77,16 @@ namespace Octokit /// Task> GetAllForCurrentWithTimestamps(); + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user with star creation timestamps. + /// + Task> GetAllForCurrentWithTimestamps(ApiOptions options); + /// /// Retrieves all of the starred (ies) for the current user. /// @@ -58,6 +98,18 @@ namespace Octokit /// Task> GetAllForCurrent(StarredRequest request); + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters. + /// + Task> GetAllForCurrent(StarredRequest request, ApiOptions options); + /// /// Retrieves all of the starred (ies) for the current user with star creation timestamps. /// @@ -69,6 +121,18 @@ namespace Octokit /// Task> GetAllForCurrentWithTimestamps(StarredRequest request); + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + Task> GetAllForCurrentWithTimestamps(StarredRequest request, ApiOptions options); + /// /// Retrieves all of the (ies) starred by the specified user. /// @@ -79,6 +143,17 @@ namespace Octokit /// Task> GetAllForUser(string user); + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user. + /// + Task> GetAllForUser(string user, ApiOptions options); + /// /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. /// @@ -89,6 +164,17 @@ namespace Octokit /// Task> GetAllForUserWithTimestamps(string user); + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user with star creation timestamps. + /// + Task> GetAllForUserWithTimestamps(string user, ApiOptions options); + /// /// Retrieves all of the (ies) starred by the specified user. /// @@ -98,6 +184,16 @@ namespace Octokit /// A starred by the specified user. Task> GetAllForUser(string user, StarredRequest request); + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A starred by the specified user. + Task> GetAllForUser(string user, StarredRequest request, ApiOptions options); + /// /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. /// @@ -110,6 +206,19 @@ namespace Octokit /// Task> GetAllForUserWithTimestamps(string user, StarredRequest request); + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the specified user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + Task> GetAllForUserWithTimestamps(string user, StarredRequest request, ApiOptions options); + /// /// Check if a repository is starred by the current authenticated user. /// diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index 132ca2dc..4ec54834 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -32,7 +32,24 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.Stargazers(owner, name)); + return GetAllStargazers(owner, name, ApiOptions.None); + } + + /// + /// Retrieves all of the stargazers for the passed repository. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository. + public Task> GetAllStargazers(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Stargazers(owner, name), options); } /// @@ -47,7 +64,24 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.Stargazers(owner, name), null, AcceptHeaders.StarCreationTimestamps); + return GetAllStargazersWithTimestamps(owner, name, ApiOptions.None); + } + + /// + /// Retrieves all of the stargazers for the passed repository with star creation timestamps. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A of s starring the passed repository with star creation timestamps. + public Task> GetAllStargazersWithTimestamps(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Stargazers(owner, name), null, AcceptHeaders.StarCreationTimestamps, options); } /// @@ -59,7 +93,22 @@ namespace Octokit /// public Task> GetAllForCurrent() { - return ApiConnection.GetAll(ApiUrls.Starred()); + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user. + /// + public Task> GetAllForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Starred(), options); } /// @@ -71,7 +120,22 @@ namespace Octokit /// public Task> GetAllForCurrentWithTimestamps() { - return ApiConnection.GetAll(ApiUrls.Starred(), null, AcceptHeaders.StarCreationTimestamps); + return GetAllForCurrentWithTimestamps(ApiOptions.None); + } + + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current authenticated user with star creation timestamps. + /// + public Task> GetAllForCurrentWithTimestamps(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Starred(), null, AcceptHeaders.StarCreationTimestamps, options); } /// @@ -89,7 +153,25 @@ namespace Octokit { Ensure.ArgumentNotNull(request, "request"); - return ApiConnection.GetAll(ApiUrls.Starred(), request.ToParametersDictionary()); + return GetAllForCurrent(request, ApiOptions.None); + } + + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters. + /// + public Task> GetAllForCurrent(StarredRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Starred(), request.ToParametersDictionary(), options); } /// @@ -107,7 +189,25 @@ namespace Octokit { Ensure.ArgumentNotNull(request, "request"); - return ApiConnection.GetAll(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps); + return GetAllForCurrentWithTimestamps(request, ApiOptions.None); + } + + /// + /// Retrieves all of the starred (ies) for the current user with star creation timestamps. + /// + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + public Task> GetAllForCurrentWithTimestamps(StarredRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps, options); } /// @@ -122,7 +222,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.StarredByUser(user)); + return GetAllForUser(user, ApiOptions.None); + } + + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user. + /// + public Task> GetAllForUser(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.StarredByUser(user), options); } /// @@ -137,7 +254,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.StarredByUser(user), null, AcceptHeaders.StarCreationTimestamps); + return GetAllForUserWithTimestamps(user, ApiOptions.None); + } + + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A (ies) starred by the specified user with star creation timestamps. + /// + public Task> GetAllForUserWithTimestamps(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.StarredByUser(user), null, AcceptHeaders.StarCreationTimestamps, options); } /// @@ -153,7 +287,24 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(request, "request"); - return ApiConnection.GetAll(ApiUrls.StarredByUser(user), request.ToParametersDictionary()); + return GetAllForUser(user, request, ApiOptions.None); + } + + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// A starred by the specified user. + public Task> GetAllForUser(string user, StarredRequest request, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), options); } /// @@ -172,7 +323,27 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(request, "request"); - return ApiConnection.GetAll(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps); + return GetAllForUserWithTimestamps(user, request, ApiOptions.None); + } + + /// + /// Retrieves all of the (ies) starred by the specified user with star creation timestamps. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Options for changing the API response + /// Thrown if the client is not authenticated. + /// + /// A of (ies) starred by the specified user, + /// sorted according to the passed request parameters and with star creation timestamps. + /// + public Task> GetAllForUserWithTimestamps(string user, StarredRequest request, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(request, "request"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps, options); } ///