From 9c77ebf00912b2f9fff89c124744d34fe2f4ec4a Mon Sep 17 00:00:00 2001 From: Elhamer Date: Thu, 14 Apr 2016 05:07:19 +0100 Subject: [PATCH] Add ApiOption overloads to methods on IIssueCommentsClient (#1267) --- .../Clients/IObservableIssueCommentsClient.cs | 21 + .../Clients/ObservableIssueCommentsClient.cs | 39 +- .../Octokit.Tests.Integration.csproj | 1 + .../ObservableIssueCommentsClientTests.cs | 92 ++++ .../Clients/IssueCommentsClientTests.cs | 425 ++++++++++-------- .../ObservableIssueCommentsClientTests.cs | 46 +- Octokit/Clients/IIssueCommentsClient.cs | 21 + Octokit/Clients/IssueCommentsClient.cs | 38 +- 8 files changed, 485 insertions(+), 198 deletions(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableIssueCommentsClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs b/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs index bc93a4e1..906a8814 100644 --- a/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs @@ -27,6 +27,16 @@ namespace Octokit.Reactive /// The list of s for the specified Repository. IObservable GetAllForRepository(string owner, string name); + /// + /// Gets Issue Comments for a repository. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// The list of s for the specified Repository. + IObservable GetAllForRepository(string owner, string name, ApiOptions options); + /// /// Gets Issue Comments for a specified Issue. /// @@ -37,6 +47,17 @@ namespace Octokit.Reactive /// The list of s for the specified Issue. IObservable GetAllForIssue(string owner, string name, int number); + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// Options for changing the API response + /// The list of s for the specified Issue. + IObservable GetAllForIssue(string owner, string name, int number, ApiOptions options); + /// /// Creates a new Issue Comment for a specified Issue. /// diff --git a/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs b/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs index 2a8494a4..37b4bccd 100644 --- a/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs @@ -46,7 +46,24 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name)); + return GetAllForRepository(owner, name, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a repository. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// The list of s for the specified 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.IssueComments(owner, name), options); } /// @@ -62,7 +79,25 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name, number)); + return GetAllForIssue(owner, name, number, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// Options for changing the API response + /// The list of s for the specified Issue. + public IObservable GetAllForIssue(string owner, string name, int number, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name, number), options); } /// diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 2c972371..ef172d00 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -138,6 +138,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableIssueCommentsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableIssueCommentsClientTests.cs new file mode 100644 index 00000000..d838866d --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableIssueCommentsClientTests.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Linq; +using System.Text; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableIssueCommentsClientTests + { + public class TheGetAllForRepositoryMethod + { + readonly ObservableIssueCommentsClient _issueCommentsClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllForRepositoryMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _issueCommentsClient = new ObservableIssueCommentsClient(github); + } + + [IntegrationTest] + public async Task ReturnsIssueComments() + { + var issueComments = await _issueCommentsClient.GetAllForRepository(owner, name).ToList(); + + Assert.NotEmpty(issueComments); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfIssueCommentsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var issueComments = await _issueCommentsClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, issueComments.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfIssueCommentsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var issueComments = await _issueCommentsClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, issueComments.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstPageIssueComments = await _issueCommentsClient.GetAllForRepository(owner, name, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondPageIssueComments = await _issueCommentsClient.GetAllForRepository(owner, name, skipStartOptions).ToList(); + + Assert.NotEqual(firstPageIssueComments[0].Id, secondPageIssueComments[0].Id); + Assert.NotEqual(firstPageIssueComments[1].Id, secondPageIssueComments[1].Id); + Assert.NotEqual(firstPageIssueComments[2].Id, secondPageIssueComments[2].Id); + Assert.NotEqual(firstPageIssueComments[3].Id, secondPageIssueComments[3].Id); + Assert.NotEqual(firstPageIssueComments[4].Id, secondPageIssueComments[4].Id); + } + } + } +} diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index 4b0eb139..a3788f07 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -3,211 +3,252 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; using NSubstitute; -using Octokit; using Octokit.Internal; -using Octokit.Tests.Helpers; using Xunit; -public class IssueCommentsClientTests +namespace Octokit.Tests.Clients { - public class TheGetMethod + public class IssueCommentsClientTests { - [Fact] - public void RequestsCorrectUrl() + public class TheGetMethod { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); - client.Get("fake", "repo", 42); + client.Get("fake", "repo", 42); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42")); + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new IssueCommentsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Get(null, "name", 1)); + await Assert.ThrowsAsync(() => client.Get("", "name", 1)); + await Assert.ThrowsAsync(() => client.Get("owner", null, 1)); + await Assert.ThrowsAsync(() => client.Get("owner", "", 1)); + } + } + + public class TheGetForRepositoryMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.GetAllForRepository("fake", "repo"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + var options = new ApiOptions() + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + client.GetAllForRepository("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments"), options); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); + 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)); + } + } + + public class TheGetForIssueMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.GetAllForIssue("fake", "repo", 3); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/3/comments"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + var options = new ApiOptions() + { + StartPage = 1, + PageSize = 1, + PageCount = 1 + }; + client.GetAllForIssue("fake", "repo", 3, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/3/comments"), options); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForIssue(null, "name", 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, null)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1, ApiOptions.None)); + } + } + + public class TheCreateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + const string newComment = "some title"; + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.Create("fake", "repo", 1, newComment); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/1/comments"), Arg.Any()); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.Create(null, "name", 1, "title")); + await Assert.ThrowsAsync(() => client.Create("", "name", 1, "x")); + await Assert.ThrowsAsync(() => client.Create("owner", null, 1, "x")); + await Assert.ThrowsAsync(() => client.Create("owner", "", 1, "x")); + await Assert.ThrowsAsync(() => client.Create("owner", "name", 1, null)); + } + } + + public class TheUpdateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + const string issueCommentUpdate = "Worthwhile update"; + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.Update("fake", "repo", 42, issueCommentUpdate); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42"), Arg.Any()); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.Update(null, "name", 42, "title")); + await Assert.ThrowsAsync(() => client.Update("", "name", 42, "x")); + await Assert.ThrowsAsync(() => client.Update("owner", null, 42, "x")); + await Assert.ThrowsAsync(() => client.Update("owner", "", 42, "x")); + await Assert.ThrowsAsync(() => client.Update("owner", "name", 42, null)); + } + } + + public class TheDeleteMethod + { + [Fact] + public void DeletesCorrectUrl() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.Delete("fake", "repo", 42); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42")); + } + + [Fact] + public async Task EnsuresArgumentsNotNullOrEmpty() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.Delete(null, "name", 42)); + await Assert.ThrowsAsync(() => client.Delete("", "name", 42)); + await Assert.ThrowsAsync(() => client.Delete("owner", null, 42)); + await Assert.ThrowsAsync(() => client.Delete("owner", "", 42)); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new IssueCommentsClient(null)); + } } [Fact] - public async Task EnsuresNonNullArguments() + public void CanDeserializeIssueComment() { - var client = new IssueCommentsClient(Substitute.For()); + const string issueResponseJson = + "{\"id\": 1," + + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," + + "\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," + + "\"body\": \"Me too\"," + + "\"user\": {" + + "\"login\": \"octocat\"," + + "\"id\": 1," + + "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + + "\"gravatar_id\": \"somehexcode\"," + + "\"url\": \"https://api.github.com/users/octocat\"" + + "}," + + "\"created_at\": \"2011-04-14T16:00:49Z\"," + + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + + "}"; + var httpResponse = new Response( + HttpStatusCode.OK, + issueResponseJson, + new Dictionary(), + "application/json"); - await Assert.ThrowsAsync(() => client.Get(null, "name", 1)); - await Assert.ThrowsAsync(() => client.Get("", "name", 1)); - await Assert.ThrowsAsync(() => client.Get("owner", null, 1)); - await Assert.ThrowsAsync(() => client.Get("owner", "", 1)); + var jsonPipeline = new JsonHttpPipeline(); + + var response = jsonPipeline.DeserializeResponse(httpResponse); + + Assert.NotNull(response.Body); + Assert.Equal(issueResponseJson, response.HttpResponse.Body); + Assert.Equal(1, response.Body.Id); } } - - public class TheGetForRepositoryMethod - { - [Fact] - public void RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.GetAllForRepository("fake", "repo"); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments")); - } - - [Fact] - public async Task EnsuresArgumentsNotNull() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); - } - } - - public class TheGetForIssueMethod - { - [Fact] - public void RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.GetAllForIssue("fake", "repo", 3); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/3/comments")); - } - - [Fact] - public async Task EnsuresArgumentsNotNull() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.GetAllForIssue(null, "name", 1)); - await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1)); - await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1)); - await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1)); - } - } - - public class TheCreateMethod - { - [Fact] - public void PostsToCorrectUrl() - { - const string newComment = "some title"; - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.Create("fake", "repo", 1, newComment); - - connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/1/comments"), Arg.Any()); - } - - [Fact] - public async Task EnsuresArgumentsNotNull() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.Create(null, "name", 1, "title")); - await Assert.ThrowsAsync(() => client.Create("", "name", 1, "x")); - await Assert.ThrowsAsync(() => client.Create("owner", null, 1, "x")); - await Assert.ThrowsAsync(() => client.Create("owner", "", 1, "x")); - await Assert.ThrowsAsync(() => client.Create("owner", "name", 1, null)); - } - } - - public class TheUpdateMethod - { - [Fact] - public void PostsToCorrectUrl() - { - const string issueCommentUpdate = "Worthwhile update"; - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.Update("fake", "repo", 42, issueCommentUpdate); - - connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42"), Arg.Any()); - } - - [Fact] - public async Task EnsuresArgumentsNotNull() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.Update(null, "name", 42, "title")); - await Assert.ThrowsAsync(() => client.Update("", "name", 42, "x")); - await Assert.ThrowsAsync(() => client.Update("owner", null, 42, "x")); - await Assert.ThrowsAsync(() => client.Update("owner", "", 42, "x")); - await Assert.ThrowsAsync(() => client.Update("owner", "name", 42, null)); - } - } - - public class TheDeleteMethod - { - [Fact] - public void DeletesCorrectUrl() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.Delete("fake", "repo", 42); - - connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42")); - } - - [Fact] - public async Task EnsuresArgumentsNotNullOrEmpty() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.Delete(null, "name", 42)); - await Assert.ThrowsAsync(() => client.Delete("", "name", 42)); - await Assert.ThrowsAsync(() => client.Delete("owner", null, 42)); - await Assert.ThrowsAsync(() => client.Delete("owner", "", 42)); - } - } - - public class TheCtor - { - [Fact] - public void EnsuresArgument() - { - Assert.Throws(() => new IssueCommentsClient(null)); - } - } - - [Fact] - public void CanDeserializeIssueComment() - { - const string issueResponseJson = - "{\"id\": 1," + - "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," + - "\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," + - "\"body\": \"Me too\"," + - "\"user\": {" + - "\"login\": \"octocat\"," + - "\"id\": 1," + - "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + - "\"gravatar_id\": \"somehexcode\"," + - "\"url\": \"https://api.github.com/users/octocat\"" + - "}," + - "\"created_at\": \"2011-04-14T16:00:49Z\"," + - "\"updated_at\": \"2011-04-14T16:00:49Z\"" + - "}"; - var httpResponse = new Response( - HttpStatusCode.OK, - issueResponseJson, - new Dictionary(), - "application/json"); - - var jsonPipeline = new JsonHttpPipeline(); - - var response = jsonPipeline.DeserializeResponse(httpResponse); - - Assert.NotNull(response.Body); - Assert.Equal(issueResponseJson, response.HttpResponse.Body); - Assert.Equal(1, response.Body.Id); - } } diff --git a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs index 96552397..958ff020 100644 --- a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs @@ -48,7 +48,25 @@ namespace Octokit.Tests.Reactive client.GetAllForRepository("fake", "repo"); gitHubClient.Connection.Received(1).Get>( - new Uri("repos/fake/repo/issues/comments", UriKind.Relative), null, null); + new Uri("repos/fake/repo/issues/comments", UriKind.Relative), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentsClient(gitHubClient); + + var options=new ApiOptions() + { + StartPage = 1, + PageSize = 1, + PageCount = 1 + }; + client.GetAllForRepository("fake", "repo", options); + + gitHubClient.Connection.Received(1).Get>( + new Uri("repos/fake/repo/issues/comments", UriKind.Relative), Arg.Any>(), null); } [Fact] @@ -61,6 +79,9 @@ namespace Octokit.Tests.Reactive await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name").ToTask()); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null).ToTask()); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "").ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", ApiOptions.None).ToTask()); } } @@ -75,7 +96,25 @@ namespace Octokit.Tests.Reactive client.GetAllForIssue("fake", "repo", 3); gitHubClient.Connection.Received(1).Get>( - new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), null, null); + new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentsClient(gitHubClient); + + var options=new ApiOptions() + { + StartPage = 1, + PageSize = 1, + PageCount = 1 + }; + client.GetAllForIssue("fake", "repo", 3, options); + + gitHubClient.Connection.Received(1).Get>( + new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), Arg.Any>(), null); } [Fact] @@ -88,6 +127,9 @@ namespace Octokit.Tests.Reactive await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1).ToTask()); await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1).ToTask()); await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, null).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1, ApiOptions.None).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1, ApiOptions.None).ToTask()); } } diff --git a/Octokit/Clients/IIssueCommentsClient.cs b/Octokit/Clients/IIssueCommentsClient.cs index 1e091d28..147c3b84 100644 --- a/Octokit/Clients/IIssueCommentsClient.cs +++ b/Octokit/Clients/IIssueCommentsClient.cs @@ -33,6 +33,16 @@ namespace Octokit /// Task> GetAllForRepository(string owner, string name); + /// + /// Gets Issue Comments for a repository. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// + Task> GetAllForRepository(string owner, string name, ApiOptions options); + /// /// Gets Issue Comments for a specified Issue. /// @@ -43,6 +53,17 @@ namespace Octokit /// Task> GetAllForIssue(string owner, string name, int number); + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// Options for changing the API response + /// + Task> GetAllForIssue(string owner, string name, int number, ApiOptions options); + /// /// Creates a new Issue Comment for a specified Issue. /// diff --git a/Octokit/Clients/IssueCommentsClient.cs b/Octokit/Clients/IssueCommentsClient.cs index 05b00e12..54748f77 100644 --- a/Octokit/Clients/IssueCommentsClient.cs +++ b/Octokit/Clients/IssueCommentsClient.cs @@ -47,7 +47,24 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.IssueComments(owner, name)); + return GetAllForRepository(owner, name, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a repository. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// + 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.IssueComments(owner, name), options); } /// @@ -63,7 +80,24 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.IssueComments(owner, name, number)); + return GetAllForIssue(owner, name, number, ApiOptions.None); + } + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// Options for changing the API response + /// + public Task> GetAllForIssue(string owner, string name, int number, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.IssueComments(owner, name, number), options); } ///