From 43381c4a535fce2ad552c6cca2f38197f6253466 Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Wed, 27 Feb 2019 21:29:33 +1000 Subject: [PATCH] Pagination support to Reactions Clients (#1948) * Add pagination to *CommitCommentReactionsClient * Add unit tests for *CommitCommentReactionsClient * Add integration tests for *CommitCommentReactionsClient * Add pagination to *IssueCommentReactionsClient * Add unit tests for *IssueCommentReactionsClient * Add integration tests for *IssueCommentReactionsClient * Add pagination to *IssueReactionsClient * Add unit tests for *IssueReactionsClient * Add integration tests for *IssueReactionsClient * Add pagination to *PullRequestReviewCommentReactionsClient * Add unit tests for *PullRequestReviewCommentReactionsClient * Add integration tests for *PullRequestReviewCommentReactionsClient * Remove rogue using statement and whitespace * Add null check tests for GetAll with repositoryid overload --- ...IObservableCommitCommentReactionsClient.cs | 21 ++ .../IObservableIssueCommentReactionsClient.cs | 19 ++ .../IObservableIssueReactionsClient.cs | 19 ++ ...PullRequestReviewCommentReactionsClient.cs | 19 ++ .../ObservableCommitCommentReactionsClient.cs | 34 ++- .../ObservableIssueCommentReactionsClient.cs | 35 ++- .../Clients/ObservableIssueReactionsClient.cs | 32 ++- ...PullRequestReviewCommentReactionsClient.cs | 24 +- .../CommitCommentReactionsClientTests.cs | 209 +++++++++++++++++ .../IssueCommentReactionsClientTests.cs | 208 +++++++++++++++++ .../Clients/IssueReactionsClientTests.cs | 188 +++++++++++++++ ...equestReviewCommentReactionsClientTests.cs | 216 ++++++++++++++++++ .../CommitCommentReactionsClientTests.cs | 51 ++++- .../IssueCommentReactionsClientTests.cs | 50 +++- .../Clients/IssueReactionsClientTests.cs | 50 +++- ...equestReviewCommentReactionsClientTests.cs | 48 +++- ...rvableCommitCommentReactionsClientTests.cs | 46 ++++ ...ervableIssueCommentReactionsClientTests.cs | 50 +++- .../ObservableIssueReactionsClientTests.cs | 48 +++- ...equestReviewCommentReactionsClientTests.cs | 44 ++++ .../Clients/CommitCommentReactionsClient.cs | 34 ++- .../Clients/ICommitCommentReactionsClient.cs | 23 +- .../Clients/IIssueCommentReactionsClient.cs | 21 +- Octokit/Clients/IIssueReactionsClient.cs | 21 +- ...PullRequestReviewCommentReactionsClient.cs | 21 +- .../Clients/IssueCommentReactionsClient.cs | 32 ++- Octokit/Clients/IssueReactionsClient.cs | 32 ++- ...PullRequestReviewCommentReactionsClient.cs | 32 ++- 28 files changed, 1591 insertions(+), 36 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableCommitCommentReactionsClient.cs b/Octokit.Reactive/Clients/IObservableCommitCommentReactionsClient.cs index a4df576fff..2488a6fa00 100644 --- a/Octokit.Reactive/Clients/IObservableCommitCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCommitCommentReactionsClient.cs @@ -41,6 +41,17 @@ public interface IObservableCommitCommentReactionsClient /// IObservable GetAll(string owner, string name, int number); + /// + /// List reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + /// + IObservable GetAll(string owner, string name, int number, ApiOptions options); + /// /// List reactions for a specified Commit Comment /// @@ -49,5 +60,15 @@ public interface IObservableCommitCommentReactionsClient /// The comment id /// IObservable GetAll(long repositoryId, int number); + + /// + /// List reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// Options for changing the API response + /// + IObservable GetAll(long repositoryId, int number, ApiOptions options); } } diff --git a/Octokit.Reactive/Clients/IObservableIssueCommentReactionsClient.cs b/Octokit.Reactive/Clients/IObservableIssueCommentReactionsClient.cs index 24294d70b4..6a8f032b90 100644 --- a/Octokit.Reactive/Clients/IObservableIssueCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/IObservableIssueCommentReactionsClient.cs @@ -38,6 +38,16 @@ public interface IObservableIssueCommentReactionsClient /// The comment id IObservable GetAll(string owner, string name, int number); + /// + /// List reactions for a specified Issue Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + IObservable GetAll(string owner, string name, int number, ApiOptions options); + /// /// List reactions for a specified Issue Comment /// @@ -45,5 +55,14 @@ public interface IObservableIssueCommentReactionsClient /// The Id of the repository /// The comment id IObservable GetAll(long repositoryId, int number); + + /// + /// List reactions for a specified Issue Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment + /// The Id of the repository + /// The comment id + /// Options for changing the API response + IObservable GetAll(long repositoryId, int number, ApiOptions options); } } diff --git a/Octokit.Reactive/Clients/IObservableIssueReactionsClient.cs b/Octokit.Reactive/Clients/IObservableIssueReactionsClient.cs index 4414327365..8d76206408 100644 --- a/Octokit.Reactive/Clients/IObservableIssueReactionsClient.cs +++ b/Octokit.Reactive/Clients/IObservableIssueReactionsClient.cs @@ -19,6 +19,16 @@ public interface IObservableIssueReactionsClient /// The issue id IObservable GetAll(string owner, string name, int number); + /// + /// List reactions for a specified Issue. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue id + /// Options for changing the API response + IObservable GetAll(string owner, string name, int number, ApiOptions options); + /// /// List reactions for a specified Issue. /// @@ -27,6 +37,15 @@ public interface IObservableIssueReactionsClient /// The issue id IObservable GetAll(long repositoryId, int number); + /// + /// List reactions for a specified Issue. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue + /// The Id of the repository + /// The issue id + /// Options for changing the API response + IObservable GetAll(long repositoryId, int number, ApiOptions options); + /// /// Creates a reaction for a specified Issue. /// diff --git a/Octokit.Reactive/Clients/IObservablePullRequestReviewCommentReactionsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestReviewCommentReactionsClient.cs index 85dff3bb96..ced771bd5c 100644 --- a/Octokit.Reactive/Clients/IObservablePullRequestReviewCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/IObservablePullRequestReviewCommentReactionsClient.cs @@ -19,6 +19,16 @@ public interface IObservablePullRequestReviewCommentReactionsClient /// The comment id IObservable GetAll(string owner, string name, int number); + /// + /// Get all reactions for a specified Pull Request Review Comment. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + IObservable GetAll(string owner, string name, int number, ApiOptions options); + /// /// Get all reactions for a specified Pull Request Review Comment. /// @@ -27,6 +37,15 @@ public interface IObservablePullRequestReviewCommentReactionsClient /// The comment id IObservable GetAll(long repositoryId, int number); + /// + /// Get all reactions for a specified Pull Request Review Comment. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment + /// The Id of the repository + /// The comment id + /// Options for changing the API response + IObservable GetAll(long repositoryId, int number, ApiOptions options); + /// /// Creates a reaction for a specified Pull Request Review Comment. /// diff --git a/Octokit.Reactive/Clients/ObservableCommitCommentReactionsClient.cs b/Octokit.Reactive/Clients/ObservableCommitCommentReactionsClient.cs index c17c50057c..8286a52077 100644 --- a/Octokit.Reactive/Clients/ObservableCommitCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCommitCommentReactionsClient.cs @@ -65,11 +65,26 @@ public IObservable Create(long repositoryId, int number, NewReaction r /// The comment id /// public IObservable GetAll(string owner, string name, int number) + { + return GetAll(owner, name, number, ApiOptions.None); + } + + /// + /// List reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + /// + public IObservable GetAll(string owner, string name, int number, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.CommitCommentReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview); + return _connection.GetAndFlattenAllPages(ApiUrls.CommitCommentReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -81,7 +96,22 @@ public IObservable GetAll(string owner, string name, int number) /// public IObservable GetAll(long repositoryId, int number) { - return _connection.GetAndFlattenAllPages(ApiUrls.CommitCommentReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview); + return GetAll(repositoryId, number, ApiOptions.None); + } + + /// + /// List reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// Options for changing the API response + /// + public IObservable GetAll(long repositoryId, int number, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CommitCommentReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); } } } diff --git a/Octokit.Reactive/Clients/ObservableIssueCommentReactionsClient.cs b/Octokit.Reactive/Clients/ObservableIssueCommentReactionsClient.cs index 641e709047..36200a0a52 100644 --- a/Octokit.Reactive/Clients/ObservableIssueCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservableIssueCommentReactionsClient.cs @@ -66,7 +66,24 @@ public IObservable GetAll(string owner, string name, int number) Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); - return _connection.GetAndFlattenAllPages(ApiUrls.IssueCommentReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview); + return GetAll(owner, name, number, ApiOptions.None); + } + + /// + /// List reactions for a specified Issue Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + public IObservable GetAll(string owner, string name, int number, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssueCommentReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -77,7 +94,21 @@ public IObservable GetAll(string owner, string name, int number) /// The comment id public IObservable GetAll(long repositoryId, int number) { - return _connection.GetAndFlattenAllPages(ApiUrls.IssueCommentReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview); + return GetAll(repositoryId, number, ApiOptions.None); + } + + /// + /// List reactions for a specified Issue Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment + /// The Id of the repository + /// The comment id + /// Options for changing the API response + public IObservable GetAll(long repositoryId, int number, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssueCommentReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); } } } diff --git a/Octokit.Reactive/Clients/ObservableIssueReactionsClient.cs b/Octokit.Reactive/Clients/ObservableIssueReactionsClient.cs index 6d2a3b154b..3de52e7f8f 100644 --- a/Octokit.Reactive/Clients/ObservableIssueReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservableIssueReactionsClient.cs @@ -31,11 +31,25 @@ public ObservableIssueReactionsClient(IGitHubClient client) /// The name of the repository /// The issue id public IObservable GetAll(string owner, string name, int number) + { + return GetAll(owner, name, number, ApiOptions.None); + } + + /// + /// List reactions for a specified Issue + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue id + /// Options for changing the API response + public IObservable GetAll(string owner, string name, int number, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.IssueReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview); + return _connection.GetAndFlattenAllPages(ApiUrls.IssueReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -46,7 +60,21 @@ public IObservable GetAll(string owner, string name, int number) /// The issue id public IObservable GetAll(long repositoryId, int number) { - return _connection.GetAndFlattenAllPages(ApiUrls.IssueReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview); + return GetAll(repositoryId, number, ApiOptions.None); + } + + /// + /// List reactions for a specified Issue. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue + /// The Id of the repository + /// The issue id + /// Options for changing the API response + public IObservable GetAll(long repositoryId, int number, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssueReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); } /// diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs index b81169ad80..4cd1f7f751 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentReactionsClient.cs @@ -31,11 +31,17 @@ public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client) /// The name of the repository /// The comment id public IObservable GetAll(string owner, string name, int number) + { + return GetAll(owner, name, number, ApiOptions.None); + } + + public IObservable GetAll(string owner, string name, int number, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), null, AcceptHeaders.ReactionsPreview); + return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -46,7 +52,21 @@ public IObservable GetAll(string owner, string name, int number) /// The comment id public IObservable GetAll(long repositoryId, int number) { - return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentReaction(repositoryId, number), null, AcceptHeaders.ReactionsPreview); + return GetAll(repositoryId, number, ApiOptions.None); + } + + /// + /// Get all reactions for a specified Pull Request Review Comment. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment + /// The Id of the repository + /// The comment id + /// Options for changing the API response + public IObservable GetAll(long repositoryId, int number, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentReaction(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); } /// diff --git a/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs index 6c3e169c06..21a9ff7256 100644 --- a/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; @@ -68,6 +70,110 @@ public async Task CanListReactions() Assert.Equal(reaction.Content, reactions[0].Content); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithoutStart() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, + commit.Sha, comment); + + Assert.NotNull(result); + + var newReaction = new NewReaction(ReactionType.Confused); + var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + var reactions = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id, options); + + Assert.Equal(1, reactions.Count); + + Assert.Equal(reaction.Id, reactions[0].Id); + Assert.Equal(reaction.Content, reactions[0].Content); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithStart() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, + commit.Sha, comment); + + Assert.NotNull(result); + + var reactions = new List(); + var reactionsContent = new []{ ReactionType.Confused, ReactionType.Hooray }; + for (var i = 0; i < 2; i++) + { + var newReaction = new NewReaction(reactionsContent[i]); + var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction); + reactions.Add(reaction); + } + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + var reactionsInfo = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id, options); + + Assert.Equal(1, reactionsInfo.Count); + + Assert.Equal(reactions.Last().Id, reactionsInfo[0].Id); + Assert.Equal(reactions.Last().Content, reactionsInfo[0].Content); + } + + [IntegrationTest] + public async Task ReturnsDistinctReactionsBasedOnStartPage() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, + commit.Sha, comment); + + Assert.NotNull(result); + + var reactionsContent = new []{ ReactionType.Confused, ReactionType.Hooray }; + for (var i = 0; i < 2; i++) + { + var newReaction = new NewReaction(reactionsContent[i]); + var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction); + } + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var firstPage = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var secondPage = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[0].Content, secondPage[0].Content); + } + [IntegrationTest] public async Task CanListReactionsWithRepositoryId() { @@ -92,6 +198,109 @@ public async Task CanListReactionsWithRepositoryId() Assert.Equal(reaction.Content, reactions[0].Content); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithoutStartWithRepositoryId() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, + commit.Sha, comment); + + Assert.NotNull(result); + + var newReaction = new NewReaction(ReactionType.Confused); + var reaction = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + var reactions = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, options); + + Assert.Equal(1, reactions.Count); + + Assert.Equal(reaction.Id, reactions[0].Id); + Assert.Equal(reaction.Content, reactions[0].Content); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithStartWithRepositoryId() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, + commit.Sha, comment); + + Assert.NotNull(result); + + var reactions = new List(); + var reactionsContent = new []{ ReactionType.Confused, ReactionType.Hooray }; + for (var i = 0; i < 2; i++) + { + var newReaction = new NewReaction(reactionsContent[i]); + var reaction = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction); + reactions.Add(reaction); + } + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + var reactionsInfo = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, options); + + Assert.Equal(1, reactionsInfo.Count); + + Assert.Equal(reactions.Last().Id, reactionsInfo[0].Id); + Assert.Equal(reactions.Last().Content, reactionsInfo[0].Content); + } + + [IntegrationTest] + public async Task ReturnsDistinctReactionsBasedOnStartPageWithRepositoryId() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, + commit.Sha, comment); + + Assert.NotNull(result); + + var reactionsContent = new []{ ReactionType.Confused, ReactionType.Hooray }; + for (var i = 0; i < 2; i++) + { + var newReaction = new NewReaction(reactionsContent[i]); + var reaction = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction); + } + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var firstPage = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var secondPage = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[0].Content, secondPage[0].Content); + } [IntegrationTest] public async Task CanCreateReaction() { diff --git a/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs index 7965c6fe33..472218a010 100644 --- a/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; @@ -44,6 +46,109 @@ public async Task CanListReactions() Assert.Equal(reactions[0].Content, issueCommentReaction.Content); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithoutStart() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueComment = await _issuesClient.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); + + Assert.NotNull(issueComment); + + var issueCommentReaction = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, new NewReaction(ReactionType.Heart)); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var reactions = await _github.Reaction.IssueComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, options); + + Assert.Equal(1, reactions.Count); + + Assert.Equal(reactions[0].Id, issueCommentReaction.Id); + Assert.Equal(reactions[0].Content, issueCommentReaction.Content); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithStart() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueComment = await _issuesClient.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); + + Assert.NotNull(issueComment); + + var reactions = new List(); + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Plus1 }; + for (var i = 0; i < 2; i++) + { + var issueCommentReaction = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, new NewReaction(reactionsContent[i])); + reactions.Add(issueCommentReaction); + } + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var reactionsInfo = await _github.Reaction.IssueComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, options); + + Assert.Equal(1, reactionsInfo.Count); + + Assert.Equal(reactionsInfo[0].Id, reactions.Last().Id); + Assert.Equal(reactionsInfo[0].Content, reactions.Last().Content); + } + + [IntegrationTest] + public async Task ReturnsDistinctReactionsBasedOnStartPage() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueComment = await _issuesClient.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); + + Assert.NotNull(issueComment); + + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Plus1 }; + for (var i = 0; i < 2; i++) + { + var issueCommentReaction = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, new NewReaction(reactionsContent[i])); + } + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var firstPage = await _github.Reaction.IssueComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + var secondPage = await _github.Reaction.IssueComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[0].Content, secondPage[0].Content); + } + [IntegrationTest] public async Task CanListReactionsWithRepositoryId() { @@ -67,6 +172,109 @@ public async Task CanListReactionsWithRepositoryId() Assert.Equal(reactions[0].Content, issueCommentReaction.Content); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithoutStartWithRepositoryId() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueComment = await _issuesClient.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); + + Assert.NotNull(issueComment); + + var issueCommentReaction = await _github.Reaction.IssueComment.Create(_context.Repository.Id, issueComment.Id, new NewReaction(ReactionType.Heart)); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var reactions = await _github.Reaction.IssueComment.GetAll(_context.Repository.Id, issueComment.Id, options); + + Assert.Equal(1, reactions.Count); + + Assert.Equal(reactions[0].Id, issueCommentReaction.Id); + Assert.Equal(reactions[0].Content, issueCommentReaction.Content); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithStartWithRepositoryId() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueComment = await _issuesClient.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); + + Assert.NotNull(issueComment); + + var reactions = new List(); + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Plus1 }; + for (var i = 0; i < 2; i++) + { + var issueCommentReaction = await _github.Reaction.IssueComment.Create(_context.Repository.Id, issueComment.Id, new NewReaction(reactionsContent[i])); + reactions.Add(issueCommentReaction); + } + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var reactionsInfo = await _github.Reaction.IssueComment.GetAll(_context.Repository.Id, issueComment.Id, options); + + Assert.Equal(1, reactionsInfo.Count); + + Assert.Equal(reactionsInfo[0].Id, reactions.Last().Id); + Assert.Equal(reactionsInfo[0].Content, reactions.Last().Content); + } + + [IntegrationTest] + public async Task ReturnsDistinctReactionsBasedOnStartPageWithRepositoryId() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueComment = await _issuesClient.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); + + Assert.NotNull(issueComment); + + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Plus1 }; + for (var i = 0; i < 2; i++) + { + var issueCommentReaction = await _github.Reaction.IssueComment.Create(_context.Repository.Id, issueComment.Id, new NewReaction(reactionsContent[i])); + } + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var firstPage = await _github.Reaction.IssueComment.GetAll(_context.Repository.Id, issueComment.Id, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + var secondPage = await _github.Reaction.IssueComment.GetAll(_context.Repository.Id, issueComment.Id, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[0].Content, secondPage[0].Content); + } + [IntegrationTest] public async Task CanCreateReaction() { diff --git a/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs index f4ffbcb31e..edba281bfa 100644 --- a/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; @@ -41,6 +43,99 @@ public async Task CanListReactions() Assert.Equal(issueReaction.Content, issueReactions[0].Content); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithoutStart() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueReaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new NewReaction(ReactionType.Heart)); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var issueReactions = await _github.Reaction.Issue.GetAll(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options); + + Assert.Equal(1, issueReactions.Count); + + Assert.Equal(issueReaction.Id, issueReactions[0].Id); + Assert.Equal(issueReaction.Content, issueReactions[0].Content); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithStart() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var reactions = new List(); + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Plus1 }; + for (var i = 0; i < 2; i++) + { + var issueReaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new NewReaction(reactionsContent[i])); + reactions.Add(issueReaction); + } + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var issueReactions = await _github.Reaction.Issue.GetAll(_context.RepositoryOwner, _context.RepositoryName, issue.Number, options); + + Assert.Equal(1, issueReactions.Count); + + Assert.Equal(reactions.Last().Id, issueReactions[0].Id); + Assert.Equal(reactions.Last().Content, issueReactions[0].Content); + } + + [IntegrationTest] + public async Task ReturnsDistinctReactionsBasedOnStartPage() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var reactions = new List(); + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Plus1 }; + for (var i = 0; i < 2; i++) + { + var issueReaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new NewReaction(reactionsContent[i])); + reactions.Add(issueReaction); + } + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var firstPage = await _github.Reaction.Issue.GetAll(_context.RepositoryOwner, _context.RepositoryName, issue.Number, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + var secondPage = await _github.Reaction.Issue.GetAll(_context.RepositoryOwner, _context.RepositoryName, issue.Number, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[0].Content, secondPage[0].Content); + } + [IntegrationTest] public async Task CanListReactionsWithRepositoryId() { @@ -59,6 +154,99 @@ public async Task CanListReactionsWithRepositoryId() Assert.Equal(issueReaction.Content, issueReactions[0].Content); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithoutStartWithRepositoryId() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueReaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new NewReaction(ReactionType.Heart)); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var issueReactions = await _github.Reaction.Issue.GetAll(_context.Repository.Id, issue.Number, options); + + Assert.Equal(1, issueReactions.Count); + + Assert.Equal(issueReaction.Id, issueReactions[0].Id); + Assert.Equal(issueReaction.Content, issueReactions[0].Content); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithStartWithRepositoryId() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var reactions = new List(); + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Plus1 }; + for (var i = 0; i < 2; i++) + { + var issueReaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new NewReaction(reactionsContent[i])); + reactions.Add(issueReaction); + } + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var issueReactions = await _github.Reaction.Issue.GetAll(_context.Repository.Id, issue.Number, options); + + Assert.Equal(1, issueReactions.Count); + + Assert.Equal(reactions.Last().Id, issueReactions[0].Id); + Assert.Equal(reactions.Last().Content, issueReactions[0].Content); + } + + [IntegrationTest] + public async Task ReturnsDistinctReactionsBasedOnStartPageWithRepositoryId() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var reactions = new List(); + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Plus1 }; + for (var i = 0; i < 2; i++) + { + var issueReaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new NewReaction(reactionsContent[i])); + reactions.Add(issueReaction); + } + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var firstPage = await _github.Reaction.Issue.GetAll(_context.Repository.Id, issue.Number, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + var secondPage = await _github.Reaction.Issue.GetAll(_context.Repository.Id, issue.Number, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[0].Content, secondPage[0].Content); + } + [IntegrationTest] public async Task CanCreateReaction() { diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs index 4044adde88..9558c1dd07 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; @@ -49,6 +51,113 @@ public async Task CanListReactions() Assert.Equal(reaction.Content, reactions[0].Content); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithoutStart() + { + var pullRequest = await CreatePullRequest(_context); + + const string body = "A review comment message"; + const int position = 1; + + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); + + var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id); + + AssertComment(commentFromGitHub, body, position); + + var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, new NewReaction(ReactionType.Heart)); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var reactions = await _github.Reaction.PullRequestReviewComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, options); + + Assert.Equal(1, reactions.Count); + Assert.Equal(reaction.Id, reactions[0].Id); + Assert.Equal(reaction.Content, reactions[0].Content); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithStart() + { + var pullRequest = await CreatePullRequest(_context); + + const string body = "A review comment message"; + const int position = 1; + + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); + + var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id); + + AssertComment(commentFromGitHub, body, position); + + var reactions = new List(); + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Hooray }; + for (var i = 0; i < 2; i++) + { + var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, new NewReaction(reactionsContent[i])); + reactions.Add(reaction); + } + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var reactionsInfo = await _github.Reaction.PullRequestReviewComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, options); + + Assert.Equal(1, reactionsInfo.Count); + Assert.Equal(reactions.Last().Id, reactionsInfo[0].Id); + Assert.Equal(reactions.Last().Content, reactionsInfo[0].Content); + } + + [IntegrationTest] + public async Task ReturnsDistinctReactionsBasedOnStartPage() + { + var pullRequest = await CreatePullRequest(_context); + + const string body = "A review comment message"; + const int position = 1; + + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); + + var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id); + + AssertComment(commentFromGitHub, body, position); + + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Hooray }; + for (var i = 0; i < 2; i++) + { + var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, new NewReaction(reactionsContent[i])); + } + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var firstPage = await _github.Reaction.PullRequestReviewComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + var secondPage = await _github.Reaction.PullRequestReviewComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.Equal(firstPage[0].Id, secondPage[0].Id); + Assert.Equal(firstPage[0].Content, secondPage[0].Content); + } + [IntegrationTest] public async Task CanListReactionsWithRepositoryId() { @@ -72,6 +181,113 @@ public async Task CanListReactionsWithRepositoryId() Assert.Equal(reaction.Content, reactions[0].Content); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithoutStartWithRepositoryId() + { + var pullRequest = await CreatePullRequest(_context); + + const string body = "A review comment message"; + const int position = 1; + + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); + + var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id); + + AssertComment(commentFromGitHub, body, position); + + var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, new NewReaction(ReactionType.Heart)); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var reactions = await _github.Reaction.PullRequestReviewComment.GetAll(_context.Repository.Id, commentFromGitHub.Id, options); + + Assert.Equal(1, reactions.Count); + Assert.Equal(reaction.Id, reactions[0].Id); + Assert.Equal(reaction.Content, reactions[0].Content); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfReactionsWithStartWithRepositoryId() + { + var pullRequest = await CreatePullRequest(_context); + + const string body = "A review comment message"; + const int position = 1; + + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); + + var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id); + + AssertComment(commentFromGitHub, body, position); + + var reactions = new List(); + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Hooray }; + for (var i = 0; i < 2; i++) + { + var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, new NewReaction(reactionsContent[i])); + reactions.Add(reaction); + } + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var reactionsInfo = await _github.Reaction.PullRequestReviewComment.GetAll(_context.Repository.Id, commentFromGitHub.Id, options); + + Assert.Equal(1, reactionsInfo.Count); + Assert.Equal(reactions.Last().Id, reactionsInfo[0].Id); + Assert.Equal(reactions.Last().Content, reactionsInfo[0].Content); + } + + [IntegrationTest] + public async Task ReturnsDistinctReactionsBasedOnStartPageWithRepositoryId() + { + var pullRequest = await CreatePullRequest(_context); + + const string body = "A review comment message"; + const int position = 1; + + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); + + var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id); + + AssertComment(commentFromGitHub, body, position); + + var reactionsContent = new[] { ReactionType.Heart, ReactionType.Hooray }; + for (var i = 0; i < 2; i++) + { + var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, new NewReaction(reactionsContent[i])); + } + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + var firstPage = await _github.Reaction.PullRequestReviewComment.GetAll(_context.Repository.Id, commentFromGitHub.Id, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + var secondPage = await _github.Reaction.PullRequestReviewComment.GetAll(_context.Repository.Id, commentFromGitHub.Id, skipStartOptions); + + Assert.Equal(1, firstPage.Count); + Assert.Equal(1, secondPage.Count); + Assert.Equal(firstPage[0].Id, secondPage[0].Id); + Assert.Equal(firstPage[0].Content, secondPage[0].Content); + } + [IntegrationTest] public async Task CanCreateReaction() { diff --git a/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs b/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs index 0f55c0e8a4..fe9dc39b35 100644 --- a/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs +++ b/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.InteropServices.ComTypes; using System.Threading.Tasks; using NSubstitute; using Xunit; @@ -26,7 +27,25 @@ public async Task RequestsCorrectUrl() await client.GetAll("fake", "repo", 42); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlApiOptions() + { + var connection = Substitute.For(); + var client = new CommitCommentReactionsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAll("fake", "repo", 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -37,7 +56,25 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.GetAll(1, 42); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdApiOptions() + { + var connection = Substitute.For(); + var client = new CommitCommentReactionsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAll(1, 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -48,10 +85,20 @@ public async Task EnsuresNotNullArguments() await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "name", 1, null)); await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); } + + [Fact] + public async Task EnsuresNotNullArgumentsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CommitCommentReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll(1, 1, null)); + } } public class TheCreateMethod diff --git a/Octokit.Tests/Clients/IssueCommentReactionsClientTests.cs b/Octokit.Tests/Clients/IssueCommentReactionsClientTests.cs index 971fc225c6..ef8ec78f57 100644 --- a/Octokit.Tests/Clients/IssueCommentReactionsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentReactionsClientTests.cs @@ -26,7 +26,25 @@ public async Task RequestsCorrectUrl() await client.GetAll("fake", "repo", 42); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlApiOptions() + { + var connection = Substitute.For(); + var client = new IssueCommentReactionsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAll("fake", "repo", 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -37,7 +55,25 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.GetAll(1, 42); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdApiOptions() + { + var connection = Substitute.For(); + var client = new IssueCommentReactionsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAll(1, 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -48,10 +84,20 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "name", 1, null)); await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); } + + [Fact] + public async Task EnsuresNonNullArgumentsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new IssueCommentReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll(1, 1, null)); + } } public class TheCreateMethod diff --git a/Octokit.Tests/Clients/IssueReactionsClientTests.cs b/Octokit.Tests/Clients/IssueReactionsClientTests.cs index 3c0ab6be6c..915d919928 100644 --- a/Octokit.Tests/Clients/IssueReactionsClientTests.cs +++ b/Octokit.Tests/Clients/IssueReactionsClientTests.cs @@ -26,7 +26,25 @@ public async Task RequestsCorrectUrl() await client.GetAll("fake", "repo", 42); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlApiOptions() + { + var connection = Substitute.For(); + var client = new IssueReactionsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAll("fake", "repo", 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -37,7 +55,25 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.GetAll(1, 42); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdApiOptions() + { + var connection = Substitute.For(); + var client = new IssueReactionsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAll(1, 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -48,10 +84,20 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.Issue.GetAll(null, "name", 1)); await Assert.ThrowsAsync(() => client.Issue.GetAll("owner", null, 1)); + await Assert.ThrowsAsync(() => client.Issue.GetAll("owner", "name", 1, null)); await Assert.ThrowsAsync(() => client.Issue.GetAll("", "name", 1)); await Assert.ThrowsAsync(() => client.Issue.GetAll("owner", "", 1)); } + + [Fact] + public async Task EnsuresNonNullArgumentsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new ReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.Issue.GetAll(1, 1, null)); + } } public class TheCreateMethod diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentReactionsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentReactionsClientTests.cs index 054ef7dd85..d0eb73c3e4 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentReactionsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentReactionsClientTests.cs @@ -26,7 +26,24 @@ public async Task RequestsCorrectUrl() await client.GetAll("fake", "repo", 42); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pulls/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pulls/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlApiOptions() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentReactionsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1 + }; + + await client.GetAll("fake", "repo", 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pulls/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -37,7 +54,24 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.GetAll(1, 42); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdApiOptions() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentReactionsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1 + }; + + await client.GetAll(1, 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/42/reactions"), null, "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -48,10 +82,20 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "name", 1, null)); await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); } + + [Fact] + public async Task EnsuresNonNullArgumentsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll(1, 1, null)); + } } public class TheCreateMethod diff --git a/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs b/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs index 021e9f24d7..903d80ffc2 100644 --- a/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs @@ -29,6 +29,24 @@ public void RequestsCorrectUrl() gitHubClient.Received().Reaction.CommitComment.GetAll("fake", "repo", 42); } + [Fact] + public void RequestsCorrectUrlApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCommitCommentReactionsClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAll("fake", "repo", 42, options); + + gitHubClient.Received().Reaction.CommitComment.GetAll("fake", "repo", 42, options); + } + [Fact] public void RequestsCorrectUrlWithRepositoryId() { @@ -40,6 +58,24 @@ public void RequestsCorrectUrlWithRepositoryId() gitHubClient.Received().Reaction.CommitComment.GetAll(1, 42); } + [Fact] + public void RequestsCorrectUrlWithRepositoryIdApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCommitCommentReactionsClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAll(1, 42, options); + + gitHubClient.Received().Reaction.CommitComment.GetAll(1, 42, options); + } + [Fact] public void EnsuresNotNullArguments() { @@ -48,10 +84,20 @@ public void EnsuresNotNullArguments() Assert.Throws(() => client.GetAll(null, "name", 1)); Assert.Throws(() => client.GetAll("owner", null, 1)); + Assert.Throws(() => client.GetAll("owner", "name", 1, null)); Assert.Throws(() => client.GetAll("", "name", 1)); Assert.Throws(() => client.GetAll("owner", "", 1)); } + + [Fact] + public void EnsuresNotNullArgumentsWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCommitCommentReactionsClient(gitHubClient); + + Assert.Throws(() => client.GetAll(1, 1, null)); + } } public class TheCreateMethod diff --git a/Octokit.Tests/Reactive/ObservableIssueCommentReactionsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssueCommentReactionsClientTests.cs index 1081d3b926..be3841ec15 100644 --- a/Octokit.Tests/Reactive/ObservableIssueCommentReactionsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssueCommentReactionsClientTests.cs @@ -26,7 +26,25 @@ public void RequestsCorrectUrl() client.GetAll("fake", "repo", 42); - gitHubClient.Received().Reaction.IssueComment.GetAll("fake", "repo", 42); + gitHubClient.Received().Reaction.IssueComment.GetAll("fake", "repo", 42, Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentReactionsClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAll("fake", "repo", 42, options); + + gitHubClient.Received().Reaction.IssueComment.GetAll("fake", "repo", 42, options); } [Fact] @@ -37,7 +55,25 @@ public void RequestsCorrectUrlWithRepositoryId() client.GetAll(1, 42); - gitHubClient.Received().Reaction.IssueComment.GetAll(1, 42); + gitHubClient.Received().Reaction.IssueComment.GetAll(1, 42, Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryIdApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentReactionsClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAll(1, 42, options); + + gitHubClient.Received().Reaction.IssueComment.GetAll(1, 42, options); } [Fact] @@ -48,10 +84,20 @@ public void EnsuresArgumentsNotNull() Assert.Throws(() => client.GetAll(null, "name", 1)); Assert.Throws(() => client.GetAll("owner", null, 1)); + Assert.Throws(() => client.GetAll("owner", "name", 1, null)); Assert.Throws(() => client.GetAll("", "name", 1)); Assert.Throws(() => client.GetAll("owner", "", 1)); } + + [Fact] + public void EnsuresArgumentsNotNullWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentReactionsClient(gitHubClient); + + Assert.Throws(() => client.GetAll(1, 1, null)); + } } public class TheCreateMethod diff --git a/Octokit.Tests/Reactive/ObservableIssueReactionsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssueReactionsClientTests.cs index 1e47649403..9fa39c9108 100644 --- a/Octokit.Tests/Reactive/ObservableIssueReactionsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssueReactionsClientTests.cs @@ -25,7 +25,24 @@ public void RequestsCorrectUrl() var client = new ObservableIssueReactionsClient(gitHubClient); client.GetAll("fake", "repo", 42); - gitHubClient.Received().Reaction.Issue.GetAll("fake", "repo", 42); + gitHubClient.Received().Reaction.Issue.GetAll("fake", "repo", 42, Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueReactionsClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAll("fake", "repo", 42, options); + gitHubClient.Received().Reaction.Issue.GetAll("fake", "repo", 42, options); } [Fact] @@ -35,7 +52,24 @@ public void RequestsCorrectUrlWithRepositoryId() var client = new ObservableIssueReactionsClient(gitHubClient); client.GetAll(1, 42); - gitHubClient.Received().Reaction.Issue.GetAll(1, 42); + gitHubClient.Received().Reaction.Issue.GetAll(1, 42, Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryIdApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueReactionsClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAll(1, 42, options); + gitHubClient.Received().Reaction.Issue.GetAll(1, 42, options); } [Fact] @@ -46,10 +80,20 @@ public void EnsuresNonNullArguments() Assert.Throws(() => client.GetAll(null, "name", 1)); Assert.Throws(() => client.GetAll("owner", null, 1)); + Assert.Throws(() => client.GetAll("owner", "name", 1, null)); Assert.Throws(() => client.GetAll("", "name", 1)); Assert.Throws(() => client.GetAll("owner", "", 1)); } + + [Fact] + public void EnsuresNonNullArgumentsWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueReactionsClient(gitHubClient); + + Assert.Throws(() => client.GetAll(1, 1, null)); + } } public class TheCreateMethod diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentReactionsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentReactionsClientTests.cs index b26ce47c9c..5dfd98f600 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentReactionsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentReactionsClientTests.cs @@ -29,6 +29,23 @@ public void RequestsCorrectUrl() gitHubClient.Received().Reaction.PullRequestReviewComment.GetAll("fake", "repo", 42); } + [Fact] + public void RequestsCorrectUrlApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentReactionsClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1 + }; + + client.GetAll("fake", "repo", 42, options); + + gitHubClient.Received().Reaction.PullRequestReviewComment.GetAll("fake", "repo", 42, options); + } + [Fact] public void RequestsCorrectUrlWithRepositoryId() { @@ -40,6 +57,23 @@ public void RequestsCorrectUrlWithRepositoryId() gitHubClient.Received().Reaction.PullRequestReviewComment.GetAll(1, 42); } + [Fact] + public void RequestsCorrectUrlWithRepositoryIdApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentReactionsClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1 + }; + + client.GetAll(1, 42, options); + + gitHubClient.Received().Reaction.PullRequestReviewComment.GetAll(1, 42, options); + } + [Fact] public void EnsuresNonNullArguments() { @@ -48,10 +82,20 @@ public void EnsuresNonNullArguments() Assert.Throws(() => client.GetAll(null, "name", 1)); Assert.Throws(() => client.GetAll("owner", null, 1)); + Assert.Throws(() => client.GetAll("owner", "name", 1, null)); Assert.Throws(() => client.GetAll("", "name", 1)); Assert.Throws(() => client.GetAll("owner", "", 1)); } + + [Fact] + public void EnsuresNonNullArgumentsWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentReactionsClient(gitHubClient); + + Assert.Throws(() => client.GetAll(1, 1, null)); + } } public class TheCreateMethod diff --git a/Octokit/Clients/CommitCommentReactionsClient.cs b/Octokit/Clients/CommitCommentReactionsClient.cs index 6decd357bc..7b97705b39 100644 --- a/Octokit/Clients/CommitCommentReactionsClient.cs +++ b/Octokit/Clients/CommitCommentReactionsClient.cs @@ -58,11 +58,26 @@ public Task Create(long repositoryId, int number, NewReaction reaction /// The comment id /// public Task> GetAll(string owner, string name, int number) + { + return GetAll(owner, name, number, ApiOptions.None); + } + + /// + /// Get all reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + /// + public Task> GetAll(string owner, string name, int number, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.CommitCommentReactions(owner, name, number), AcceptHeaders.ReactionsPreview); + return ApiConnection.GetAll(ApiUrls.CommitCommentReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -74,7 +89,22 @@ public Task> GetAll(string owner, string name, int numbe /// public Task> GetAll(long repositoryId, int number) { - return ApiConnection.GetAll(ApiUrls.CommitCommentReactions(repositoryId, number), AcceptHeaders.ReactionsPreview); + return GetAll(repositoryId, number, ApiOptions.None); + } + + /// + /// Get all reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// Options for changing the API response + /// + public Task> GetAll(long repositoryId, int number, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.CommitCommentReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); } } } diff --git a/Octokit/Clients/ICommitCommentReactionsClient.cs b/Octokit/Clients/ICommitCommentReactionsClient.cs index 7725f9df2d..c64c25fa19 100644 --- a/Octokit/Clients/ICommitCommentReactionsClient.cs +++ b/Octokit/Clients/ICommitCommentReactionsClient.cs @@ -40,9 +40,19 @@ public interface ICommitCommentReactionsClient /// The name of the repository /// The comment id /// - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAll(string owner, string name, int number); + /// + /// Get all reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + /// + Task> GetAll(string owner, string name, int number, ApiOptions options); + /// /// Get all reactions for a specified Commit Comment /// @@ -50,7 +60,16 @@ public interface ICommitCommentReactionsClient /// The owner of the repository /// The comment id /// - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAll(long repositoryId, int number); + + /// + /// Get all reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// Options for changing the API response + /// + Task> GetAll(long repositoryId, int number, ApiOptions options); } } diff --git a/Octokit/Clients/IIssueCommentReactionsClient.cs b/Octokit/Clients/IIssueCommentReactionsClient.cs index c2eec16264..4fd60ba45d 100644 --- a/Octokit/Clients/IIssueCommentReactionsClient.cs +++ b/Octokit/Clients/IIssueCommentReactionsClient.cs @@ -37,16 +37,33 @@ public interface IIssueCommentReactionsClient /// The owner of the repository /// The name of the repository /// The comment id - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAll(string owner, string name, int number); + /// + /// Get all reactions for a specified Issue Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + Task> GetAll(string owner, string name, int number, ApiOptions options); + /// /// Get all reactions for a specified Issue Comment /// /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment /// The Id of the repository /// The comment id - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAll(long repositoryId, int number); + + /// + /// Get all reactions for a specified Issue Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment + /// The Id of the repository + /// The comment id + /// Options for changing the API response + Task> GetAll(long repositoryId, int number, ApiOptions options); } } diff --git a/Octokit/Clients/IIssueReactionsClient.cs b/Octokit/Clients/IIssueReactionsClient.cs index ffc7cc56e6..0de3feff55 100644 --- a/Octokit/Clients/IIssueReactionsClient.cs +++ b/Octokit/Clients/IIssueReactionsClient.cs @@ -18,18 +18,35 @@ public interface IIssueReactionsClient /// The owner of the repository /// The name of the repository /// The issue id - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAll(string owner, string name, int number); + /// + /// Get all reactions for a specified Issue + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue id + /// Options for changing the API response + Task> GetAll(string owner, string name, int number, ApiOptions options); + /// /// Get all reactions for a specified Issue /// /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue /// The Id of the repository /// The issue id - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAll(long repositoryId, int number); + /// + /// Get all reactions for a specified Issue + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue + /// The Id of the repository + /// The issue id + /// Options for changing the API response + Task> GetAll(long repositoryId, int number, ApiOptions options); + /// /// Creates a reaction for a specified Issue /// diff --git a/Octokit/Clients/IPullRequestReviewCommentReactionsClient.cs b/Octokit/Clients/IPullRequestReviewCommentReactionsClient.cs index 10e3dbad00..96a47395e5 100644 --- a/Octokit/Clients/IPullRequestReviewCommentReactionsClient.cs +++ b/Octokit/Clients/IPullRequestReviewCommentReactionsClient.cs @@ -18,18 +18,35 @@ public interface IPullRequestReviewCommentReactionsClient /// The owner of the repository /// The name of the repository /// The comment id - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAll(string owner, string name, int number); + /// + /// Get all reactions for a specified Pull Request Review Comment. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + Task> GetAll(string owner, string name, int number, ApiOptions options); + /// /// Get all reactions for a specified Pull Request Review Comment. /// /// https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment /// The Id of the repository /// The comment id - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAll(long repositoryId, int number); + /// + /// Get all reactions for a specified Pull Request Review Comment. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment + /// The Id of the repository + /// The comment id + /// Options for changing the API response + Task> GetAll(long repositoryId, int number, ApiOptions options); + /// /// Creates a reaction for a specified Pull Request Review Comment. /// diff --git a/Octokit/Clients/IssueCommentReactionsClient.cs b/Octokit/Clients/IssueCommentReactionsClient.cs index 6f3f7ebac4..21ef4b5e1a 100644 --- a/Octokit/Clients/IssueCommentReactionsClient.cs +++ b/Octokit/Clients/IssueCommentReactionsClient.cs @@ -55,11 +55,25 @@ public Task Create(long repositoryId, int number, NewReaction reaction /// The name of the repository /// The comment id public Task> GetAll(string owner, string name, int number) + { + return GetAll(owner, name, number, ApiOptions.None); + } + + /// + /// Get all reactions for a specified Issue Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + public Task> GetAll(string owner, string name, int number, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.IssueCommentReactions(owner, name, number), AcceptHeaders.ReactionsPreview); + return ApiConnection.GetAll(ApiUrls.IssueCommentReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -70,7 +84,21 @@ public Task> GetAll(string owner, string name, int numbe /// The comment id public Task> GetAll(long repositoryId, int number) { - return ApiConnection.GetAll(ApiUrls.IssueCommentReactions(repositoryId, number), AcceptHeaders.ReactionsPreview); + return GetAll(repositoryId, number, ApiOptions.None); + } + + /// + /// Get all reactions for a specified Issue Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment + /// The Id of the repository + /// The comment id + /// Options for changing the API response + public Task> GetAll(long repositoryId, int number, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.IssueCommentReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); } } } diff --git a/Octokit/Clients/IssueReactionsClient.cs b/Octokit/Clients/IssueReactionsClient.cs index 6b0dd40667..02b826d26c 100644 --- a/Octokit/Clients/IssueReactionsClient.cs +++ b/Octokit/Clients/IssueReactionsClient.cs @@ -24,11 +24,25 @@ public IssueReactionsClient(IApiConnection apiConnection) /// The name of the repository /// The issue id public Task> GetAll(string owner, string name, int number) + { + return GetAll(owner, name, number, ApiOptions.None); + } + + /// + /// Get all reactions for a specified Issue + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue id + /// Options for changing the API response + public Task> GetAll(string owner, string name, int number, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.IssueReactions(owner, name, number), AcceptHeaders.ReactionsPreview); + return ApiConnection.GetAll(ApiUrls.IssueReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -39,7 +53,21 @@ public Task> GetAll(string owner, string name, int numbe /// The issue id public Task> GetAll(long repositoryId, int number) { - return ApiConnection.GetAll(ApiUrls.IssueReactions(repositoryId, number), AcceptHeaders.ReactionsPreview); + return GetAll(repositoryId, number, ApiOptions.None); + } + + /// + /// Get all reactions for a specified Issue + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-an-issue + /// The Id of the repository + /// The issue id + /// Options for changing the API response + public Task> GetAll(long repositoryId, int number, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.IssueReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); } /// diff --git a/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs b/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs index 251d9acdd0..695b5f0e52 100644 --- a/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentReactionsClient.cs @@ -24,11 +24,25 @@ public PullRequestReviewCommentReactionsClient(IApiConnection apiConnection) /// The name of the repository /// The comment id public Task> GetAll(string owner, string name, int number) + { + return GetAll(owner, name, number, ApiOptions.None); + } + + /// + /// Get all reactions for a specified Pull Request Review Comment. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// Options for changing the API response + public Task> GetAll(string owner, string name, int number, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), AcceptHeaders.ReactionsPreview); + return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -39,7 +53,21 @@ public Task> GetAll(string owner, string name, int numbe /// The comment id public Task> GetAll(long repositoryId, int number) { - return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentReaction(repositoryId, number), AcceptHeaders.ReactionsPreview); + return GetAll(repositoryId, number, ApiOptions.None); + } + + /// + /// Get all reactions for a specified Pull Request Review Comment. + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment + /// The Id of the repository + /// The comment id + /// Options for changing the API response + public Task> GetAll(long repositoryId, int number, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentReaction(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); } ///