diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 64a9bb71..f55ffc71 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -123,7 +123,7 @@ flagged as a spammer. ### Testing Documentation If you are making changes to the documentation for Octokit, you can test these -changes locally using the [guide](https://github.com/shiftkey/octokit.net/blob/rewrite-contributing/docs/contributing.md) +changes locally using the [guide](https://github.com/octokit/octokit.net/blob/master/docs/contributing.md) under the `docs` folder. ### Submitting Changes diff --git a/Octokit.Reactive/Clients/IObservableEventsClient.cs b/Octokit.Reactive/Clients/IObservableEventsClient.cs index 5c037fdb..50f49490 100644 --- a/Octokit.Reactive/Clients/IObservableEventsClient.cs +++ b/Octokit.Reactive/Clients/IObservableEventsClient.cs @@ -14,6 +14,16 @@ namespace Octokit.Reactive [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetAll(); + /// + /// Gets all the public events + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events + /// + /// Options for changing the API response + /// All the public s for the particular user. + IObservable GetAll(ApiOptions options); + /// /// Gets all the events for a given repository /// @@ -25,6 +35,18 @@ namespace Octokit.Reactive /// All the s for the particular repository. IObservable GetAllForRepository(string owner, string name); + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + IObservable GetAllForRepository(string owner, string name, ApiOptions options); + /// /// Gets all the events for a given repository network /// @@ -36,6 +58,18 @@ namespace Octokit.Reactive /// All the s for the particular repository network. IObservable GetAllForRepositoryNetwork(string owner, string name); + /// + /// Gets all the events for a given repository network + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository network. + IObservable GetAllForRepositoryNetwork(string owner, string name, ApiOptions options); + /// /// Gets all the events for a given organization /// @@ -46,6 +80,17 @@ namespace Octokit.Reactive /// All the s for the particular organization. IObservable GetAllForOrganization(string organization); + /// + /// Gets all the events for a given organization + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization + /// + /// The name of the organization + /// Options for changing the API response + /// All the s for the particular organization. + IObservable GetAllForOrganization(string organization, ApiOptions options); + /// /// Gets all the events that have been received by a given user. /// @@ -56,6 +101,17 @@ namespace Octokit.Reactive /// All the s that a particular user has received. IObservable GetAllUserReceived(string user); + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + IObservable GetAllUserReceived(string user, ApiOptions options); + /// /// Gets all the events that have been received by a given user. /// @@ -66,6 +122,17 @@ namespace Octokit.Reactive /// All the s that a particular user has received. IObservable GetAllUserReceivedPublic(string user); + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + IObservable GetAllUserReceivedPublic(string user, ApiOptions options); + /// /// Gets all the events that have been performed by a given user. /// @@ -76,6 +143,17 @@ namespace Octokit.Reactive /// All the s that a particular user has performed. IObservable GetAllUserPerformed(string user); + /// + /// Gets all the events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has performed. + IObservable GetAllUserPerformed(string user, ApiOptions options); + /// /// Gets all the public events that have been performed by a given user. /// @@ -86,6 +164,17 @@ namespace Octokit.Reactive /// All the public s that a particular user has performed. IObservable GetAllUserPerformedPublic(string user); + /// + /// Gets all the public events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the public s that a particular user has performed. + IObservable GetAllUserPerformedPublic(string user, ApiOptions options); + /// /// Gets all the events that are associated with an organization. /// @@ -96,5 +185,17 @@ namespace Octokit.Reactive /// The name of the organization /// All the public s that are associated with an organization. IObservable GetAllForAnOrganization(string user, string organization); + + /// + /// Gets all the events that are associated with an organization. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-for-an-organization + /// + /// The login of the user + /// The name of the organization + /// Options for changing the API response + /// All the public s that are associated with an organization. + IObservable GetAllForAnOrganization(string user, string organization, ApiOptions options); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs b/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs index be577f16..ea817b2f 100644 --- a/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs @@ -25,6 +25,15 @@ namespace Octokit.Reactive /// IObservable{GistComment}. IObservable GetAllForGist(string gistId); + /// + /// Gets all comments for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist + /// The id of the gist + /// Options for changing the API response + /// IObservable{GistComment}. + IObservable GetAllForGist(string gistId, ApiOptions options); + /// /// Creates a comment for the gist with the specified id. /// diff --git a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs index 29d4d55e..12a4ebf8 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs @@ -35,6 +35,15 @@ namespace Octokit.Reactive /// IObservable GetAll(string owner, string name); + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// + IObservable GetAll(string owner, string name, ApiOptions options); + /// /// Gets all commits for a given repository /// @@ -44,6 +53,16 @@ namespace Octokit.Reactive /// IObservable GetAll(string owner, string name, CommitRequest request); + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Used to filter list of commits returned + /// Options for changing the API response + /// + IObservable GetAll(string owner, string name, CommitRequest request, ApiOptions options); + /// /// Get the SHA-1 of a commit reference /// diff --git a/Octokit.Reactive/Clients/ObservableCommitStatusClient.cs b/Octokit.Reactive/Clients/ObservableCommitStatusClient.cs index cc43773e..e34ed7a9 100644 --- a/Octokit.Reactive/Clients/ObservableCommitStatusClient.cs +++ b/Octokit.Reactive/Clients/ObservableCommitStatusClient.cs @@ -52,7 +52,7 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.CommitStatuses(owner, name, reference),options); + return _connection.GetAndFlattenAllPages(ApiUrls.CommitStatuses(owner, name, reference), options); } /// diff --git a/Octokit.Reactive/Clients/ObservableEventsClient.cs b/Octokit.Reactive/Clients/ObservableEventsClient.cs index ad871c29..18de33fd 100644 --- a/Octokit.Reactive/Clients/ObservableEventsClient.cs +++ b/Octokit.Reactive/Clients/ObservableEventsClient.cs @@ -23,7 +23,22 @@ namespace Octokit.Reactive /// All the public s for the particular user. public IObservable GetAll() { - return _connection.GetAndFlattenAllPages(ApiUrls.Events()); + return GetAll(ApiOptions.None); + } + + /// + /// Gets all the public events + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events + /// + /// Options for changing the API response + /// All the public s for the particular user. + public IObservable GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Events(), options); } /// @@ -40,7 +55,26 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.IssuesEvents(owner, name)); + return GetAllForRepository(owner, name, ApiOptions.None); + } + + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + public IObservable GetAllForRepository(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssuesEvents(owner, name), options); } /// @@ -57,7 +91,26 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.NetworkEvents(owner, name)); + return GetAllForRepositoryNetwork(owner, name, ApiOptions.None); + } + + /// + /// Gets all the events for a given repository network + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository network. + public IObservable GetAllForRepositoryNetwork(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.NetworkEvents(owner, name), options); } /// @@ -72,7 +125,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationEvents(organization)); + return GetAllForOrganization(organization, ApiOptions.None); + } + + /// + /// Gets all the events for a given organization + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization + /// + /// The name of the organization + /// Options for changing the API response + /// All the s for the particular organization. + public IObservable GetAllForOrganization(string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationEvents(organization), options); } /// @@ -87,7 +157,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.ReceivedEvents(user)); + return GetAllUserReceived(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + public IObservable GetAllUserReceived(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.ReceivedEvents(user), options); } /// @@ -102,7 +189,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.ReceivedEvents(user, true)); + return GetAllUserReceivedPublic(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + public IObservable GetAllUserReceivedPublic(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.ReceivedEvents(user, true), options); } /// @@ -117,7 +221,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.PerformedEvents(user)); + return GetAllUserPerformed(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has performed. + public IObservable GetAllUserPerformed(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.PerformedEvents(user), options); } /// @@ -132,7 +253,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.PerformedEvents(user, true)); + return GetAllUserPerformedPublic(user, ApiOptions.None); + } + + /// + /// Gets all the public events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the public s that a particular user has performed. + public IObservable GetAllUserPerformedPublic(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.PerformedEvents(user, true), options); } /// @@ -149,7 +287,26 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationEvents(user, organization)); + return GetAllForAnOrganization(user, organization, ApiOptions.None); + } + + /// + /// Gets all the events that are associated with an organization. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-for-an-organization + /// + /// The login of the user + /// The name of the organization + /// Options for changing the API response + /// All the public s that are associated with an organization. + public IObservable GetAllForAnOrganization(string user, string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationEvents(user, organization),options); } } } diff --git a/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs b/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs index 7dc639bf..57165687 100644 --- a/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs @@ -38,7 +38,24 @@ namespace Octokit.Reactive /// IObservable{GistComment}. public IObservable GetAllForGist(string gistId) { - return _connection.GetAndFlattenAllPages(ApiUrls.GistComments(gistId)); + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + + return GetAllForGist(gistId, ApiOptions.None); + } + + /// + /// Gets all comments for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist + /// The id of the gist + /// Options for changing the API response + /// IObservable{GistComment}. + public IObservable GetAllForGist(string gistId, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.GistComments(gistId), options); } /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs b/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs index 629142d7..3304e261 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs @@ -54,7 +54,26 @@ namespace Octokit.Reactive /// public IObservable GetAll(string owner, string name) { - return GetAll(owner, name, new CommitRequest()); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return GetAll(owner, name, new CommitRequest(), ApiOptions.None); + } + + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// + public IObservable GetAll(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return GetAll(owner, name, new CommitRequest(), options); } /// @@ -70,8 +89,24 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); - return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryCommits(owner, name), - request.ToParametersDictionary()); + return GetAll(owner, name, request, ApiOptions.None); + } + + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Used to filter list of commits returned + /// Options for changing the API response + /// + public IObservable GetAll(string owner, string name, CommitRequest request, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(request, "request"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryCommits(owner, name), request.ToParametersDictionary(), options); } /// diff --git a/Octokit.Reactive/Helpers/ConnectionExtensions.cs b/Octokit.Reactive/Helpers/ConnectionExtensions.cs index becbf01c..5f2aec15 100644 --- a/Octokit.Reactive/Helpers/ConnectionExtensions.cs +++ b/Octokit.Reactive/Helpers/ConnectionExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; @@ -16,11 +15,7 @@ namespace Octokit.Reactive.Internal public static IObservable GetAndFlattenAllPages(this IConnection connection, Uri url, ApiOptions options) { - return GetPagesWithOptions(url, options, (pageUrl, o) => - { - var parameters = Pagination.Setup(new Dictionary(), options); - return connection.Get>(pageUrl, parameters, null).ToObservable(); - }); + return connection.GetAndFlattenAllPages(url, null, options); } public static IObservable GetAndFlattenAllPages(this IConnection connection, Uri url, IDictionary parameters) @@ -28,6 +23,15 @@ namespace Octokit.Reactive.Internal return GetPages(url, parameters, (pageUrl, pageParams) => connection.Get>(pageUrl, pageParams, null).ToObservable()); } + public static IObservable GetAndFlattenAllPages(this IConnection connection, Uri url, IDictionary parameters, ApiOptions options) + { + return GetPagesWithOptions(url, parameters, options, (pageUrl, pageParams, o) => + { + var passingParameters = Pagination.Setup(parameters, options); + return connection.Get>(pageUrl, passingParameters, null).ToObservable(); + }); + } + public static IObservable GetAndFlattenAllPages(this IConnection connection, Uri url, IDictionary parameters, string accepts) { return GetPages(url, parameters, (pageUrl, pageParams) => connection.Get>(pageUrl, pageParams, accepts).ToObservable()); @@ -47,19 +51,16 @@ namespace Octokit.Reactive.Internal .SelectMany(resp => resp.Body); } - static IObservable GetPagesWithOptions(Uri uri, ApiOptions options, - Func>>> getPageFunc) + static IObservable GetPagesWithOptions(Uri uri, IDictionary parameters, ApiOptions options, Func, ApiOptions, IObservable>>> getPageFunc) { - return getPageFunc(uri, options).Expand(resp => + return getPageFunc(uri, parameters, options).Expand(resp => { - var nextPageUri = resp.HttpResponse.ApiInfo.GetNextPageUrl(); + var nextPageUrl = resp.HttpResponse.ApiInfo.GetNextPageUrl(); - var shouldContinue = Pagination.ShouldContinue( - nextPageUri, - options); + var shouldContinue = Pagination.ShouldContinue(nextPageUrl, options); - return shouldContinue - ? Observable.Defer(() => getPageFunc(nextPageUri, null)) + return shouldContinue + ? Observable.Defer(() => getPageFunc(nextPageUrl, null, null)) : Observable.Empty>>(); }) .Where(resp => resp != null) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs index 83401a3e..c5a3e3c4 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs @@ -42,6 +42,59 @@ public class RepositoryCommitsClientTests Assert.NotEmpty(list); } + [IntegrationTest] + public async Task CanGetCorrectCountOfCommitsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var commits = await _fixture.GetAll("shiftkey", "ReactiveGit", options); + Assert.Equal(5, commits.Count); + } + + [IntegrationTest] + public async Task CanGetCorrectCountOfCommitsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var commits = await _fixture.GetAll("shiftkey", "ReactiveGit", options); + Assert.Equal(5, commits.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStart() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + }; + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var firstCommit = await _fixture.GetAll("shiftkey", "ReactiveGit", startOptions); + var secondCommit = await _fixture.GetAll("shiftkey", "ReactiveGit", skipStartOptions); + + Assert.NotEqual(firstCommit[0].Sha, secondCommit[0].Sha); + Assert.NotEqual(firstCommit[1].Sha, secondCommit[1].Sha); + Assert.NotEqual(firstCommit[2].Sha, secondCommit[2].Sha); + Assert.NotEqual(firstCommit[3].Sha, secondCommit[3].Sha); + Assert.NotEqual(firstCommit[4].Sha, secondCommit[4].Sha); + } + [IntegrationTest] public async Task CanGetListOfCommitsBySha() { diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 6c775ab3..7a80595a 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -138,8 +138,11 @@ + + + @@ -152,6 +155,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs new file mode 100644 index 00000000..3308120c --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs @@ -0,0 +1,699 @@ +using System.Linq; +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableEventsClientTests + { + public class TheGetAllMethod + { + readonly ObservableEventsClient _eventsClient; + + public TheGetAllMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + [IntegrationTest] + public async Task ReturnsEvents() + { + var events = await _eventsClient.GetAll().ToList(); + + Assert.NotEmpty(events); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var events = await _eventsClient.GetAll(options).ToList(); + + Assert.Equal(5, events.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var events = await _eventsClient.GetAll(options).ToList(); + + Assert.Equal(5, events.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstEventsPage = await _eventsClient.GetAll(startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondEventsPage = await _eventsClient.GetAll(skipStartOptions).ToList(); + + Assert.NotEqual(firstEventsPage[0].Id, secondEventsPage[0].Id); + Assert.NotEqual(firstEventsPage[1].Id, secondEventsPage[1].Id); + Assert.NotEqual(firstEventsPage[2].Id, secondEventsPage[2].Id); + Assert.NotEqual(firstEventsPage[3].Id, secondEventsPage[3].Id); + Assert.NotEqual(firstEventsPage[4].Id, secondEventsPage[4].Id); + } + + } + + public class TheGetAllForRepositoryMethod + { + + readonly ObservableEventsClient _eventsClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllForRepositoryMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + [IntegrationTest] + public async Task ReturnsRepositoryEvents() + { + var repositoryEvents = await _eventsClient.GetAllForRepository(owner, name).ToList(); + + Assert.NotEmpty(repositoryEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var repositoryEvents = await _eventsClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, repositoryEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var repositoryEvents = await _eventsClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, repositoryEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoryEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstRepositoryEventsPage = await _eventsClient.GetAllForRepository(owner, name, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondRepositoryEventsPage = await _eventsClient.GetAllForRepository(owner, name, skipStartOptions).ToList(); + + Assert.NotEqual(firstRepositoryEventsPage[0].Id, secondRepositoryEventsPage[0].Id); + Assert.NotEqual(firstRepositoryEventsPage[1].Id, secondRepositoryEventsPage[1].Id); + Assert.NotEqual(firstRepositoryEventsPage[2].Id, secondRepositoryEventsPage[2].Id); + Assert.NotEqual(firstRepositoryEventsPage[3].Id, secondRepositoryEventsPage[3].Id); + Assert.NotEqual(firstRepositoryEventsPage[4].Id, secondRepositoryEventsPage[4].Id); + } + + } + + public class TheGetAllForRepositoryNetworkMethod + { + readonly ObservableEventsClient _eventsClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllForRepositoryNetworkMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + [IntegrationTest] + public async Task ReturnsRepositoryNetworkEvents() + { + var repositoryNetworkEvents = await _eventsClient.GetAllForRepositoryNetwork(owner, name).ToList(); + + Assert.NotEmpty(repositoryNetworkEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryNetworkEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var repositoryNetworkEvents = await _eventsClient.GetAllForRepositoryNetwork(owner, name, options).ToList(); + + Assert.Equal(5, repositoryNetworkEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryNetworkEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var repositoryNetworkEvents = await _eventsClient.GetAllForRepositoryNetwork(owner, name, options).ToList(); + + Assert.Equal(5, repositoryNetworkEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoryNetworkEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstRepositoryNetworkEventsPage = await _eventsClient.GetAllForRepositoryNetwork(owner, name, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondRepositoryNetworkEventsPage = await _eventsClient.GetAllForRepositoryNetwork(owner, name, skipStartOptions).ToList(); + + Assert.NotEqual(firstRepositoryNetworkEventsPage[0].Id, secondRepositoryNetworkEventsPage[0].Id); + Assert.NotEqual(firstRepositoryNetworkEventsPage[1].Id, secondRepositoryNetworkEventsPage[1].Id); + Assert.NotEqual(firstRepositoryNetworkEventsPage[2].Id, secondRepositoryNetworkEventsPage[2].Id); + Assert.NotEqual(firstRepositoryNetworkEventsPage[3].Id, secondRepositoryNetworkEventsPage[3].Id); + Assert.NotEqual(firstRepositoryNetworkEventsPage[4].Id, secondRepositoryNetworkEventsPage[4].Id); + } + + } + + public class TheGetAllForOrganizationMethod + { + + readonly ObservableEventsClient _eventsClient; + const string organization = "octokit"; + + public TheGetAllForOrganizationMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsOrganizationEvents() + { + var organizationEvents = await _eventsClient.GetAllForOrganization(organization).ToList(); + + Assert.NotEmpty(organizationEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfOrganizationEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var organizationEvents = await _eventsClient.GetAllForOrganization(organization, options).ToList(); + + Assert.Equal(5, organizationEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfOrganizationEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var organizationEvents = await _eventsClient.GetAllForOrganization(organization, options).ToList(); + + Assert.Equal(5, organizationEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctOrganizationEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstOrganizationEventsPage = await _eventsClient.GetAllForOrganization(organization, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondOrganizationEventsPage = await _eventsClient.GetAllForOrganization(organization, skipStartOptions).ToList(); + + Assert.NotEqual(firstOrganizationEventsPage[0].Id, secondOrganizationEventsPage[0].Id); + Assert.NotEqual(firstOrganizationEventsPage[1].Id, secondOrganizationEventsPage[1].Id); + Assert.NotEqual(firstOrganizationEventsPage[2].Id, secondOrganizationEventsPage[2].Id); + Assert.NotEqual(firstOrganizationEventsPage[3].Id, secondOrganizationEventsPage[3].Id); + Assert.NotEqual(firstOrganizationEventsPage[4].Id, secondOrganizationEventsPage[4].Id); + } + + } + + public class TheGetAllUserReceivedMethod + { + readonly ObservableEventsClient _eventsClient; + const string user = "shiftkey"; + + public TheGetAllUserReceivedMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsUserReceivedEvents() + { + var userReceivedEvents = await _eventsClient.GetAllUserReceived(user).ToList(); + + Assert.NotEmpty(userReceivedEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserReceivedEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userReceivedEvents = await _eventsClient.GetAllUserReceived(user, options).ToList(); + + Assert.Equal(5, userReceivedEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserReceivedEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userReceivedEvents = await _eventsClient.GetAllUserReceived(user, options).ToList(); + + Assert.Equal(5, userReceivedEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserReceivedEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserReceivedEventsPage = await _eventsClient.GetAllUserReceived(user, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserReceivedEventsPage = await _eventsClient.GetAllUserReceived(user, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserReceivedEventsPage[0].Id, secondUserReceivedEventsPage[0].Id); + Assert.NotEqual(firstUserReceivedEventsPage[1].Id, secondUserReceivedEventsPage[1].Id); + Assert.NotEqual(firstUserReceivedEventsPage[2].Id, secondUserReceivedEventsPage[2].Id); + Assert.NotEqual(firstUserReceivedEventsPage[3].Id, secondUserReceivedEventsPage[3].Id); + Assert.NotEqual(firstUserReceivedEventsPage[4].Id, secondUserReceivedEventsPage[4].Id); + } + } + + public class TheGetAllUserReceivedPublicMethod + { + + readonly ObservableEventsClient _eventsClient; + const string user = "shiftkey"; + + public TheGetAllUserReceivedPublicMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsUserReceivedPublicEvents() + { + var userReceivedPublicEvents = await _eventsClient.GetAllUserReceivedPublic(user).ToList(); + + Assert.NotEmpty(userReceivedPublicEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserReceivedPublicEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userReceivedPublicEvents = await _eventsClient.GetAllUserReceivedPublic(user, options).ToList(); + + Assert.Equal(5, userReceivedPublicEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserReceivedPublicEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userReceivedPublicEvents = await _eventsClient.GetAllUserReceivedPublic(user, options).ToList(); + + Assert.Equal(5, userReceivedPublicEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserReceivedPublicEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserReceivedPublicEventsPage = await _eventsClient.GetAllUserReceivedPublic(user, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserReceivedPublicEventsPage = await _eventsClient.GetAllUserReceivedPublic(user, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserReceivedPublicEventsPage[0].Id, secondUserReceivedPublicEventsPage[0].Id); + Assert.NotEqual(firstUserReceivedPublicEventsPage[1].Id, secondUserReceivedPublicEventsPage[1].Id); + Assert.NotEqual(firstUserReceivedPublicEventsPage[2].Id, secondUserReceivedPublicEventsPage[2].Id); + Assert.NotEqual(firstUserReceivedPublicEventsPage[3].Id, secondUserReceivedPublicEventsPage[3].Id); + Assert.NotEqual(firstUserReceivedPublicEventsPage[4].Id, secondUserReceivedPublicEventsPage[4].Id); + } + + } + + public class TheGetAllUserPerformedMethod + { + readonly ObservableEventsClient _eventsClient; + const string user = "shiftkey"; + + public TheGetAllUserPerformedMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsUserPerformedEvents() + { + var userPerformedEvents = await _eventsClient.GetAllUserPerformed(user).ToList(); + + Assert.NotEmpty(userPerformedEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserPerformedEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userPerformedEvents = await _eventsClient.GetAllUserPerformed(user, options).ToList(); + + Assert.Equal(5, userPerformedEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserPerformedEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userPerformedEvents = await _eventsClient.GetAllUserPerformed(user, options).ToList(); + + Assert.Equal(5, userPerformedEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserPerformedEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserPerformedEventsPage = await _eventsClient.GetAllUserPerformed(user, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserPerformedEventsPage = await _eventsClient.GetAllUserPerformed(user, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserPerformedEventsPage[0].Id, secondUserPerformedEventsPage[0].Id); + Assert.NotEqual(firstUserPerformedEventsPage[1].Id, secondUserPerformedEventsPage[1].Id); + Assert.NotEqual(firstUserPerformedEventsPage[2].Id, secondUserPerformedEventsPage[2].Id); + Assert.NotEqual(firstUserPerformedEventsPage[3].Id, secondUserPerformedEventsPage[3].Id); + Assert.NotEqual(firstUserPerformedEventsPage[4].Id, secondUserPerformedEventsPage[4].Id); + } + + } + + public class TheGetAllUserPerformedPublicMethod + { + readonly ObservableEventsClient _eventsClient; + const string user = "shiftkey"; + + public TheGetAllUserPerformedPublicMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsUserPerformedPublicEvents() + { + var userPerformedPublicEvents = await _eventsClient.GetAllUserPerformedPublic(user).ToList(); + + Assert.NotEmpty(userPerformedPublicEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserPerformedPublicEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userPerformedPublicEvents = await _eventsClient.GetAllUserPerformedPublic(user, options).ToList(); + + Assert.Equal(5, userPerformedPublicEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserPerformedPublicEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userPerformedPublicEvents = await _eventsClient.GetAllUserPerformedPublic(user, options).ToList(); + + Assert.Equal(5, userPerformedPublicEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserPerformedPublicEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserPerformedPublicEventsPage = await _eventsClient.GetAllUserPerformedPublic(user, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserPerformedPublicEventsPage = await _eventsClient.GetAllUserPerformedPublic(user, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserPerformedPublicEventsPage[0].Id, secondUserPerformedPublicEventsPage[0].Id); + Assert.NotEqual(firstUserPerformedPublicEventsPage[1].Id, secondUserPerformedPublicEventsPage[1].Id); + Assert.NotEqual(firstUserPerformedPublicEventsPage[2].Id, secondUserPerformedPublicEventsPage[2].Id); + Assert.NotEqual(firstUserPerformedPublicEventsPage[3].Id, secondUserPerformedPublicEventsPage[3].Id); + Assert.NotEqual(firstUserPerformedPublicEventsPage[4].Id, secondUserPerformedPublicEventsPage[4].Id); + } + + } + + public class TheGetAllForAnOrganizationMethod + { + readonly ObservableEventsClient _eventsClient; + readonly string _organization; + readonly string _user; + + public TheGetAllForAnOrganizationMethod() + { + var github = Helper.GetAuthenticatedClient(); + _eventsClient = new ObservableEventsClient(github); + _user = Helper.UserName; + _organization = Helper.Organization; + } + + [IntegrationTest] + public async Task ReturnsUserOrganizationEvents() + { + var userOrganizationEvents = await _eventsClient.GetAllForAnOrganization(_user,_organization).ToList(); + + Assert.NotEmpty(userOrganizationEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserOrganizationEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userOrganizationEvents = await _eventsClient.GetAllForAnOrganization(_user, _organization, options).ToList(); + + Assert.Equal(5, userOrganizationEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserOrganizationEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userOrganizationEvents = await _eventsClient.GetAllForAnOrganization(_user, _organization, options).ToList(); + + Assert.Equal(5, userOrganizationEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserOrganizationEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserOrganizationEventsPage = await _eventsClient.GetAllForAnOrganization(_user, _organization, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserOrganizationEventsPage = await _eventsClient.GetAllForAnOrganization(_user, _organization, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserOrganizationEventsPage[0].Id, secondUserOrganizationEventsPage[0].Id); + Assert.NotEqual(firstUserOrganizationEventsPage[1].Id, secondUserOrganizationEventsPage[1].Id); + Assert.NotEqual(firstUserOrganizationEventsPage[2].Id, secondUserOrganizationEventsPage[2].Id); + Assert.NotEqual(firstUserOrganizationEventsPage[3].Id, secondUserOrganizationEventsPage[3].Id); + Assert.NotEqual(firstUserOrganizationEventsPage[4].Id, secondUserOrganizationEventsPage[4].Id); + } + + } + } +} diff --git a/Octokit.Tests.Integration/Reactive/ObservableGistCommentsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableGistCommentsClientTests.cs new file mode 100644 index 00000000..1f350dbe --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableGistCommentsClientTests.cs @@ -0,0 +1,86 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableGistCommentsClientTests + { + public class TheGetAllForGistMethod + { + readonly ObservableGistCommentsClient _gistCommentsClient; + const string gistId = "7783a2c14a15a2e3c93b"; + + public TheGetAllForGistMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _gistCommentsClient = new ObservableGistCommentsClient(github); + } + + [IntegrationTest] + public async Task ReturnsGistComments() + { + var comments = await _gistCommentsClient.GetAllForGist(gistId).ToList(); + + Assert.NotEmpty(comments); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfGistCommentsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var comments = await _gistCommentsClient.GetAllForGist(gistId, options).ToList(); + + Assert.Equal(5, comments.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfGistCommentsWithStart() + { + var options = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + + var comments = await _gistCommentsClient.GetAllForGist(gistId, options).ToList(); + + Assert.Equal(4, comments.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1 + }; + + var firstCommentsPage = await _gistCommentsClient.GetAllForGist(gistId, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + + var secondCommentsPage = await _gistCommentsClient.GetAllForGist(gistId, skipStartOptions).ToList(); + + Assert.NotEqual(firstCommentsPage[0].Id, secondCommentsPage[0].Id); + Assert.NotEqual(firstCommentsPage[1].Id, secondCommentsPage[1].Id); + Assert.NotEqual(firstCommentsPage[2].Id, secondCommentsPage[2].Id); + Assert.NotEqual(firstCommentsPage[3].Id, secondCommentsPage[3].Id); + } + } + } +} diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs new file mode 100644 index 00000000..63995c8c --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs @@ -0,0 +1,75 @@ +using System.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using System.Reactive.Linq; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableRepositoryCommitsClientTests + { + public class TheGetAllMethod + { + readonly ObservableRepositoryCommitsClient _repositoryCommitsClient; + + public TheGetAllMethod() + { + var client = Helper.GetAuthenticatedClient(); + _repositoryCommitsClient = new ObservableRepositoryCommitsClient(client); + } + + [IntegrationTest] + public async Task CanGetCorrectCountOfCommitsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var commits = await _repositoryCommitsClient.GetAll("shiftkey", "ReactiveGit", options).ToList(); + Assert.Equal(5, commits.Count); + } + + [IntegrationTest] + public async Task CanGetCorrectCountOfCommitsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var commits = await _repositoryCommitsClient.GetAll("shiftkey", "ReactiveGit", options).ToList(); + Assert.Equal(5, commits.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStart() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + }; + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var firstCommit = await _repositoryCommitsClient.GetAll("shiftkey", "ReactiveGit", startOptions).ToList(); + var secondCommit = await _repositoryCommitsClient.GetAll("shiftkey", "ReactiveGit", skipStartOptions).ToList(); + + Assert.NotEqual(firstCommit[0].Sha, secondCommit[0].Sha); + Assert.NotEqual(firstCommit[1].Sha, secondCommit[1].Sha); + Assert.NotEqual(firstCommit[2].Sha, secondCommit[2].Sha); + Assert.NotEqual(firstCommit[3].Sha, secondCommit[3].Sha); + Assert.NotEqual(firstCommit[4].Sha, secondCommit[4].Sha); + } + } + } +} diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs index bbcf8ef5..914392a3 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs @@ -6,7 +6,7 @@ using Octokit.Reactive; using Octokit.Tests.Integration; using Xunit; -public class ObservableRepositoryDeployKeysClientTests : IDisposable +public class ObservableRespositoryDeployKeysClientTests : IDisposable { const string _key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDB8IE5+RppLpeW+6lqo0fpfvMunKg6W4bhYCfVJIOYbpKoHP95nTUMZPBT++9NLeB4/YsuNTCrrpnpjc4f2IVpGvloRiVXjAzoJk9QIL6uzn1zRFdvaxSJ3Urhe9LcLHcIgccgZgSdWGzaZI3xtMvGC4diwWNsPjvVc/RyDM/MPqAim0X5XVOQwEFsSsUSraezJ+VgYMYzLYBcKWW0B86HVVhL4ZtmcY/RN2544bljnzw2M3aQvXNPTvkuiUoqLOI+5/qzZ8PfkruO55YtweEd0lkY6oZvrBPMD6dLODEqMHb4tD6htx60wSipNqjPwpOMpzp0Bk3G909unVXi6Fw5"; const string _keyTitle = "octokit@github"; @@ -14,7 +14,7 @@ public class ObservableRepositoryDeployKeysClientTests : IDisposable Repository _repository; string _owner; - public ObservableRepositoryDeployKeysClientTests() + public ObservableRespositoryDeployKeysClientTests() { var github = Helper.GetAuthenticatedClient(); diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index 57437d82..3defac5b 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -24,7 +24,33 @@ namespace Octokit.Tests.Clients client.GetAll(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "events"), Args.ApiOptions); + } + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAll(options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "events"), options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll(null)); } } @@ -38,7 +64,25 @@ namespace Octokit.Tests.Clients client.GetAllForRepository("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), Args.ApiOptions); + } + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + + client.GetAllForRepository("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), options); } [Fact] @@ -51,6 +95,9 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name",null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "",ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None)); } } @@ -64,7 +111,25 @@ namespace Octokit.Tests.Clients client.GetAllForRepositoryNetwork("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "networks/fake/repo/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "networks/fake/repo/events"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllForRepositoryNetwork("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "networks/fake/repo/events"), options); } [Fact] @@ -77,6 +142,9 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("", "name")); await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("owner", null)); await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("owner", "")); + await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("owner", "name", null)); + await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("owner", "", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("", "name", ApiOptions.None)); } } @@ -90,7 +158,25 @@ namespace Octokit.Tests.Clients client.GetAllForOrganization("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/events"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllForOrganization("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/events"), options); } [Fact] @@ -101,6 +187,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForOrganization(null)); await Assert.ThrowsAsync(() => client.GetAllForOrganization("")); + await Assert.ThrowsAsync(() => client.GetAllForOrganization("fake", null)); + await Assert.ThrowsAsync(() => client.GetAllForOrganization("", ApiOptions.None)); } } @@ -114,7 +202,25 @@ namespace Octokit.Tests.Clients client.GetAllUserReceived("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllUserReceived("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events"), options); } [Fact] @@ -125,6 +231,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllUserReceived(null)); await Assert.ThrowsAsync(() => client.GetAllUserReceived("")); + await Assert.ThrowsAsync(() => client.GetAllUserReceived("fake", null)); + await Assert.ThrowsAsync(() => client.GetAllUserReceived("", ApiOptions.None)); } } @@ -138,7 +246,25 @@ namespace Octokit.Tests.Clients client.GetAllUserReceivedPublic("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events/public")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events/public"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllUserReceivedPublic("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events/public"), options); } [Fact] @@ -149,6 +275,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllUserReceivedPublic(null)); await Assert.ThrowsAsync(() => client.GetAllUserReceivedPublic("")); + await Assert.ThrowsAsync(() => client.GetAllUserReceivedPublic("fake", null)); + await Assert.ThrowsAsync(() => client.GetAllUserReceivedPublic("", ApiOptions.None)); } } @@ -162,7 +290,25 @@ namespace Octokit.Tests.Clients client.GetAllUserPerformed("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllUserPerformed("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events"), options); } [Fact] @@ -173,6 +319,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllUserPerformed(null)); await Assert.ThrowsAsync(() => client.GetAllUserPerformed("")); + await Assert.ThrowsAsync(() => client.GetAllUserPerformed("fake", null)); + await Assert.ThrowsAsync(() => client.GetAllUserPerformed("", ApiOptions.None)); } } @@ -186,7 +334,25 @@ namespace Octokit.Tests.Clients client.GetAllUserPerformedPublic("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/public")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/public"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllUserPerformedPublic("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/public"), options); } [Fact] @@ -197,6 +363,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllUserPerformedPublic(null)); await Assert.ThrowsAsync(() => client.GetAllUserPerformedPublic("")); + await Assert.ThrowsAsync(() => client.GetAllUserPerformedPublic("fake",null)); + await Assert.ThrowsAsync(() => client.GetAllUserPerformedPublic("",ApiOptions.None)); } } @@ -210,7 +378,25 @@ namespace Octokit.Tests.Clients client.GetAllForAnOrganization("fake", "org"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/orgs/org")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/orgs/org"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllForAnOrganization("fake", "org", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/orgs/org"), options); } [Fact] @@ -223,6 +409,9 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("", "org")); await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("fake", null)); await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("fake", "")); + await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("fake", "org", null)); + await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("fake", "", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("", "org", ApiOptions.None)); } } diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs index 7689dcc4..66b33d38 100644 --- a/Octokit.Tests/Clients/GistCommentsClientTests.cs +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -1,108 +1,140 @@ using System; using System.Threading.Tasks; using NSubstitute; -using Octokit; -using Octokit.Tests.Helpers; using Xunit; -public class GistCommentsClientTests +namespace Octokit.Tests.Clients { - public class TheCtor + public class GistCommentsClientTests { - [Fact] - public void EnsuresArgument() + public class TheCtor { - Assert.Throws(() => new GistCommentsClient(null)); - } - } - - public class TheGetMethod - { - [Fact] - public async Task RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); - - await client.Get("24", 1337); - - connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); - } - } - - public class TheGetForGistMethod - { - [Fact] - public async Task RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); - - await client.GetAllForGist("24"); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments")); - } - } - - public class TheCreateMethod - { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); - - await Assert.ThrowsAsync(() => client.Create("24", null)); - await Assert.ThrowsAsync(() => client.Create("24", "")); + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new GistCommentsClient(null)); + } } - [Fact] - public async Task PostsToCorrectUrl() + public class TheGetMethod { - var comment = "This is a comment."; - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); - await client.Create("24", comment); + await client.Get("24", 1337); - connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), Arg.Is(x => x.Body == comment)); - } - } - - public class TheUpdateMethod - { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); - - await Assert.ThrowsAsync(() => client.Update("24", 1337, null)); - await Assert.ThrowsAsync(() => client.Update("24", 1337, "")); + connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); + } } - [Fact] - public async Task PostsToCorrectUrl() + public class TheGetAllForGistMethod { - var comment = "This is a comment."; - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); - await client.Update("24", 1337, comment); + await client.GetAllForGist("24"); - connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), Arg.Is(x => x.Body == comment)); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments"), Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + await client.GetAllForGist("24", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments"), options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForGist(null)); + await Assert.ThrowsAsync(() => client.GetAllForGist("")); + await Assert.ThrowsAsync(() => client.GetAllForGist("24", null)); + await Assert.ThrowsAsync(() => client.GetAllForGist("", ApiOptions.None)); + + } } - } - public class TheDeleteMethod - { - [Fact] - public async Task PostsToCorrectUrl() + public class TheCreateMethod { - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); - await client.Delete("24", 1337); + await Assert.ThrowsAsync(() => client.Create("24", null)); + await Assert.ThrowsAsync(() => client.Create("24", "")); + } - connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); + [Fact] + public async Task PostsToCorrectUrl() + { + var comment = "This is a comment."; + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Create("24", comment); + + connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), Arg.Is(x => x.Body == comment)); + } + } + + public class TheUpdateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Update("24", 1337, null)); + await Assert.ThrowsAsync(() => client.Update("24", 1337, "")); + } + + [Fact] + public async Task PostsToCorrectUrl() + { + var comment = "This is a comment."; + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Update("24", 1337, comment); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), Arg.Is(x => x.Body == comment)); + } + } + + public class TheDeleteMethod + { + [Fact] + public async Task PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Delete("24", 1337); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); + } } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/ReleasesClientTests.cs b/Octokit.Tests/Clients/ReleasesClientTests.cs index 10ce49a8..645ce6c2 100644 --- a/Octokit.Tests/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests/Clients/ReleasesClientTests.cs @@ -51,8 +51,12 @@ namespace Octokit.Tests.Clients var releasesClient = new ReleasesClient(Substitute.For()); await Assert.ThrowsAsync(() => releasesClient.GetAll(null, "name")); + await Assert.ThrowsAsync(() => releasesClient.GetAll("", "name")); await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", null)); + await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", "")); await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", "name", null)); + await Assert.ThrowsAsync(() => releasesClient.GetAll("", "name", ApiOptions.None)); + await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", "", ApiOptions.None)); } } diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index cae96871..6789f048 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -740,7 +740,7 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAll("owner", null)); await Assert.ThrowsAsync(() => client.GetAll("owner", "")); - await Assert.ThrowsAsync(() => client.GetAll("owner", "repo", null)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "repo", null, ApiOptions.None)); } [Fact] @@ -752,8 +752,7 @@ namespace Octokit.Tests.Clients client.GetAll("owner", "name"); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/commits"), - Arg.Any>()); + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/commits"), Args.EmptyDictionary, Args.ApiOptions); } } diff --git a/Octokit.Tests/Clients/RespositoryCommitsClientTests.cs b/Octokit.Tests/Clients/RespositoryCommitsClientTests.cs new file mode 100644 index 00000000..fe0ba30f --- /dev/null +++ b/Octokit.Tests/Clients/RespositoryCommitsClientTests.cs @@ -0,0 +1,50 @@ +using NSubstitute; +using System; +using System.Collections.Generic; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class RespositoryCommitsClientTests + { + public class TheGetAllMethod + { + [Fact] + public void EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new RepositoryCommitsClient(connection); + var options = new ApiOptions(); + var request = new CommitRequest(); + + Assert.ThrowsAsync(() => client.GetAll("", "name", request, options)); + Assert.ThrowsAsync(() => client.GetAll("owner", "", request, options)); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new RepositoryCommitsClient(connection); + var options = new ApiOptions(); + var request = new CommitRequest(); + + Assert.ThrowsAsync(() => client.GetAll(null, "name", request, options)); + Assert.ThrowsAsync(() => client.GetAll("owner", null, request, options)); + Assert.ThrowsAsync(() => client.GetAll("owner", "name", null, options)); + Assert.ThrowsAsync(() => client.GetAll("owner", "name", request, null)); + + } + + [Fact] + public void GetsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryCommitsClient(connection); + + client.GetAll("fake", "repo", new CommitRequest(), new ApiOptions()); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits"), Args.EmptyDictionary, Args.ApiOptions); + } + } + } +} diff --git a/Octokit.Tests/Exceptions/LegalRestrictionExceptionTests.cs b/Octokit.Tests/Exceptions/LegalRestrictionExceptionTests.cs new file mode 100644 index 00000000..c6190cea --- /dev/null +++ b/Octokit.Tests/Exceptions/LegalRestrictionExceptionTests.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Net; +using Octokit.Internal; +using Xunit; + +namespace Octokit.Tests.Exceptions +{ + public class LegalRestrictionExceptionTests + { + [Fact] + public void HasDefaultMessage() + { + var response = new Response((HttpStatusCode)451, null, new Dictionary(), "application/json"); + var legalRestrictionException = new LegalRestrictionException(response); + + Assert.Equal("Resource taken down due to a DMCA notice.", legalRestrictionException.Message); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 2051df68..06747a7e 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -99,6 +99,7 @@ + @@ -136,6 +137,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableEventsClientTests.cs b/Octokit.Tests/Reactive/ObservableEventsClientTests.cs index 0c8d7e64..bc44a1fd 100644 --- a/Octokit.Tests/Reactive/ObservableEventsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableEventsClientTests.cs @@ -22,7 +22,7 @@ namespace Octokit.Tests.Reactive client.GetAll(); - gitHubClient.Connection.Received(1).Get>(new Uri("events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("events", UriKind.Relative), Args.EmptyDictionary, null); } } @@ -36,7 +36,7 @@ namespace Octokit.Tests.Reactive client.GetAllForRepository("fake", "repo"); - gitHubClient.Connection.Received(1).Get>(new Uri("repos/fake/repo/issues/events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("repos/fake/repo/issues/events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -62,7 +62,7 @@ namespace Octokit.Tests.Reactive client.GetAllForRepositoryNetwork("fake", "repo"); - gitHubClient.Connection.Received(1).Get>(new Uri("networks/fake/repo/events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("networks/fake/repo/events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -88,7 +88,7 @@ namespace Octokit.Tests.Reactive client.GetAllForOrganization("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("orgs/fake/events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("orgs/fake/events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -112,7 +112,7 @@ namespace Octokit.Tests.Reactive client.GetAllUserReceived("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/received_events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/received_events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -136,7 +136,7 @@ namespace Octokit.Tests.Reactive client.GetAllUserReceivedPublic("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/received_events/public", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/received_events/public", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -160,7 +160,7 @@ namespace Octokit.Tests.Reactive client.GetAllUserPerformed("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -184,7 +184,7 @@ namespace Octokit.Tests.Reactive client.GetAllUserPerformedPublic("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events/public", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events/public", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -208,7 +208,7 @@ namespace Octokit.Tests.Reactive client.GetAllForAnOrganization("fake", "org"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events/orgs/org", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events/orgs/org", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] diff --git a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs index a2f0e31f..9825cd74 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs @@ -269,13 +269,13 @@ namespace Octokit.Tests.Reactive public class TheGetAllCommitsMethod { [Fact] - public void EnsuresArguments() + public void EnsuresNonNullArguments() { var client = new ObservableRepositoriesClient(Substitute.For()); Assert.Throws(() => client.Commit.GetAll(null, "repo")); Assert.Throws(() => client.Commit.GetAll("owner", null)); - Assert.Throws(() => client.Commit.GetAll("owner", "repo", null)); + Assert.Throws(() => client.Commit.GetAll("owner", "repo", null, ApiOptions.None)); Assert.Throws(() => client.Commit.GetAll("", "repo")); Assert.Throws(() => client.Commit.GetAll("owner", "")); } diff --git a/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs index bcd91f37..07d15de3 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs @@ -18,6 +18,48 @@ namespace Octokit.Tests.Reactive } } + public class TheGetAllMethod + { + [Fact] + public void EnsuresNonEmptyArguments() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommitsClient(githubClient); + var options = new ApiOptions(); + var request = new CommitRequest(); + + Assert.ThrowsAsync(() => client.GetAll("", "name", request, options).ToTask()); + Assert.ThrowsAsync(() => client.GetAll("owner", "", request, options).ToTask()); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommitsClient(githubClient); + var options = new ApiOptions(); + var request = new CommitRequest(); + + Assert.ThrowsAsync(() => client.GetAll(null, "name", request, options).ToTask()); + Assert.ThrowsAsync(() => client.GetAll("owner", null, request, options).ToTask()); + Assert.ThrowsAsync(() => client.GetAll("owner", "name", null, options).ToTask()); + Assert.ThrowsAsync(() => client.GetAll("owner", "name", request, null).ToTask()); + + } + + [Fact] + public void GetsCorrectUrl() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommitsClient(githubClient); + var options = new ApiOptions(); + var request = new CommitRequest(); + + client.GetAll("fake", "repo", request, options); + githubClient.Received().Repository.Commit.GetAll("fake", "repo", request, options); + } + } + public class TheGetSha1Method { [Fact] diff --git a/Octokit/Clients/AssigneesClient.cs b/Octokit/Clients/AssigneesClient.cs index 58ca8666..0cd692c7 100644 --- a/Octokit/Clients/AssigneesClient.cs +++ b/Octokit/Clients/AssigneesClient.cs @@ -66,8 +66,7 @@ namespace Octokit try { - var response = await Connection.Get(ApiUrls.CheckAssignee(owner, name, assignee), null, null) - .ConfigureAwait(false); + var response = await Connection.Get(ApiUrls.CheckAssignee(owner, name, assignee), null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) diff --git a/Octokit/Clients/AuthorizationsClient.cs b/Octokit/Clients/AuthorizationsClient.cs index c94a7604..4d6e0340 100644 --- a/Octokit/Clients/AuthorizationsClient.cs +++ b/Octokit/Clients/AuthorizationsClient.cs @@ -320,10 +320,7 @@ namespace Octokit { var endpoint = ApiUrls.AuthorizationsForClient(clientId); - return await ApiConnection.Put( - endpoint, - requestData, - twoFactorAuthenticationCode); + return await ApiConnection.Put(endpoint, requestData, twoFactorAuthenticationCode).ConfigureAwait(false); } catch (AuthorizationException e) { @@ -341,15 +338,13 @@ namespace Octokit /// Client ID of the OAuth application for the token /// The OAuth token to check /// The valid . - public async Task CheckApplicationAuthentication(string clientId, string accessToken) + public Task CheckApplicationAuthentication(string clientId, string accessToken) { Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId"); Ensure.ArgumentNotNullOrEmptyString(accessToken, "accessToken"); var endpoint = ApiUrls.ApplicationAuthorization(clientId, accessToken); - return await ApiConnection.Get( - endpoint, - null); + return ApiConnection.Get(endpoint, null); } /// @@ -362,15 +357,14 @@ namespace Octokit /// ClientID of the OAuth application for the token /// The OAuth token to reset /// The valid with a new OAuth token - public async Task ResetApplicationAuthentication(string clientId, string accessToken) + public Task ResetApplicationAuthentication(string clientId, string accessToken) { Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId"); Ensure.ArgumentNotNullOrEmptyString(accessToken, "accessToken"); var requestData = new { }; - return await ApiConnection.Post( - ApiUrls.ApplicationAuthorization(clientId, accessToken), requestData); + return ApiConnection.Post(ApiUrls.ApplicationAuthorization(clientId, accessToken), requestData); } /// diff --git a/Octokit/Clients/Enterprise/EnterpriseAdminStatsClient.cs b/Octokit/Clients/Enterprise/EnterpriseAdminStatsClient.cs index 11e5f9fb..cdbbd7de 100644 --- a/Octokit/Clients/Enterprise/EnterpriseAdminStatsClient.cs +++ b/Octokit/Clients/Enterprise/EnterpriseAdminStatsClient.cs @@ -21,12 +21,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsIssues() + public Task GetStatisticsIssues() { var endpoint = ApiUrls.EnterpriseAdminStatsIssues(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -36,12 +35,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsHooks() + public Task GetStatisticsHooks() { var endpoint = ApiUrls.EnterpriseAdminStatsHooks(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -51,12 +49,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsMilestones() + public Task GetStatisticsMilestones() { var endpoint = ApiUrls.EnterpriseAdminStatsMilestones(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -66,12 +63,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsOrgs() + public Task GetStatisticsOrgs() { var endpoint = ApiUrls.EnterpriseAdminStatsOrgs(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -81,12 +77,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsComments() + public Task GetStatisticsComments() { var endpoint = ApiUrls.EnterpriseAdminStatsComments(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -96,12 +91,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsPages() + public Task GetStatisticsPages() { var endpoint = ApiUrls.EnterpriseAdminStatsPages(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -111,12 +105,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsUsers() + public Task GetStatisticsUsers() { var endpoint = ApiUrls.EnterpriseAdminStatsUsers(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -126,12 +119,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsGists() + public Task GetStatisticsGists() { var endpoint = ApiUrls.EnterpriseAdminStatsGists(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -141,12 +133,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsPulls() + public Task GetStatisticsPulls() { var endpoint = ApiUrls.EnterpriseAdminStatsPulls(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -156,12 +147,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The statistics. - public async Task GetStatisticsRepos() + public Task GetStatisticsRepos() { var endpoint = ApiUrls.EnterpriseAdminStatsRepos(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } /// @@ -171,12 +161,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/admin_stats/#get-statistics /// /// The collection of statistics. - public async Task GetStatisticsAll() + public Task GetStatisticsAll() { var endpoint = ApiUrls.EnterpriseAdminStatsAll(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } } } diff --git a/Octokit/Clients/Enterprise/EnterpriseLdapClient.cs b/Octokit/Clients/Enterprise/EnterpriseLdapClient.cs index 1980dc6f..16c8987f 100644 --- a/Octokit/Clients/Enterprise/EnterpriseLdapClient.cs +++ b/Octokit/Clients/Enterprise/EnterpriseLdapClient.cs @@ -48,7 +48,7 @@ namespace Octokit var endpoint = ApiUrls.EnterpriseLdapUserSync(userName); - var response = await Connection.Post(endpoint); + var response = await Connection.Post(endpoint).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.Created) { throw new ApiException("Invalid Status Code returned. Expected a 201", response.HttpResponse.StatusCode); @@ -90,7 +90,7 @@ namespace Octokit var endpoint = ApiUrls.EnterpriseLdapTeamSync(teamId); - var response = await Connection.Post(endpoint); + var response = await Connection.Post(endpoint).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.Created) { throw new ApiException("Invalid Status Code returned. Expected a 201", response.HttpResponse.StatusCode); diff --git a/Octokit/Clients/Enterprise/EnterpriseLicenseClient.cs b/Octokit/Clients/Enterprise/EnterpriseLicenseClient.cs index 46638883..4efab54b 100644 --- a/Octokit/Clients/Enterprise/EnterpriseLicenseClient.cs +++ b/Octokit/Clients/Enterprise/EnterpriseLicenseClient.cs @@ -21,12 +21,11 @@ namespace Octokit /// https://developer.github.com/v3/enterprise/license/#get-license-information /// /// The statistics. - public async Task Get() + public Task Get() { var endpoint = ApiUrls.EnterpriseLicense(); - return await ApiConnection.Get(endpoint) - .ConfigureAwait(false); + return ApiConnection.Get(endpoint); } } } diff --git a/Octokit/Clients/Enterprise/EnterpriseOrganizationClient.cs b/Octokit/Clients/Enterprise/EnterpriseOrganizationClient.cs index 0848ff8e..22fee148 100644 --- a/Octokit/Clients/Enterprise/EnterpriseOrganizationClient.cs +++ b/Octokit/Clients/Enterprise/EnterpriseOrganizationClient.cs @@ -22,13 +22,13 @@ namespace Octokit /// /// A instance describing the organization to be created /// The created. - public async Task Create(NewOrganization newOrganization) + public Task Create(NewOrganization newOrganization) { Ensure.ArgumentNotNull(newOrganization, "newOrganization"); var endpoint = ApiUrls.EnterpriseOrganization(); - return await ApiConnection.Post(endpoint, newOrganization); + return ApiConnection.Post(endpoint, newOrganization); } } } diff --git a/Octokit/Clients/Enterprise/EnterpriseSearchIndexingClient.cs b/Octokit/Clients/Enterprise/EnterpriseSearchIndexingClient.cs index 2351a2f1..0feea186 100644 --- a/Octokit/Clients/Enterprise/EnterpriseSearchIndexingClient.cs +++ b/Octokit/Clients/Enterprise/EnterpriseSearchIndexingClient.cs @@ -23,15 +23,14 @@ namespace Octokit /// /// A user or organization account /// The message. - public async Task Queue(string owner) + public Task Queue(string owner) { Ensure.ArgumentNotNull(owner, "owner"); var endpoint = ApiUrls.EnterpriseSearchIndexing(); var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}", owner)); - return await ApiConnection.Post(endpoint, target) - .ConfigureAwait(false); + return ApiConnection.Post(endpoint, target); } /// @@ -43,7 +42,7 @@ namespace Octokit /// A user or organization account /// A repository /// The message. - public async Task Queue(string owner, string repository) + public Task Queue(string owner, string repository) { Ensure.ArgumentNotNull(owner, "owner"); Ensure.ArgumentNotNull(repository, "repository"); @@ -51,8 +50,7 @@ namespace Octokit var endpoint = ApiUrls.EnterpriseSearchIndexing(); var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, repository)); - return await ApiConnection.Post(endpoint, target) - .ConfigureAwait(false); + return ApiConnection.Post(endpoint, target); } /// @@ -63,15 +61,14 @@ namespace Octokit /// /// A user or organization account /// The message. - public async Task QueueAll(string owner) + public Task QueueAll(string owner) { Ensure.ArgumentNotNull(owner, "owner"); var endpoint = ApiUrls.EnterpriseSearchIndexing(); var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/*", owner)); - return await ApiConnection.Post(endpoint, target) - .ConfigureAwait(false); + return ApiConnection.Post(endpoint, target); } /// @@ -83,7 +80,7 @@ namespace Octokit /// A user or organization account /// A repository /// The message. - public async Task QueueAllIssues(string owner, string repository) + public Task QueueAllIssues(string owner, string repository) { Ensure.ArgumentNotNull(owner, "owner"); Ensure.ArgumentNotNull(repository, "repository"); @@ -91,8 +88,7 @@ namespace Octokit var endpoint = ApiUrls.EnterpriseSearchIndexing(); var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/{1}/issues", owner, repository)); - return await ApiConnection.Post(endpoint, target) - .ConfigureAwait(false); + return ApiConnection.Post(endpoint, target); } /// @@ -103,15 +99,14 @@ namespace Octokit /// /// A user or organization account /// The message. - public async Task QueueAllIssues(string owner) + public Task QueueAllIssues(string owner) { Ensure.ArgumentNotNull(owner, "owner"); var endpoint = ApiUrls.EnterpriseSearchIndexing(); var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/*/issues", owner)); - return await ApiConnection.Post(endpoint, target) - .ConfigureAwait(false); + return ApiConnection.Post(endpoint, target); } /// @@ -123,7 +118,7 @@ namespace Octokit /// A user or organization account /// A repository /// The message. - public async Task QueueAllCode(string owner, string repository) + public Task QueueAllCode(string owner, string repository) { Ensure.ArgumentNotNull(owner, "owner"); Ensure.ArgumentNotNull(repository, "repository"); @@ -131,8 +126,7 @@ namespace Octokit var endpoint = ApiUrls.EnterpriseSearchIndexing(); var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/{1}/code", owner, repository)); - return await ApiConnection.Post(endpoint, target) - .ConfigureAwait(false); + return ApiConnection.Post(endpoint, target); } /// @@ -143,15 +137,14 @@ namespace Octokit /// /// A user or organization account /// The message. - public async Task QueueAllCode(string owner) + public Task QueueAllCode(string owner) { Ensure.ArgumentNotNull(owner, "owner"); var endpoint = ApiUrls.EnterpriseSearchIndexing(); var target = new SearchIndexTarget(string.Format(CultureInfo.InvariantCulture, "{0}/*/code", owner)); - return await ApiConnection.Post(endpoint, target) - .ConfigureAwait(false); + return ApiConnection.Post(endpoint, target); } } } diff --git a/Octokit/Clients/EventsClient.cs b/Octokit/Clients/EventsClient.cs index 65e420f0..a1586ca2 100644 --- a/Octokit/Clients/EventsClient.cs +++ b/Octokit/Clients/EventsClient.cs @@ -29,7 +29,22 @@ namespace Octokit /// All the public s for the particular user. public Task> GetAll() { - return ApiConnection.GetAll(ApiUrls.Events()); + return GetAll(ApiOptions.None); + } + + /// + /// Gets all the public events + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events + /// + /// Options for changing the API response + /// All the public s for the particular user. + public Task> GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Events(),options); } /// @@ -46,7 +61,26 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.IssuesEvents(owner, name)); + return GetAllForRepository(owner,name,ApiOptions.None); + } + + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + public Task> GetAllForRepository(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.IssuesEvents(owner, name),options); } /// @@ -63,7 +97,26 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.NetworkEvents(owner, name)); + return GetAllForRepositoryNetwork(owner,name,ApiOptions.None); + } + + /// + /// Gets all the events for a given repository network + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository network. + public Task> GetAllForRepositoryNetwork(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.NetworkEvents(owner, name), options); } /// @@ -78,7 +131,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return ApiConnection.GetAll(ApiUrls.OrganizationEvents(organization)); + return GetAllForOrganization(organization, ApiOptions.None); + } + + /// + /// Gets all the events for a given organization + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization + /// + /// The name of the organization + /// Options for changing the API response + /// All the s for the particular organization. + public Task> GetAllForOrganization(string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.OrganizationEvents(organization), options); } /// @@ -93,7 +163,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.ReceivedEvents(user)); + return GetAllUserReceived(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + public Task> GetAllUserReceived(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.ReceivedEvents(user), options); } /// @@ -108,7 +195,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.ReceivedEvents(user, true)); + return GetAllUserReceivedPublic(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + public Task> GetAllUserReceivedPublic(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.ReceivedEvents(user, true),options); } /// @@ -123,7 +227,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.PerformedEvents(user)); + return GetAllUserPerformed(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has performed. + public Task> GetAllUserPerformed(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.PerformedEvents(user),options); } /// @@ -138,7 +259,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.PerformedEvents(user, true)); + return GetAllUserPerformedPublic(user, ApiOptions.None); + } + + /// + /// Gets all the public events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the public s that a particular user has performed. + public Task> GetAllUserPerformedPublic(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.PerformedEvents(user, true), options); } /// @@ -155,7 +293,26 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return ApiConnection.GetAll(ApiUrls.OrganizationEvents(user, organization)); + return GetAllForAnOrganization(user, organization, ApiOptions.None); + } + + /// + /// Gets all the events that are associated with an organization. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-for-an-organization + /// + /// The login of the user + /// The name of the organization + /// Options for changing the API response + /// All the public s that are associated with an organization. + public Task> GetAllForAnOrganization(string user, string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.OrganizationEvents(user, organization),options); } } } diff --git a/Octokit/Clients/FollowersClient.cs b/Octokit/Clients/FollowersClient.cs index 5a6dcd44..b2cfe95f 100644 --- a/Octokit/Clients/FollowersClient.cs +++ b/Octokit/Clients/FollowersClient.cs @@ -88,8 +88,7 @@ namespace Octokit try { - var response = await Connection.Get(ApiUrls.IsFollowing(following), null, null) - .ConfigureAwait(false); + var response = await Connection.Get(ApiUrls.IsFollowing(following), null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) @@ -114,8 +113,7 @@ namespace Octokit try { - var response = await Connection.Get(ApiUrls.IsFollowing(login, following), null, null) - .ConfigureAwait(false); + var response = await Connection.Get(ApiUrls.IsFollowing(login, following), null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) @@ -139,8 +137,7 @@ namespace Octokit try { var requestData = new { }; - var response = await Connection.Put(ApiUrls.IsFollowing(login), requestData) - .ConfigureAwait(false); + var response = await Connection.Put(ApiUrls.IsFollowing(login), requestData).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.NoContent) { throw new ApiException("Invalid Status Code returned. Expected a 204", response.HttpResponse.StatusCode); diff --git a/Octokit/Clients/GistCommentsClient.cs b/Octokit/Clients/GistCommentsClient.cs index 47487159..23eccda0 100644 --- a/Octokit/Clients/GistCommentsClient.cs +++ b/Octokit/Clients/GistCommentsClient.cs @@ -39,7 +39,24 @@ namespace Octokit /// Task{IReadOnlyList{GistComment}}. public Task> GetAllForGist(string gistId) { - return ApiConnection.GetAll(ApiUrls.GistComments(gistId)); + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + + return GetAllForGist(gistId, ApiOptions.None); + } + + /// + /// Gets all comments for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist + /// The id of the gist + /// Options for changing the API response + /// Task{IReadOnlyList{GistComment}}. + public Task> GetAllForGist(string gistId, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.GistComments(gistId), options); } /// diff --git a/Octokit/Clients/GistsClient.cs b/Octokit/Clients/GistsClient.cs index 87807656..929d08e2 100644 --- a/Octokit/Clients/GistsClient.cs +++ b/Octokit/Clients/GistsClient.cs @@ -289,8 +289,7 @@ namespace Octokit try { - var response = await Connection.Get(ApiUrls.StarGist(id), null, null) - .ConfigureAwait(false); + var response = await Connection.Get(ApiUrls.StarGist(id), null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) diff --git a/Octokit/Clients/IEventsClient.cs b/Octokit/Clients/IEventsClient.cs index ec148815..06cb5ef6 100644 --- a/Octokit/Clients/IEventsClient.cs +++ b/Octokit/Clients/IEventsClient.cs @@ -21,6 +21,16 @@ namespace Octokit [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] Task> GetAll(); + /// + /// Gets all the public events + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events + /// + /// Options for changing the API response + /// All the public s for the particular user. + Task> GetAll(ApiOptions options); + /// /// Gets all the events for a given repository /// @@ -32,6 +42,20 @@ namespace Octokit /// All the s for the particular repository. Task> GetAllForRepository(string owner, string name); + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + Task> GetAllForRepository(string owner, string name, ApiOptions options); + + + /// /// Gets all the events for a given repository network /// @@ -43,6 +67,18 @@ namespace Octokit /// All the s for the particular repository network. Task> GetAllForRepositoryNetwork(string owner, string name); + /// + /// Gets all the events for a given repository network + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository network. + Task> GetAllForRepositoryNetwork(string owner, string name,ApiOptions options); + /// /// Gets all the events for a given organization /// @@ -53,6 +89,17 @@ namespace Octokit /// All the s for the particular organization. Task> GetAllForOrganization(string organization); + /// + /// Gets all the events for a given organization + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization + /// + /// The name of the organization + /// Options for changing the API response + /// All the s for the particular organization. + Task> GetAllForOrganization(string organization, ApiOptions options); + /// /// Gets all the events that have been received by a given user. /// @@ -63,6 +110,17 @@ namespace Octokit /// All the s that a particular user has received. Task> GetAllUserReceived(string user); + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + Task> GetAllUserReceived(string user, ApiOptions options); + /// /// Gets all the events that have been received by a given user. /// @@ -73,6 +131,17 @@ namespace Octokit /// All the s that a particular user has received. Task> GetAllUserReceivedPublic(string user); + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + Task> GetAllUserReceivedPublic(string user, ApiOptions options); + /// /// Gets all the events that have been performed by a given user. /// @@ -83,6 +152,17 @@ namespace Octokit /// All the s that a particular user has performed. Task> GetAllUserPerformed(string user); + /// + /// Gets all the events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has performed. + Task> GetAllUserPerformed(string user, ApiOptions options); + /// /// Gets all the public events that have been performed by a given user. /// @@ -93,6 +173,17 @@ namespace Octokit /// All the public s that a particular user has performed. Task> GetAllUserPerformedPublic(string user); + /// + /// Gets all the public events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the public s that a particular user has performed. + Task> GetAllUserPerformedPublic(string user, ApiOptions options); + /// /// Gets all the events that are associated with an organization. /// @@ -103,5 +194,17 @@ namespace Octokit /// The name of the organization /// All the public s that are associated with an organization. Task> GetAllForAnOrganization(string user, string organization); + + /// + /// Gets all the events that are associated with an organization. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-for-an-organization + /// + /// The login of the user + /// The name of the organization + /// Options for changing the API response + /// All the public s that are associated with an organization. + Task> GetAllForAnOrganization(string user, string organization, ApiOptions options); } } \ No newline at end of file diff --git a/Octokit/Clients/IGistCommentsClient.cs b/Octokit/Clients/IGistCommentsClient.cs index bf91680c..30867774 100644 --- a/Octokit/Clients/IGistCommentsClient.cs +++ b/Octokit/Clients/IGistCommentsClient.cs @@ -31,6 +31,15 @@ namespace Octokit /// Task{IReadOnlyList{GistComment}}. Task> GetAllForGist(string gistId); + /// + /// Gets all comments for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist + /// The id of the gist + /// Options for changing the API response + /// Task{IReadOnlyList{GistComment}}. + Task> GetAllForGist(string gistId, ApiOptions options); + /// /// Creates a comment for the gist with the specified id. /// diff --git a/Octokit/Clients/IRepositoryCommitsClient.cs b/Octokit/Clients/IRepositoryCommitsClient.cs index bd486192..33c7b877 100644 --- a/Octokit/Clients/IRepositoryCommitsClient.cs +++ b/Octokit/Clients/IRepositoryCommitsClient.cs @@ -42,6 +42,15 @@ namespace Octokit /// Task> GetAll(string owner, string name); + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// + Task> GetAll(string owner, string name, ApiOptions options); + /// /// Gets all commits for a given repository /// @@ -51,6 +60,15 @@ namespace Octokit /// Task> GetAll(string owner, string name, CommitRequest request); + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Used to filter list of commits returned + /// Options for changing the API response + /// + Task> GetAll(string owner, string name, CommitRequest request, ApiOptions options); /// /// Get the SHA-1 of a commit reference /// diff --git a/Octokit/Clients/MiscellaneousClient.cs b/Octokit/Clients/MiscellaneousClient.cs index c9f03d54..cf6242b9 100644 --- a/Octokit/Clients/MiscellaneousClient.cs +++ b/Octokit/Clients/MiscellaneousClient.cs @@ -38,8 +38,7 @@ namespace Octokit public async Task> GetAllEmojis() { var endpoint = new Uri("emojis", UriKind.Relative); - var response = await _connection.Get>(endpoint, null, null) - .ConfigureAwait(false); + var response = await _connection.Get>(endpoint, null, null).ConfigureAwait(false); return new ReadOnlyCollection( response.Body.Select(kvp => new Emoji(kvp.Key, new Uri(kvp.Value))).ToArray()); } @@ -53,8 +52,7 @@ namespace Octokit public async Task RenderRawMarkdown(string markdown) { var endpoint = new Uri("markdown/raw", UriKind.Relative); - var response = await _connection.Post(endpoint, markdown, "text/html", "text/plain") - .ConfigureAwait(false); + var response = await _connection.Post(endpoint, markdown, "text/html", "text/plain").ConfigureAwait(false); return response.Body; } @@ -67,8 +65,7 @@ namespace Octokit public async Task RenderArbitraryMarkdown(NewArbitraryMarkdown markdown) { var endpoint = new Uri("markdown", UriKind.Relative); - var response = await _connection.Post(endpoint, markdown, "text/html", "text/plain") - .ConfigureAwait(false); + var response = await _connection.Post(endpoint, markdown, "text/html", "text/plain").ConfigureAwait(false); return response.Body; } @@ -80,8 +77,7 @@ namespace Octokit { var endpoint = new Uri("gitignore/templates", UriKind.Relative); - var response = await _connection.Get(endpoint, null, null) - .ConfigureAwait(false); + var response = await _connection.Get(endpoint, null, null).ConfigureAwait(false); return new ReadOnlyCollection(response.Body); } @@ -96,8 +92,7 @@ namespace Octokit var endpoint = new Uri("gitignore/templates/" + Uri.EscapeUriString(templateName), UriKind.Relative); - var response = await _connection.Get(endpoint, null, null) - .ConfigureAwait(false); + var response = await _connection.Get(endpoint, null, null).ConfigureAwait(false); return response.Body; } @@ -111,8 +106,7 @@ namespace Octokit { var endpoint = new Uri("licenses", UriKind.Relative); - var response = await _connection.Get(endpoint, null, AcceptHeaders.LicensesApiPreview) - .ConfigureAwait(false); + var response = await _connection.Get(endpoint, null, AcceptHeaders.LicensesApiPreview).ConfigureAwait(false); return new ReadOnlyCollection(response.Body); } @@ -125,8 +119,7 @@ namespace Octokit { var endpoint = new Uri("licenses/" + Uri.EscapeUriString(key), UriKind.Relative); - var response = await _connection.Get(endpoint, null, AcceptHeaders.LicensesApiPreview) - .ConfigureAwait(false); + var response = await _connection.Get(endpoint, null, AcceptHeaders.LicensesApiPreview).ConfigureAwait(false); return response.Body; } diff --git a/Octokit/Clients/OAuthClient.cs b/Octokit/Clients/OAuthClient.cs index d283b5a4..e6e17fb8 100644 --- a/Octokit/Clients/OAuthClient.cs +++ b/Octokit/Clients/OAuthClient.cs @@ -62,7 +62,7 @@ namespace Octokit var body = new FormUrlEncodedContent(request.ToParametersDictionary()); - var response = await connection.Post(endPoint, body, "application/json", null, hostAddress); + var response = await connection.Post(endPoint, body, "application/json", null, hostAddress).ConfigureAwait(false); return response.Body; } } diff --git a/Octokit/Clients/OrganizationMembersClient.cs b/Octokit/Clients/OrganizationMembersClient.cs index 02eb939a..3f24c984 100644 --- a/Octokit/Clients/OrganizationMembersClient.cs +++ b/Octokit/Clients/OrganizationMembersClient.cs @@ -211,8 +211,7 @@ namespace Octokit try { - var response = await Connection.Get(ApiUrls.CheckMember(org, user), null, null) - .ConfigureAwait(false); + var response = await Connection.Get(ApiUrls.CheckMember(org, user), null, null).ConfigureAwait(false); var statusCode = response.HttpResponse.StatusCode; if (statusCode != HttpStatusCode.NotFound && statusCode != HttpStatusCode.NoContent @@ -245,8 +244,7 @@ namespace Octokit try { - var response = await Connection.Get(ApiUrls.CheckMemberPublic(org, user), null, null) - .ConfigureAwait(false); + var response = await Connection.Get(ApiUrls.CheckMemberPublic(org, user), null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) @@ -294,8 +292,7 @@ namespace Octokit try { var requestData = new { }; - var response = await Connection.Put(ApiUrls.OrganizationMembership(org, user), requestData) - .ConfigureAwait(false); + var response = await Connection.Put(ApiUrls.OrganizationMembership(org, user), requestData).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.NoContent) { throw new ApiException("Invalid Status Code returned. Expected a 204", response.HttpResponse.StatusCode); diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs index 5d8363b2..8db0925b 100644 --- a/Octokit/Clients/PullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -93,7 +93,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - var response = await ApiConnection.Connection.Post(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); + var endpoint = ApiUrls.PullRequestReviewComments(owner, name, number); + var response = await ApiConnection.Connection.Post(endpoint, comment, null, null).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.Created) { @@ -118,7 +119,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - var response = await ApiConnection.Connection.Post(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); + var endpoint = ApiUrls.PullRequestReviewComments(owner, name, number); + var response = await ApiConnection.Connection.Post(endpoint, comment, null, null).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.Created) { diff --git a/Octokit/Clients/PullRequestsClient.cs b/Octokit/Clients/PullRequestsClient.cs index 85ffe16f..c8c33478 100644 --- a/Octokit/Clients/PullRequestsClient.cs +++ b/Octokit/Clients/PullRequestsClient.cs @@ -118,7 +118,8 @@ namespace Octokit try { - return await ApiConnection.Put(ApiUrls.MergePullRequest(owner, name, number), mergePullRequest); + var endpoint = ApiUrls.MergePullRequest(owner, name, number); + return await ApiConnection.Put(endpoint, mergePullRequest).ConfigureAwait(false); } catch (ApiException ex) { @@ -151,8 +152,8 @@ namespace Octokit try { - var response = await Connection.Get(ApiUrls.MergePullRequest(owner, name, number), null, null) - .ConfigureAwait(false); + var endpoint = ApiUrls.MergePullRequest(owner, name, number); + var response = await Connection.Get(endpoint, null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index af46fc91..db0d41d0 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -57,8 +57,7 @@ namespace Octokit try { - var response = await Connection.Get(endpoint, null, null) - .ConfigureAwait(false); + var response = await Connection.Get(endpoint, null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 41af07ae..dfb3806e 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -87,7 +87,7 @@ namespace Octokit { try { - return await ApiConnection.Post(url, newRepository); + return await ApiConnection.Post(url, newRepository).ConfigureAwait(false); } catch (ApiValidationException e) { @@ -518,9 +518,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var data = await ApiConnection - .Get>(ApiUrls.RepositoryLanguages(owner, name)) - .ConfigureAwait(false); + var endpoint = ApiUrls.RepositoryLanguages(owner, name); + var data = await ApiConnection.Get>(endpoint).ConfigureAwait(false); return new ReadOnlyCollection( data.Select(kvp => new RepositoryLanguage(kvp.Key, kvp.Value)).ToList()); diff --git a/Octokit/Clients/RepositoryCommitsClient.cs b/Octokit/Clients/RepositoryCommitsClient.cs index e5fa9613..f2ea2ccd 100644 --- a/Octokit/Clients/RepositoryCommitsClient.cs +++ b/Octokit/Clients/RepositoryCommitsClient.cs @@ -60,9 +60,27 @@ namespace Octokit /// public Task> GetAll(string owner, string name) { - return GetAll(owner, name, new CommitRequest()); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return GetAll(owner, name, new CommitRequest(), ApiOptions.None); } + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// + public Task> GetAll(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return GetAll(owner, name, new CommitRequest(), options); + } + /// /// Gets all commits for a given repository /// @@ -76,8 +94,24 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); - return _apiConnection.GetAll(ApiUrls.RepositoryCommits(owner, name), - request.ToParametersDictionary()); + return GetAll(owner, name, request, ApiOptions.None); + } + + /// + /// Gets all commits for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Used to filter list of commits returned + /// Options for changing the API response + /// + public Task> GetAll(string owner, string name, CommitRequest request, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(request, "request"); + + return _apiConnection.GetAll(ApiUrls.RepositoryCommits(owner, name), request.ToParametersDictionary(), options); } /// diff --git a/Octokit/Clients/RepositoryContentsClient.cs b/Octokit/Clients/RepositoryContentsClient.cs index cc63f00e..fbd1d850 100644 --- a/Octokit/Clients/RepositoryContentsClient.cs +++ b/Octokit/Clients/RepositoryContentsClient.cs @@ -259,7 +259,7 @@ namespace Octokit var endpoint = ApiUrls.RepositoryArchiveLink(owner, name, archiveFormat, reference); - var response = await Connection.Get(endpoint, timeout); + var response = await Connection.Get(endpoint, timeout).ConfigureAwait(false); return response.Body; } diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index 1ed20dcd..132ca2dc 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -189,9 +189,7 @@ namespace Octokit try { - var response = await Connection.Get(ApiUrls.Starred(owner, name), null, null) - .ConfigureAwait(false); - + var response = await Connection.Get(ApiUrls.Starred(owner, name), null, null).ConfigureAwait(false); return response.HttpResponse.StatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) @@ -213,9 +211,7 @@ namespace Octokit try { - var response = await Connection.Put(ApiUrls.Starred(owner, name), null, null) - .ConfigureAwait(false); - + var response = await Connection.Put(ApiUrls.Starred(owner, name), null, null).ConfigureAwait(false); return response.HttpResponse.StatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) @@ -237,9 +233,7 @@ namespace Octokit try { - var statusCode = await Connection.Delete(ApiUrls.Starred(owner, name)) - .ConfigureAwait(false); - + var statusCode = await Connection.Delete(ApiUrls.Starred(owner, name)).ConfigureAwait(false); return statusCode == HttpStatusCode.NoContent; } catch (NotFoundException) diff --git a/Octokit/Clients/StatisticsClient.cs b/Octokit/Clients/StatisticsClient.cs index f63a94ec..d55207d2 100644 --- a/Octokit/Clients/StatisticsClient.cs +++ b/Octokit/Clients/StatisticsClient.cs @@ -39,13 +39,13 @@ namespace Octokit /// The name of the repository /// A token used to cancel this potentially long running request /// A list of - public async Task> GetContributors(string owner, string repositoryName, CancellationToken cancellationToken) + public Task> GetContributors(string owner, string repositoryName, CancellationToken cancellationToken) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "repos/{0}/{1}/stats/contributors".FormatUri(owner, repositoryName); - return await ApiConnection.GetQueuedOperation(endpoint, cancellationToken); + return ApiConnection.GetQueuedOperation(endpoint, cancellationToken); } /// @@ -72,7 +72,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "repos/{0}/{1}/stats/commit_activity".FormatUri(owner, repositoryName); - var activity = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken); + var activity = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); return new CommitActivity(activity); } @@ -100,7 +100,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "repos/{0}/{1}/stats/code_frequency".FormatUri(owner, repositoryName); - var rawFrequencies = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken); + var rawFrequencies = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); return new CodeFrequency(rawFrequencies); } @@ -128,7 +128,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "repos/{0}/{1}/stats/participation".FormatUri(owner, repositoryName); - var result = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken); + var result = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); return result.FirstOrDefault(); } @@ -156,7 +156,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); var endpoint = "repos/{0}/{1}/stats/punch_card".FormatUri(owner, repositoryName); - var punchCardData = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken); + var punchCardData = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); return new PunchCard(punchCardData); } } diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 67376b42..ae721871 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -137,7 +137,7 @@ namespace Octokit try { - response = await ApiConnection.Get>(endpoint); + response = await ApiConnection.Get>(endpoint).ConfigureAwait(false); } catch (NotFoundException) { @@ -208,7 +208,7 @@ namespace Octokit try { - response = await ApiConnection.Put>(endpoint, RequestBody.Empty); + response = await ApiConnection.Put>(endpoint, RequestBody.Empty).ConfigureAwait(false); } catch (NotFoundException) { @@ -242,7 +242,7 @@ namespace Octokit try { - var httpStatusCode = await ApiConnection.Connection.Delete(endpoint); + var httpStatusCode = await ApiConnection.Connection.Delete(endpoint).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } @@ -268,7 +268,7 @@ namespace Octokit try { - var response = await ApiConnection.Connection.GetResponse(endpoint); + var response = await ApiConnection.Connection.GetResponse(endpoint).ConfigureAwait(false); return response.HttpResponse.StatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) @@ -333,7 +333,7 @@ namespace Octokit try { - var httpStatusCode = await ApiConnection.Connection.Put(endpoint); + var httpStatusCode = await ApiConnection.Connection.Put(endpoint).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) @@ -356,7 +356,7 @@ namespace Octokit try { - var httpStatusCode = await ApiConnection.Connection.Delete(endpoint); + var httpStatusCode = await ApiConnection.Connection.Delete(endpoint).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } @@ -385,7 +385,7 @@ namespace Octokit try { - var response = await ApiConnection.Connection.GetResponse(endpoint); + var response = await ApiConnection.Connection.GetResponse(endpoint).ConfigureAwait(false); return response.HttpResponse.StatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) diff --git a/Octokit/Clients/UserAdministrationClient.cs b/Octokit/Clients/UserAdministrationClient.cs index 1b7a15e6..7245a8ad 100644 --- a/Octokit/Clients/UserAdministrationClient.cs +++ b/Octokit/Clients/UserAdministrationClient.cs @@ -95,7 +95,7 @@ namespace Octokit var endpoint = ApiUrls.UserAdministrationAuthorization(login); - var response = ((HttpStatusCode)await Connection.Delete(endpoint)); + var response = await Connection.Delete(endpoint).ConfigureAwait(false); if (response != HttpStatusCode.NoContent) { throw new ApiException("Invalid Status Code returned. Expected a 204", response); @@ -196,7 +196,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(login, "login"); var endpoint = ApiUrls.UserAdministration(login); - var response = ((HttpStatusCode)await Connection.Delete(endpoint)); + var response = await Connection.Delete(endpoint).ConfigureAwait(false); if (response != HttpStatusCode.NoContent) { throw new ApiException("Invalid Status Code returned. Expected a 204", response); @@ -219,7 +219,7 @@ namespace Octokit Ensure.ArgumentNotNull(keyId, "keyId"); var endpoint = ApiUrls.UserAdministrationPublicKeys(keyId); - var response = ((HttpStatusCode)await Connection.Delete(endpoint)); + var response = await Connection.Delete(endpoint).ConfigureAwait(false); if (response != HttpStatusCode.NoContent) { throw new ApiException("Invalid Status Code returned. Expected a 204", response); diff --git a/Octokit/Clients/WatchedClient.cs b/Octokit/Clients/WatchedClient.cs index fbc23c97..e406696a 100644 --- a/Octokit/Clients/WatchedClient.cs +++ b/Octokit/Clients/WatchedClient.cs @@ -77,8 +77,8 @@ namespace Octokit try { - var subscription = await ApiConnection.Get(ApiUrls.Watched(owner, name)) - .ConfigureAwait(false); + var endpoint = ApiUrls.Watched(owner, name); + var subscription = await ApiConnection.Get(endpoint).ConfigureAwait(false); return subscription != null; } @@ -117,8 +117,8 @@ namespace Octokit try { - var statusCode = await Connection.Delete(ApiUrls.Watched(owner, name)) - .ConfigureAwait(false); + var endpoint = ApiUrls.Watched(owner, name); + var statusCode = await Connection.Delete(endpoint).ConfigureAwait(false); return statusCode == HttpStatusCode.NoContent; } diff --git a/Octokit/Exceptions/LegalRestrictionException.cs b/Octokit/Exceptions/LegalRestrictionException.cs new file mode 100644 index 00000000..df115d4d --- /dev/null +++ b/Octokit/Exceptions/LegalRestrictionException.cs @@ -0,0 +1,73 @@ +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Runtime.Serialization; + +namespace Octokit +{ + /// + /// Represents a HTTP 451 - Unavailable For Legal Reasons response returned from the API. + /// This will returned if GitHub has been asked to takedown the requested resource due to + /// a DMCA takedown. + /// +#if !NETFX_CORE + [Serializable] +#endif + [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", + Justification = "These exceptions are specific to the GitHub API and not general purpose exceptions")] + public class LegalRestrictionException : ApiException + { + public override string Message + { + get { return ApiErrorMessageSafe ?? "Resource taken down due to a DMCA notice."; } + } + + /// + /// Constructs an instance of LegalRestrictionException + /// + /// The HTTP payload from the server + public LegalRestrictionException(IResponse response) : this(response, null) + { + } + + /// + /// Constructs an instance of LegalRestrictionException + /// + /// The exception message + /// The http status code returned by the response + public LegalRestrictionException(string message, HttpStatusCode statusCode) : base(message, statusCode) + { + } + + /// + /// Constructs an instance of LegalRestrictionException + /// + /// The HTTP payload from the server + /// The inner exception + public LegalRestrictionException(IResponse response, Exception innerException) + : base(response, innerException) + { + Debug.Assert(response != null && response.StatusCode == (HttpStatusCode)451, + "LegalRestrictionException created with wrong status code"); + } + +#if !NETFX_CORE + /// + /// Constructs an instance of LegalRestrictionException + /// + /// + /// The that holds the + /// serialized object data about the exception being thrown. + /// + /// + /// The that contains + /// contextual information about the source or destination. + /// + protected LegalRestrictionException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } +#endif + } +} diff --git a/Octokit/Helpers/AuthorizationExtensions.cs b/Octokit/Helpers/AuthorizationExtensions.cs index 0d115ab9..1a490e8f 100644 --- a/Octokit/Helpers/AuthorizationExtensions.cs +++ b/Octokit/Helpers/AuthorizationExtensions.cs @@ -41,8 +41,7 @@ namespace Octokit TwoFactorRequiredException twoFactorException = null; try { - return await authorizationsClient.GetOrCreateApplicationAuthentication(clientId, clientSecret, newAuthorization) - .ConfigureAwait(false); + return await authorizationsClient.GetOrCreateApplicationAuthentication(clientId, clientSecret, newAuthorization).ConfigureAwait(false); } catch (TwoFactorRequiredException exception) { diff --git a/Octokit/Helpers/ReferenceExtensions.cs b/Octokit/Helpers/ReferenceExtensions.cs index 93bd4f70..b7220a9a 100644 --- a/Octokit/Helpers/ReferenceExtensions.cs +++ b/Octokit/Helpers/ReferenceExtensions.cs @@ -29,7 +29,8 @@ namespace Octokit.Helpers throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The specified branch name '{0}' appears to be a ref name and not a branch name because it starts with the string 'refs/heads'. Either specify just the branch name or use the Create method if you need to specify the full ref name", branchName), "branchName"); } - return await referencesClient.Create(owner, name, new NewReference("refs/heads/" + branchName, baseReference.Object.Sha)); + var newReference = new NewReference("refs/heads/" + branchName, baseReference.Object.Sha); + return await referencesClient.Create(owner, name, newReference).ConfigureAwait(false); } /// @@ -50,8 +51,9 @@ namespace Octokit.Helpers throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The specified branch name '{0}' appears to be a ref name and not a branch name because it starts with the string 'refs/heads'. Either specify just the branch name or use the Create method if you need to specify the full ref name", branchName), "branchName"); } - var baseBranch = await referencesClient.Get(owner, name, "heads/master"); - return await referencesClient.Create(owner, name, new NewReference("refs/heads/" + branchName, baseBranch.Object.Sha)); + var baseBranch = await referencesClient.Get(owner, name, "heads/master").ConfigureAwait(false); + var newReference = new NewReference("refs/heads/" + branchName, baseBranch.Object.Sha); + return await referencesClient.Create(owner, name, newReference).ConfigureAwait(false); } } } diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index a08a8aeb..3838e555 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -171,8 +171,7 @@ namespace Octokit { Ensure.ArgumentNotNull(uri, "uri"); - return _pagination.GetAllPages(async () => await GetPage(uri, parameters, accepts) - .ConfigureAwait(false), uri); + return _pagination.GetAllPages(async () => await GetPage(uri, parameters, accepts).ConfigureAwait(false), uri); } public Task> GetAll(Uri uri, IDictionary parameters, string accepts, ApiOptions options) @@ -182,8 +181,7 @@ namespace Octokit parameters = Pagination.Setup(parameters, options); - return _pagination.GetAllPages(async () => await GetPage(uri, parameters, accepts, options) - .ConfigureAwait(false), uri); + return _pagination.GetAllPages(async () => await GetPage(uri, parameters, accepts, options).ConfigureAwait(false), uri); } /// @@ -259,11 +257,7 @@ namespace Octokit Ensure.ArgumentNotNull(uri, "uri"); Ensure.ArgumentNotNull(data, "data"); - var response = await Connection.Post( - uri, - data, - accepts, - contentType).ConfigureAwait(false); + var response = await Connection.Post(uri, data, accepts, contentType).ConfigureAwait(false); return response.Body; } @@ -284,12 +278,7 @@ namespace Octokit Ensure.ArgumentNotNull(data, "data"); Ensure.ArgumentNotNull(twoFactorAuthenticationCode, "twoFactorAuthenticationCode"); - var response = await Connection.Post( - uri, - data, - accepts, - contentType, - twoFactorAuthenticationCode).ConfigureAwait(false); + var response = await Connection.Post(uri, data, accepts, contentType, twoFactorAuthenticationCode).ConfigureAwait(false); return response.Body; } @@ -299,12 +288,7 @@ namespace Octokit Ensure.ArgumentNotNull(uri, "uri"); Ensure.ArgumentNotNull(data, "data"); - var response = await Connection.Post( - uri, - data, - accepts, - contentType, - timeout).ConfigureAwait(false); + var response = await Connection.Post(uri, data, accepts, contentType, timeout).ConfigureAwait(false); return response.Body; } @@ -494,7 +478,7 @@ namespace Octokit public async Task GetRedirect(Uri uri) { Ensure.ArgumentNotNull(uri, "uri"); - var response = await Connection.GetRedirect(uri); + var response = await Connection.GetRedirect(uri).ConfigureAwait(false); if (response.HttpResponse.StatusCode == HttpStatusCode.Redirect) { @@ -522,7 +506,7 @@ namespace Octokit { Ensure.ArgumentNotNull(uri, "uri"); - var response = await Connection.GetResponse>(uri, cancellationToken); + var response = await Connection.GetResponse>(uri, cancellationToken).ConfigureAwait(false); switch (response.HttpResponse.StatusCode) { diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 60e81df9..ed5dd957 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -233,7 +233,7 @@ namespace Octokit { Ensure.ArgumentNotNull(uri, "uri"); - var response = await SendData(uri, HttpMethod.Post, null, null, null, CancellationToken.None); + var response = await SendData(uri, HttpMethod.Post, null, null, null, CancellationToken.None).ConfigureAwait(false); return response.HttpResponse.StatusCode; } @@ -399,7 +399,7 @@ namespace Octokit BaseAddress = BaseAddress, Endpoint = uri }; - var response = await Run(request, CancellationToken.None); + var response = await Run(request, CancellationToken.None).ConfigureAwait(false); return response.HttpResponse.StatusCode; } @@ -418,7 +418,7 @@ namespace Octokit BaseAddress = BaseAddress, Endpoint = uri }; - var response = await Run(request, CancellationToken.None); + var response = await Run(request, CancellationToken.None).ConfigureAwait(false); return response.HttpResponse.StatusCode; } @@ -437,7 +437,7 @@ namespace Octokit BaseAddress = BaseAddress, Endpoint = uri }; - var response = await Run(request, CancellationToken.None); + var response = await Run(request, CancellationToken.None).ConfigureAwait(false); return response.HttpResponse.StatusCode; } @@ -451,14 +451,7 @@ namespace Octokit { Ensure.ArgumentNotNull(uri, "uri"); - var response = await SendData( - uri, - HttpMethod.Delete, - null, - null, - null, - CancellationToken.None, - twoFactorAuthenticationCode); + var response = await SendData(uri, HttpMethod.Delete, null, null, null, CancellationToken.None, twoFactorAuthenticationCode).ConfigureAwait(false); return response.HttpResponse.StatusCode; } @@ -480,7 +473,7 @@ namespace Octokit BaseAddress = BaseAddress, Endpoint = uri }; - var response = await Run(request, CancellationToken.None); + var response = await Run(request, CancellationToken.None).ConfigureAwait(false); return response.HttpResponse.StatusCode; } @@ -496,7 +489,7 @@ namespace Octokit Ensure.ArgumentNotNull(uri, "uri"); Ensure.ArgumentNotNull(accepts, "accepts"); - var response = await SendData(uri, HttpMethod.Delete, data, accepts, null, CancellationToken.None); + var response = await SendData(uri, HttpMethod.Delete, data, accepts, null, CancellationToken.None).ConfigureAwait(false); return response.HttpResponse.StatusCode; } @@ -543,7 +536,7 @@ namespace Octokit async Task> GetHtml(IRequest request) { request.Headers.Add("Accept", AcceptHeaders.StableVersionHtml); - var response = await RunRequest(request, CancellationToken.None); + var response = await RunRequest(request, CancellationToken.None).ConfigureAwait(false); return new ApiResponse(response, response.Body as string); } @@ -575,7 +568,8 @@ namespace Octokit { HttpStatusCode.Unauthorized, GetExceptionForUnauthorized }, { HttpStatusCode.Forbidden, GetExceptionForForbidden }, { HttpStatusCode.NotFound, response => new NotFoundException(response) }, - { (HttpStatusCode)422, response => new ApiValidationException(response) } + { (HttpStatusCode)422, response => new ApiValidationException(response) }, + { (HttpStatusCode)451, response => new LegalRestrictionException(response) } }; static void HandleErrors(IResponse response) diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index 1c6a65a5..16bb8868 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -43,8 +43,7 @@ namespace Octokit.Internal using (var requestMessage = BuildRequestMessage(request)) { // Make the request - var responseMessage = await _http.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, cancellationTokenForRequest) - .ConfigureAwait(false); + var responseMessage = await _http.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, cancellationTokenForRequest).ConfigureAwait(false); return await BuildResponse(responseMessage).ConfigureAwait(false); } } @@ -178,7 +177,7 @@ namespace Octokit.Internal protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { - var response = await base.SendAsync(request, cancellationToken); + var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false); // Can't redirect without somewhere to redirect too. Throw? if (response.Headers.Location == null) return response; @@ -213,7 +212,7 @@ namespace Octokit.Internal { if (request.Content != null && request.Content.Headers.ContentLength != 0) { - var stream = await request.Content.ReadAsStreamAsync(); + var stream = await request.Content.ReadAsStreamAsync().ConfigureAwait(false); if (stream.CanSeek) { stream.Position = 0; @@ -230,7 +229,7 @@ namespace Octokit.Internal { newRequest.Headers.Authorization = null; } - response = await SendAsync(newRequest, cancellationToken); + response = await SendAsync(newRequest, cancellationToken).ConfigureAwait(false); } return response; diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index abbfe348..4b28ca06 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -458,6 +458,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 60896d14..4396b3c8 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -467,6 +467,7 @@ + - + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 41d2a7e0..10562bbe 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -463,7 +463,8 @@ + - + \ No newline at end of file diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 0f950019..17259fe6 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -455,6 +455,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 3cfdc341..73e36516 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -462,6 +462,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index f6004fb9..f4944f25 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -91,6 +91,7 @@ +