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/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.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 9e4162f0..f79e88e2 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -139,6 +139,7 @@ + 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/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/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/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. ///