diff --git a/Octokit.Reactive/Clients/ObservableIssuesClient.cs b/Octokit.Reactive/Clients/ObservableIssuesClient.cs index 766838413e..97c4c021da 100644 --- a/Octokit.Reactive/Clients/ObservableIssuesClient.cs +++ b/Octokit.Reactive/Clients/ObservableIssuesClient.cs @@ -144,7 +144,7 @@ public IObservable GetAllForCurrent(IssueRequest request, ApiOptions opti Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.Issues(), request.ToParametersDictionary(), options); + return _connection.GetAndFlattenAllPages(ApiUrls.Issues(), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// @@ -203,7 +203,7 @@ public IObservable GetAllForOwnedAndMemberRepositories(IssueRequest reque Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.IssuesForOwnedAndMember(), request.ToParametersDictionary(), options); + return _connection.GetAndFlattenAllPages(ApiUrls.IssuesForOwnedAndMember(), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// @@ -267,7 +267,7 @@ public IObservable GetAllForOrganization(string organization, IssueReques Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.Issues(organization), request.ToParametersDictionary(), options); + return _connection.GetAndFlattenAllPages(ApiUrls.Issues(organization), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// @@ -381,7 +381,7 @@ public IObservable GetAllForRepository(string owner, string name, Reposit Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), options); + return _connection.GetAndFlattenAllPages(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs index dd5f73f832..5fa2f93fb5 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs @@ -64,7 +64,7 @@ public IObservable GetAll(string owner, string name, i Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewComments(owner, name, number), options); + return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewComments(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -178,7 +178,7 @@ public IObservable GetAllForRepository(string owner, s Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentsRepository(owner, name), request.ToParametersDictionary(), + return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentsRepository(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } @@ -194,7 +194,10 @@ public IObservable GetAllForRepository(int repositoryI Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentsRepository(repositoryId), request.ToParametersDictionary(), + return _connection.GetAndFlattenAllPages( + ApiUrls.PullRequestReviewCommentsRepository(repositoryId), + request.ToParametersDictionary(), + AcceptHeaders.ReactionsPreview, options); } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs index 48391689f8..5d5529f55e 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs @@ -87,7 +87,7 @@ public IObservable GetAllForRepository(string owner, string name, Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name), options); + return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -100,7 +100,7 @@ public IObservable GetAllForRepository(int repositoryId, ApiOptio { Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId), options); + return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -147,7 +147,7 @@ public IObservable GetAllForCommit(string owner, string name, str Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name, sha), options); + return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name, sha), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -162,7 +162,7 @@ public IObservable GetAllForCommit(int repositoryId, string sha, Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(options, "options"); - return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId, sha), options); + return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId, sha), null, AcceptHeaders.ReactionsPreview, options); } /// diff --git a/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs index ec03237a17..7965c6fe33 100644 --- a/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs @@ -83,7 +83,7 @@ public async Task CanCreateReaction() { var newReaction = new NewReaction(reactionType); - var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction); + var reaction = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction); Assert.IsType(reaction); Assert.Equal(reactionType, reaction.Content); diff --git a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs index 071a841e0a..b772e21238 100644 --- a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs @@ -3,13 +3,17 @@ using Octokit.Tests.Integration; using Octokit.Tests.Integration.Helpers; using Xunit; +using System; +using System.Linq; +using System.Collections.Generic; public class IssueCommentsClientTests { public class TheGetMethod { + readonly IGitHubClient _github; readonly IIssueCommentsClient _issueCommentsClient; - + const string owner = "octokit"; const string name = "octokit.net"; const int id = 12067722; @@ -17,9 +21,9 @@ public class TheGetMethod public TheGetMethod() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; + _issueCommentsClient = _github.Issue.Comment; } [IntegrationTest] @@ -37,10 +41,37 @@ public async Task ReturnsIssueCommentWithRepositoryId() Assert.NotNull(comment); } + + [IntegrationTest] + public async Task CanGetReactionPayload() + { + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests"))) + { + // Create a test issue + var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName); + + // Create a test comment with reactions + var commentId = await HelperCreateIssueCommentWithReactions(context.RepositoryOwner, context.RepositoryName, issueNumber); + + // Retrieve the comment + var retrieved = await _issueCommentsClient.Get(context.RepositoryOwner, context.RepositoryName, commentId); + + // Check the reactions + Assert.True(retrieved.Id > 0); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } } public class TheGetAllForRepositoryMethod { + readonly IGitHubClient _github; readonly IIssueCommentsClient _issueCommentsClient; const string owner = "octokit"; @@ -49,9 +80,9 @@ public class TheGetAllForRepositoryMethod public TheGetAllForRepositoryMethod() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; + _issueCommentsClient = _github.Issue.Comment; } [IntegrationTest] @@ -181,10 +212,50 @@ public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId() Assert.NotEqual(firstPageIssueComments[3].Id, secondPageIssueComments[3].Id); Assert.NotEqual(firstPageIssueComments[4].Id, secondPageIssueComments[4].Id); } + + [IntegrationTest] + public async Task CanGetReactionPayload() + { + var numberToCreate = 2; + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests"))) + { + var commentIds = new List(); + + // Create multiple test issues + for (int count = 1; count <= numberToCreate; count++) + { + var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName); + + // Each with a comment with reactions + var commentId = await HelperCreateIssueCommentWithReactions(context.RepositoryOwner, context.RepositoryName, issueNumber); + commentIds.Add(commentId); + } + Assert.Equal(numberToCreate, commentIds.Count); + + // Retrieve all issue comments for the repo + var issueComments = await _issueCommentsClient.GetAllForRepository(context.RepositoryOwner, context.RepositoryName); + + // Check the reactions + foreach (var commentId in commentIds) + { + var retrieved = issueComments.FirstOrDefault(x => x.Id == commentId); + + Assert.NotNull(retrieved); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } + } } public class TheGetAllForIssueMethod { + readonly IGitHubClient _github; readonly IIssueCommentsClient _issueCommentsClient; const string owner = "octokit"; @@ -194,9 +265,9 @@ public class TheGetAllForIssueMethod public TheGetAllForIssueMethod() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; + _issueCommentsClient = _github.Issue.Comment; } [IntegrationTest] @@ -326,6 +397,45 @@ public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId() Assert.NotEqual(firstPageIssueComments[3].Id, secondPageIssueComments[3].Id); Assert.NotEqual(firstPageIssueComments[4].Id, secondPageIssueComments[4].Id); } + + [IntegrationTest] + public async Task CanGetReactionPayload() + { + var numberToCreate = 2; + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests"))) + { + var commentIds = new List(); + + // Create a single test issue + var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName); + + // With multiple comments with reactions + for (int count = 1; count <= numberToCreate; count++) + { + var commentId = await HelperCreateIssueCommentWithReactions(context.RepositoryOwner, context.RepositoryName, issueNumber); + commentIds.Add(commentId); + } + Assert.Equal(numberToCreate, commentIds.Count); + + // Retrieve all comments for the issue + var issueComments = await _issueCommentsClient.GetAllForIssue(context.RepositoryOwner, context.RepositoryName, issueNumber); + + // Check the reactions + foreach (var commentId in commentIds) + { + var retrieved = issueComments.FirstOrDefault(x => x.Id == commentId); + + Assert.NotNull(retrieved); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } + } } public class TheCreateMethod @@ -472,4 +582,36 @@ public async Task DeleteIssueWithRepositoryId() await Assert.ThrowsAsync(() => _issueCommentsClient.Get(_context.Repository.Id, comment.Id)); } } + + async static Task HelperCreateIssue(string owner, string repo) + { + var github = Helper.GetAuthenticatedClient(); + + var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" }; + var issue = await github.Issue.Create(owner, repo, newIssue); + Assert.NotNull(issue); + + return issue.Number; + } + + async static Task HelperCreateIssueCommentWithReactions(string owner, string repo, int number) + { + var github = Helper.GetAuthenticatedClient(); + + var issueComment = await github.Issue.Comment.Create(owner, repo, number, "A test issue comment"); + Assert.NotNull(issueComment); + + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await github.Reaction.IssueComment.Create(owner, repo, issueComment.Id, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(issueComment.User.Id, reaction.User.Id); + } + + return issueComment.Id; + } } diff --git a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index e2aa83c762..205d99d969 100644 --- a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading.Tasks; @@ -9,15 +10,16 @@ public class IssuesClientTests : IDisposable { + private readonly IGitHubClient _github; private readonly RepositoryContext _context; private readonly IIssuesClient _issuesClient; public IssuesClientTests() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _issuesClient = github.Issue; - _context = github.CreateRepositoryContext(new NewRepository(repoName)).Result; + _issuesClient = _github.Issue; + _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result; } [IntegrationTest] @@ -1053,6 +1055,87 @@ public async Task GetAllForOrganizationContainsRepositoryData() } } + [IntegrationTest] + public async Task CanGetReactionPayload() + { + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssuesReactionTests"))) + { + // Create a test issue with reactions + var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName); + + // Retrieve the issue + var retrieved = await _issuesClient.Get(context.RepositoryOwner, context.RepositoryName, issueNumber); + + // Check the reactions + Assert.True(retrieved.Id > 0); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } + + [IntegrationTest] + public async Task CanGetReactionPayloadForMultipleIssues() + { + var numberToCreate = 2; + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssuesReactionTests"))) + { + var issueNumbers = new List(); + + // Create multiple test issues with reactions + for (int count = 1; count <= numberToCreate; count++) + { + var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName); + issueNumbers.Add(issueNumber); + } + Assert.Equal(numberToCreate, issueNumbers.Count); + + // Retrieve all issues for the repo + var issues = await _issuesClient.GetAllForRepository(context.RepositoryOwner, context.RepositoryName); + + // Check the reactions + foreach (var issueNumber in issueNumbers) + { + var retrieved = issues.FirstOrDefault(x => x.Number == issueNumber); + + Assert.NotNull(retrieved); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } + } + + async static Task HelperCreateIssue(string owner, string repo) + { + var github = Helper.GetAuthenticatedClient(); + + var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" }; + var issue = await github.Issue.Create(owner, repo, newIssue); + Assert.NotNull(issue); + + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await github.Reaction.Issue.Create(owner, repo, issue.Number, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(issue.User.Id, reaction.User.Id); + } + + return issue.Number; + } + public void Dispose() { _context.Dispose(); diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs index e457144caf..92f21dc963 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs @@ -90,7 +90,7 @@ public async Task CanCreateReaction() { var newReaction = new NewReaction(reactionType); - var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReaction); + var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReaction); Assert.IsType(reaction); Assert.Equal(reactionType, reaction.Content); diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index 7e4a34adef..1a7832009f 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -14,8 +14,6 @@ public class PullRequestReviewCommentsClientTests : IDisposable private readonly RepositoryContext _context; const string branchName = "new-branch"; - const string branchHead = "heads/" + branchName; - const string branchRef = "refs/" + branchHead; const string path = "CONTRIBUTING.md"; public PullRequestReviewCommentsClientTests() @@ -408,6 +406,7 @@ public async Task CanGetForRepositoryWithRepositoryId() var pullRequestComments = await _client.GetAllForRepository(_context.Repository.Id); AssertComments(pullRequestComments, commentsToCreate, position); + } [IntegrationTest] @@ -849,10 +848,14 @@ static void AssertComments(IReadOnlyList comments, Lis /// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request) /// /// - async Task CreatePullRequest(RepositoryContext context) + async Task CreatePullRequest(RepositoryContext context, string branch = branchName) { - var repoName = context.RepositoryName; + string branchHead = "heads/" + branch; + string branchRef = "refs/" + branchHead; + + var repoName = context.RepositoryName; + // Creating a commit in master var createdCommitInMaster = await CreateCommit(repoName, "Hello World!", "README.md", "heads/master", "A master commit message"); @@ -868,7 +871,7 @@ async Task CreatePullRequest(RepositoryContext context) // Creating a pull request - var pullRequest = new NewPullRequest("Nice title for the pull request", branchName, "master"); + var pullRequest = new NewPullRequest("Nice title for the pull request", branch, "master"); var createdPullRequest = await _github.PullRequest.Create(Helper.UserName, repoName, pullRequest); var data = new PullRequestData @@ -919,4 +922,105 @@ class PullRequestData public int Number { get; set; } public string Sha { get; set; } } + + [IntegrationTest] + public async Task CanGetReactionPayloadForPullRequestReviews() + { + int numberToCreate = 2; + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("PullRequestReviewCommentsReactionTests"))) + { + var commentIds = new List(); + + // Create a test pull request + var pullRequest = await CreatePullRequest(context); + + // With multiple review comments with reactions + for (int count = 1; count <= numberToCreate; count++) + { + var commentId = await HelperCreatePullRequestReviewCommentWithReactions(context.RepositoryOwner, context.RepositoryName, pullRequest); + commentIds.Add(commentId); + } + Assert.Equal(numberToCreate, commentIds.Count); + + // Retrieve all review comments for the pull request + var reviewComments = await _client.GetAll(context.RepositoryOwner, context.RepositoryName, pullRequest.Number); + + // Check the reactions + foreach (var commentId in commentIds) + { + var retrieved = reviewComments.FirstOrDefault(x => x.Id == commentId); + + Assert.NotNull(retrieved); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } + } + + [IntegrationTest] + public async Task CanGetReactionPayloadForRepositoryPullRequestReviews() + { + int numberToCreate = 2; + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("PullRequestReviewCommentsReactionTests"))) + { + var commentIds = new List(); + + // Create multiple test pull requests + for (int count = 1; count <= numberToCreate; count++) + { + var pullRequest = await CreatePullRequest(context, "branch" + count); + + // Each with a review comment with reactions + var commentId = await HelperCreatePullRequestReviewCommentWithReactions(context.RepositoryOwner, context.RepositoryName, pullRequest); + commentIds.Add(commentId); + } + Assert.Equal(numberToCreate, commentIds.Count); + + // Retrieve all review comments for the repo + var reviewComments = await _client.GetAllForRepository(context.RepositoryOwner, context.RepositoryName); + + // Check the reactions + foreach (var commentId in commentIds) + { + var retrieved = reviewComments.FirstOrDefault(x => x.Id == commentId); + + Assert.NotNull(retrieved); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } + } + + async Task HelperCreatePullRequestReviewCommentWithReactions(string owner, string repo, PullRequestData pullRequest) + { + var github = Helper.GetAuthenticatedClient(); + + const string body = "A review comment message"; + const int position = 1; + + var reviewComment = await CreateComment(body, position, repo, pullRequest.Sha, pullRequest.Number); + + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await github.Reaction.PullRequestReviewComment.Create(owner, repo, reviewComment.Id, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(reviewComment.User.Id, reaction.User.Id); + } + + return reviewComment.Id; + } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs index 8421cfdaa6..32df136d57 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; @@ -9,6 +11,7 @@ public class RepositoryCommentsClientTests { public class TheGetMethod { + readonly IGitHubClient _github; readonly IRepositoryCommentsClient _fixture; const string owner = "octocat"; const string name = "Hello-World"; @@ -16,9 +19,9 @@ public class TheGetMethod public TheGetMethod() { - var client = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _fixture = client.Repository.Comment; + _fixture = _github.Repository.Comment; } [IntegrationTest] @@ -34,10 +37,37 @@ public async Task CanGetCommentWithRepositoryId() var commit = await _fixture.Get(repositoryId, 1467023); Assert.NotNull(commit); } + + [IntegrationTest] + public async Task CanGetReactionPayload() + { + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("CommitCommentsReactionTests"))) + { + // Create a test commit + var commit = await HelperCreateCommit(context.RepositoryOwner, context.RepositoryName); + + // Create a test comment with reactions + var commentId = await HelperCreateCommitCommentWithReactions(context.RepositoryOwner, context.RepositoryName, commit.Sha); + + // Retrieve the comment + var retrieved = await _fixture.Get(context.RepositoryOwner, context.RepositoryName, commentId); + + // Check the reactions + Assert.True(retrieved.Id > 0); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } } public class TheGetAllForRepositoryMethod { + readonly IGitHubClient _github; readonly IRepositoryCommentsClient _fixture; const string owner = "octocat"; const string name = "Hello-World"; @@ -45,9 +75,9 @@ public class TheGetAllForRepositoryMethod public TheGetAllForRepositoryMethod() { - var client = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _fixture = client.Repository.Comment; + _fixture = _github.Repository.Comment; } [IntegrationTest] @@ -169,10 +199,50 @@ public async Task ReturnsDistinctResultsBasedOnStartWithRepositoryId() Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id); Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id); } + + [IntegrationTest] + public async Task CanGetReactionPayload() + { + var numberToCreate = 2; + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("CommitCommentsReactionTests"))) + { + var commentIds = new List(); + + // Create multiple test commits + for (int count = 1; count <= numberToCreate; count++) + { + var commit = await HelperCreateCommit(context.RepositoryOwner, context.RepositoryName); + + // Each with a comment with reactions + var commentId = await HelperCreateCommitCommentWithReactions(context.RepositoryOwner, context.RepositoryName, commit.Sha); + commentIds.Add(commentId); + } + Assert.Equal(numberToCreate, commentIds.Count); + + // Retrieve all comments for the repo + var commitComments = await _fixture.GetAllForRepository(context.RepositoryOwner, context.RepositoryName); + + // Check the reactions + foreach (var commentId in commentIds) + { + var retrieved = commitComments.FirstOrDefault(x => x.Id == commentId); + + Assert.NotNull(retrieved); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } + } } public class TheGetAllForCommitMethod { + readonly IGitHubClient _github; readonly IRepositoryCommentsClient _fixture; const string owner = "octocat"; const string name = "Hello-World"; @@ -180,9 +250,9 @@ public class TheGetAllForCommitMethod public TheGetAllForCommitMethod() { - var client = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _fixture = client.Repository.Comment; + _fixture = _github.Repository.Comment; } [IntegrationTest] @@ -304,6 +374,45 @@ public async Task ReturnsDistinctResultsBasedOnStartForCommitWithRepositoryId() Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id); Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id); } + + [IntegrationTest] + public async Task CanGetReactionPayload() + { + var numberToCreate = 2; + using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("CommitCommentsReactionTests"))) + { + var commentIds = new List(); + + // Create a single test commit + var commit = await HelperCreateCommit(context.RepositoryOwner, context.RepositoryName); + + // With multiple comments with reactions + for (int count = 1; count <= numberToCreate; count++) + { + var commentId = await HelperCreateCommitCommentWithReactions(context.RepositoryOwner, context.RepositoryName, commit.Sha); + commentIds.Add(commentId); + } + Assert.Equal(numberToCreate, commentIds.Count); + + // Retrieve all comments for the commit + var commitComments = await _fixture.GetAllForCommit(context.RepositoryOwner, context.RepositoryName, commit.Sha); + + // Check the reactions + foreach (var commentId in commentIds) + { + var retrieved = commitComments.FirstOrDefault(x => x.Id == commentId); + + Assert.NotNull(retrieved); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + } + } } public class TheCreateMethod : IDisposable @@ -314,7 +423,6 @@ public class TheCreateMethod : IDisposable public TheCreateMethod() { _github = Helper.GetAuthenticatedClient(); - _context = _github.CreateRepositoryContext("public-repo").Result; } @@ -377,6 +485,38 @@ public async Task CanCreateCommentWithRepositoryId() Assert.NotNull(retrieved); } + [IntegrationTest] + public async Task CanGetReactionPayload() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.Repository.Id, + commit.Sha, comment); + + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(result.User.Id, reaction.User.Id); + } + var retrieved = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id); + + Assert.True(retrieved.Id > 0); + Assert.Equal(6, retrieved.Reactions.TotalCount); + Assert.Equal(1, retrieved.Reactions.Plus1); + Assert.Equal(1, retrieved.Reactions.Hooray); + Assert.Equal(1, retrieved.Reactions.Heart); + Assert.Equal(1, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(1, retrieved.Reactions.Minus1); + } + public void Dispose() { _context.Dispose(); @@ -578,4 +718,52 @@ public void Dispose() _context.Dispose(); } } + + async static Task HelperCreateCommit(string owner, string repo) + { + var client = Helper.GetAuthenticatedClient(); + + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + var blobResult = await client.Git.Blob.Create(owner, repo, blob); + + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem + { + Type = TreeType.Blob, + Mode = FileMode.File, + Path = "README.md", + Sha = blobResult.Sha + }); + + var treeResult = await client.Git.Tree.Create(owner, repo, newTree); + + var newCommit = new NewCommit("test-commit", treeResult.Sha); + + return await client.Git.Commit.Create(owner, repo, newCommit); + } + + async static Task HelperCreateCommitCommentWithReactions(string owner, string repo, string sha) + { + var github = Helper.GetAuthenticatedClient(); + + var commitComment = await github.Repository.Comment.Create(owner, repo, sha, new NewCommitComment("A test comment")); + Assert.NotNull(commitComment); + + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await github.Reaction.CommitComment.Create(owner, repo, commitComment.Id, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(commitComment.User.Id, reaction.User.Id); + } + + return commitComment.Id; + } } diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index 2354e780f4..46a803a5fe 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -22,8 +22,8 @@ public async Task RequestsCorrectUrl() connection.Received().Get( Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42"), - Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -34,7 +34,9 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.Get(1, 42); - connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/issues/comments/42")); + connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/issues/comments/42"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -63,7 +65,7 @@ public async Task RequestsCorrectUrl() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -75,7 +77,10 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.GetAllForRepository(1); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/comments"), Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); } [Fact] @@ -96,7 +101,7 @@ public async Task RequestsCorrectUrlWithApiOptions() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", options); } @@ -115,7 +120,10 @@ public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() await client.GetAllForRepository(1, options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/comments"), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", + options); } [Fact] @@ -152,7 +160,7 @@ public async Task RequestsCorrectUrl() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fake/repo/issues/3/comments"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -164,7 +172,10 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.GetAllForIssue(1, 3); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/3/comments"), Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/3/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); } [Fact] @@ -185,7 +196,7 @@ public async Task RequestsCorrectUrlWithApiOptions() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fake/repo/issues/3/comments"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", options); } @@ -204,7 +215,10 @@ public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() await client.GetAllForIssue(1, 3, options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/3/comments"), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/3/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", + options); } [Fact] diff --git a/Octokit.Tests/Clients/IssuesClientTests.cs b/Octokit.Tests/Clients/IssuesClientTests.cs index b3b5f539ea..981f69b6ef 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -20,7 +20,9 @@ public async Task RequestsCorrectUrl() await client.Get("fake", "repo", 42); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42")); + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -31,7 +33,9 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.Get(1, 42); - connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/issues/42")); + connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/issues/42"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -69,7 +73,9 @@ public async Task RequestsCorrectUrl() await client.GetAllForCurrent(); connection.Received().GetAll(Arg.Is(u => u.ToString() == "issues"), - Arg.Any>(), Args.ApiOptions); + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); } [Fact] @@ -86,6 +92,7 @@ public async Task SendsAppropriateParameters() && d["sort"] == "created" && d["state"] == "open" && d["direction"] == "asc"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } } @@ -113,6 +120,7 @@ public async Task RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/issues"), Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } } @@ -154,6 +162,7 @@ public async Task RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/issues"), Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -174,6 +183,7 @@ public void SendsAppropriateParameters() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } } @@ -226,6 +236,7 @@ public async Task RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -239,6 +250,7 @@ public async Task RequestsCorrectUrlWithRepositoryId() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues"), Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -257,7 +269,10 @@ public async Task RequestsCorrectUrlWithApiOptions() await client.GetAllForRepository("fake", "repo", options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), Arg.Any>(), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", + options); } [Fact] @@ -277,6 +292,7 @@ public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues"), Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", options); } @@ -297,6 +313,7 @@ public async Task SendsAppropriateParameters() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -317,6 +334,7 @@ public async Task SendsAppropriateParametersWithRepositoryId() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -344,6 +362,7 @@ public async Task SendsAppropriateParametersWithApiOptions() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + "application/vnd.github.squirrel-girl-preview", options); } @@ -371,6 +390,7 @@ public async Task SendsAppropriateParametersWithRepositoryIdWithApiOptions() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + "application/vnd.github.squirrel-girl-preview", options); } } diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index c6377fad14..2217f9b59a 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -98,7 +98,9 @@ public async Task RequestsCorrectUrl() await client.GetAll("owner", "name", 7); connection.Received().GetAll( - Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), Args.ApiOptions); + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } [Fact] @@ -129,7 +131,9 @@ public async Task RequestsCorrectUrlWithApiOptions() await client.GetAll("owner", "name", 7, options); connection.Received().GetAll( - Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), options); + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -195,7 +199,9 @@ public async Task RequestsCorrectUrl() Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), Args.ApiOptions); + && d["sort"] == "updated"), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); } [Fact] @@ -217,7 +223,8 @@ public async Task RequestsCorrectUrlWithRepositoryId() Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), Args.ApiOptions); + && d["sort"] == "updated"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } [Fact] @@ -246,7 +253,9 @@ public async Task RequestsCorrectUrlWithApiOptions() Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), options); + && d["sort"] == "updated"), + "application/vnd.github.squirrel-girl-preview", + options); } [Fact] @@ -275,7 +284,8 @@ public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), options); + && d["sort"] == "updated"), + "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -289,7 +299,9 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArguments() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), Args.ApiOptions); + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); } [Fact] @@ -303,7 +315,8 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithRepositor connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), Args.ApiOptions); + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } [Fact] @@ -324,7 +337,9 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOption connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), options); + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview", + options); } [Fact] @@ -345,7 +360,8 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOption connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), options); + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -402,7 +418,10 @@ public void RequestsCorrectUrl() client.GetComment("owner", "name", 53); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/53")); + connection.Received().Get( + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/53"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview"); } [Fact] diff --git a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs index b54ef6a693..d255289d5e 100644 --- a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs @@ -20,7 +20,7 @@ public async Task RequestsCorrectUrl() await client.Get("fake", "repo", 42); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/comments/42")); + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/comments/42"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -31,7 +31,7 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.Get(1, 42); - connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/comments/42")); + connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/comments/42"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -57,7 +57,7 @@ public async Task RequestsCorrectUrl() await client.GetAllForRepository("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/comments"), Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/comments"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } [Fact] @@ -68,7 +68,7 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.GetAllForRepository(1); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments"), Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } [Fact] @@ -86,7 +86,7 @@ public async Task RequestsCorrectUrlWithApiOptions() await client.GetAllForRepository("fake", "repo", options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/comments"), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/comments"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -104,7 +104,7 @@ public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() await client.GetAllForRepository(1, options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments"), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -116,7 +116,7 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null)); - + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); @@ -139,8 +139,10 @@ public async Task RequestsCorrectUrl() await client.GetAllForCommit("fake", "repo", "sha"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/comments"), - Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); } [Fact] @@ -151,7 +153,9 @@ public async Task RequestsCorrectUrlWithRepositoryId() await client.GetAllForCommit(1, "sha"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/commits/sha/comments"), + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/commits/sha/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -170,7 +174,8 @@ public async Task RequestsCorrectUrlWithApiOptions() await client.GetAllForCommit("fake", "repo", "sha", options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/comments"), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/comments"), Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -188,7 +193,9 @@ public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() await client.GetAllForCommit(1, "sha", options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/commits/sha/comments"), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/commits/sha/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -207,7 +214,7 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.GetAllForCommit(1, null, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForCommit(1, "sha", null)); - + await Assert.ThrowsAsync(() => client.GetAllForCommit("", "name", "sha")); await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "", "sha")); await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", "")); diff --git a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs index 9471a2d0c0..7df08bb0d3 100644 --- a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs @@ -94,7 +94,8 @@ public void RequestsCorrectUrl() client.GetAllForRepository("fake", "repo"); gitHubClient.Connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), - Arg.Any>(), null); + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -131,7 +132,8 @@ public void RequestsCorrectUrlWithApiOptions() && d["sort"] == "created" && d["direction"] == "desc" && d["page"] == "1" - && d["per_page"] == "1"), null); + && d["per_page"] == "1"), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -175,7 +177,8 @@ public void SendsAppropriateParameters() && d["filter"] == "assigned" && d["state"] == "open" && d["sort"] == "created" - && d["direction"] == "asc"), null); + && d["direction"] == "asc"), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -223,7 +226,7 @@ public void SendsAppropriateParametersWithApiOptions() && d["direction"] == "asc" && d["page"] == "1" && d["per_page"] == "1"), - null); + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -299,9 +302,9 @@ public async Task ReturnsEveryPageOfIssues() && d["sort"] == "created" && d["filter"] == "assigned"), Arg.Any()) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); @@ -374,11 +377,11 @@ public async Task ReturnsEveryPageOfIssues() && d["state"] == "open" && d["sort"] == "created" && d["filter"] == "assigned"), - Arg.Any()) + "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); @@ -460,13 +463,13 @@ public async Task ReturnsEveryPageOfIssues() && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "created" - && d["filter"] == "assigned"), Arg.Any()) + && d["filter"] == "assigned"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); - + var client = new ObservableIssuesClient(gitHubClient); var results = await client.GetAllForOrganization("test").ToArray(); @@ -533,11 +536,11 @@ public async Task ReturnsEveryPageOfIssues() && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "created" - && d["filter"] == "assigned"), Arg.Any()) + && d["filter"] == "assigned"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs index 428cd7329c..7e637dbdec 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs @@ -125,11 +125,12 @@ public async Task RequestsCorrectUrlMulti() ); var gitHubClient = Substitute.For(); - gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) + var acceptHeader = "application/vnd.github.squirrel-girl-preview"; + gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, acceptHeader) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, null) + gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, acceptHeader) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, null) + gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, acceptHeader) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -137,9 +138,9 @@ public async Task RequestsCorrectUrlMulti() var results = await client.GetAll("owner", "name", 7).ToArray(); Assert.Equal(7, results.Length); - gitHubClient.Connection.Received(1).Get>(firstPageUrl, Args.EmptyDictionary, null); - gitHubClient.Connection.Received(1).Get>(secondPageUrl, Args.EmptyDictionary, null); - gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Args.EmptyDictionary, null); + gitHubClient.Connection.Received(1).Get>(firstPageUrl, Args.EmptyDictionary, acceptHeader); + gitHubClient.Connection.Received(1).Get>(secondPageUrl, Args.EmptyDictionary, acceptHeader); + gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Args.EmptyDictionary, acceptHeader); } [Fact] @@ -178,6 +179,8 @@ public async Task RequestsCorrectUrlMultiWithRepositoryId() } ); + var acceptHeader = "application/vnd.github.squirrel-girl-preview"; + var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); @@ -343,22 +346,23 @@ public async Task RequestsCorrectUrlMulti() ); var gitHubClient = Substitute.For(); + var previewAcceptHeader = "application/vnd.github.squirrel-girl-preview"; gitHubClient.Connection.Get>(firstPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null) + && d["sort"] == "updated"), previewAcceptHeader) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null) + && d["sort"] == "updated"), previewAcceptHeader) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null) + && d["sort"] == "updated"), previewAcceptHeader) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -377,15 +381,15 @@ public async Task RequestsCorrectUrlMulti() Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null); + && d["sort"] == "updated"), previewAcceptHeader); gitHubClient.Connection.Received(1).Get>(secondPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null); + && d["sort"] == "updated"), previewAcceptHeader); gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null); + && d["sort"] == "updated"), previewAcceptHeader); } [Fact] @@ -431,17 +435,17 @@ public async Task RequestsCorrectUrlMultiWithRepositoryId() Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null) + && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null) + && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null) + && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -460,15 +464,15 @@ public async Task RequestsCorrectUrlMultiWithRepositoryId() Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null); + && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview"); gitHubClient.Connection.Received(1).Get>(secondPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null); + && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview"); gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), null); + && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -568,18 +572,20 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMulti() var gitHubClient = Substitute.For(); + var previewAcceptHeader = "application/vnd.github.squirrel-girl-preview"; + gitHubClient.Connection.Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null) + && d["sort"] == "created"), previewAcceptHeader) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null) + && d["sort"] == "created"), previewAcceptHeader) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null) + && d["sort"] == "created"), previewAcceptHeader) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -590,13 +596,13 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMulti() gitHubClient.Connection.Received(1).Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null); + && d["sort"] == "created"), previewAcceptHeader); gitHubClient.Connection.Received(1).Get>(secondPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null); + && d["sort"] == "created"), previewAcceptHeader); gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null); + && d["sort"] == "created"), previewAcceptHeader); } [Fact] @@ -641,15 +647,15 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMultiWithRepo gitHubClient.Connection.Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null) + && d["sort"] == "created"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null) + && d["sort"] == "created"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); gitHubClient.Connection.Get>(thirdPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null) + && d["sort"] == "created"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -660,13 +666,15 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMultiWithRepo gitHubClient.Connection.Received(1).Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null); + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview"); gitHubClient.Connection.Received(1).Get>(secondPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null); + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview"); gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null); + && d["sort"] == "created"), "application/vnd.github.squirrel-girl-preview"); } [Fact] diff --git a/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs index 02d87fdfb5..4af7888f52 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs @@ -64,7 +64,7 @@ public void RequestsCorrectUrl() client.GetAllForRepository("fake", "repo"); githubClient.Connection.Received(1).Get>(Arg.Is(uri => uri.ToString() == "repos/fake/repo/comments"), - Args.EmptyDictionary, null); + Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -75,7 +75,7 @@ public void RequestsCorrectUrlWithRepositoryId() client.GetAllForRepository(1); githubClient.Connection.Received(1).Get>(Arg.Is(uri => uri.ToString() == "repositories/1/comments"), - Args.EmptyDictionary, null); + Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -93,7 +93,7 @@ public void RequestsCorrectUrlWithApiOptions() client.GetAllForRepository("fake", "repo", options); githubClient.Connection.Received(1).Get>(Arg.Is(uri => uri.ToString() == "repos/fake/repo/comments"), - Arg.Is>(dictionary => dictionary.Count == 2), null); + Arg.Is>(dictionary => dictionary.Count == 2), "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -111,7 +111,7 @@ public void RequestsCorrectUrlWithRepositoryIdWithApiOptions() client.GetAllForRepository(1, options); githubClient.Connection.Received(1).Get>(Arg.Is(uri => uri.ToString() == "repositories/1/comments"), - Arg.Is>(dictionary => dictionary.Count == 2), null); + Arg.Is>(dictionary => dictionary.Count == 2), "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -145,7 +145,7 @@ public void RequestsCorrectUrl() client.GetAllForCommit("fake", "repo", "sha"); githubClient.Connection.Received().Get>(Arg.Is(new Uri("repos/fake/repo/commits/sha/comments", UriKind.Relative)), - Args.EmptyDictionary, null); + Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -156,7 +156,7 @@ public void RequestsCorrectUrlWithRepositoryId() client.GetAllForCommit(1, "sha"); githubClient.Connection.Received().Get>(Arg.Is(new Uri("repositories/1/commits/sha/comments", UriKind.Relative)), - Args.EmptyDictionary, null); + Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -174,7 +174,7 @@ public void RequestsCorrectUrlWithApiOptions() client.GetAllForCommit("fake", "repo", "sha", options); githubClient.Connection.Received().Get>(Arg.Is(new Uri("repos/fake/repo/commits/sha/comments", UriKind.Relative)), - Arg.Is>(d => d.Count == 2), null); + Arg.Is>(d => d.Count == 2), "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -192,7 +192,7 @@ public void RequestsCorrectUrlWithRepositoryIdWithApiOptions() client.GetAllForCommit(1, "sha", options); githubClient.Connection.Received().Get>(Arg.Is(new Uri("repositories/1/commits/sha/comments", UriKind.Relative)), - Arg.Is>(d => d.Count == 2), null); + Arg.Is>(d => d.Count == 2), "application/vnd.github.squirrel-girl-preview"); } [Fact] diff --git a/Octokit/Clients/IssueCommentsClient.cs b/Octokit/Clients/IssueCommentsClient.cs index 87e9dd7cb9..f7f2faf1fe 100644 --- a/Octokit/Clients/IssueCommentsClient.cs +++ b/Octokit/Clients/IssueCommentsClient.cs @@ -42,7 +42,7 @@ public Task Get(string owner, string name, int id) /// The issue comment id public Task Get(int repositoryId, int id) { - return ApiConnection.Get(ApiUrls.IssueComment(repositoryId, id)); + return ApiConnection.Get(ApiUrls.IssueComment(repositoryId, id), null, AcceptHeaders.ReactionsPreview); } /// @@ -95,7 +95,7 @@ public Task> GetAllForRepository(int repositoryId, A { Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.IssueComments(repositoryId), options); + return ApiConnection.GetAll(ApiUrls.IssueComments(repositoryId), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -152,7 +152,7 @@ public Task> GetAllForIssue(int repositoryId, int nu { Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.IssueComments(repositoryId, number), options); + return ApiConnection.GetAll(ApiUrls.IssueComments(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); } /// diff --git a/Octokit/Clients/IssuesClient.cs b/Octokit/Clients/IssuesClient.cs index cddf5c1b6e..f085acb14a 100644 --- a/Octokit/Clients/IssuesClient.cs +++ b/Octokit/Clients/IssuesClient.cs @@ -65,7 +65,7 @@ public Task Get(string owner, string name, int number) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.Get(ApiUrls.Issue(owner, name, number)); + return ApiConnection.Get(ApiUrls.Issue(owner, name, number), null, AcceptHeaders.ReactionsPreview); } /// @@ -78,7 +78,7 @@ public Task Get(string owner, string name, int number) /// The issue number public Task Get(int repositoryId, int number) { - return ApiConnection.Get(ApiUrls.Issue(repositoryId, number)); + return ApiConnection.Get(ApiUrls.Issue(repositoryId, number), null, AcceptHeaders.ReactionsPreview); } /// @@ -139,7 +139,7 @@ public Task> GetAllForCurrent(IssueRequest request, ApiOpti Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.Issues(), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.Issues(), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// @@ -198,7 +198,7 @@ public Task> GetAllForOwnedAndMemberRepositories(IssueReque Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.IssuesForOwnedAndMember(), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.IssuesForOwnedAndMember(), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// @@ -262,7 +262,7 @@ public Task> GetAllForOrganization(string organization, Iss Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.Issues(organization), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.Issues(organization), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// @@ -376,7 +376,7 @@ public Task> GetAllForRepository(string owner, string name, Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// @@ -393,7 +393,7 @@ public Task> GetAllForRepository(int repositoryId, Reposito Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.Issues(repositoryId), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.Issues(repositoryId), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs index 870744972e..6ff2667e3a 100644 --- a/Octokit/Clients/PullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -57,7 +57,7 @@ public Task> GetAll(string owner, string Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.PullRequestReviewComments(owner, name, number), options); + return ApiConnection.GetAll(ApiUrls.PullRequestReviewComments(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -171,7 +171,7 @@ public Task> GetAllForRepository(string Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentsRepository(owner, name), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentsRepository(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// @@ -186,7 +186,7 @@ public Task> GetAllForRepository(int rep Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentsRepository(repositoryId), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentsRepository(repositoryId), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// @@ -201,7 +201,7 @@ public Task GetComment(string owner, string name, int Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.Get(ApiUrls.PullRequestReviewComment(owner, name, number)); + return ApiConnection.Get(ApiUrls.PullRequestReviewComment(owner, name, number), new Dictionary(), AcceptHeaders.ReactionsPreview); } /// diff --git a/Octokit/Clients/RepositoryCommentsClient.cs b/Octokit/Clients/RepositoryCommentsClient.cs index a9fe278b47..5978fbb6f8 100644 --- a/Octokit/Clients/RepositoryCommentsClient.cs +++ b/Octokit/Clients/RepositoryCommentsClient.cs @@ -32,7 +32,7 @@ public Task Get(string owner, string name, int number) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.Get(ApiUrls.CommitComment(owner, name, number)); + return ApiConnection.Get(ApiUrls.CommitComment(owner, name, number), null, AcceptHeaders.ReactionsPreview); } /// @@ -43,7 +43,7 @@ public Task Get(string owner, string name, int number) /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment public Task Get(int repositoryId, int number) { - return ApiConnection.Get(ApiUrls.CommitComment(repositoryId, number)); + return ApiConnection.Get(ApiUrls.CommitComment(repositoryId, number), null, AcceptHeaders.ReactionsPreview); } /// @@ -83,7 +83,7 @@ public Task> GetAllForRepository(string owner, stri Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.CommitComments(owner, name), options); + return ApiConnection.GetAll(ApiUrls.CommitComments(owner, name), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -96,7 +96,7 @@ public Task> GetAllForRepository(int repositoryId, { Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.CommitComments(repositoryId), options); + return ApiConnection.GetAll(ApiUrls.CommitComments(repositoryId), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -143,7 +143,7 @@ public Task> GetAllForCommit(string owner, string n Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.CommitComments(owner, name, sha), options); + return ApiConnection.GetAll(ApiUrls.CommitComments(owner, name, sha), null, AcceptHeaders.ReactionsPreview, options); } /// @@ -158,7 +158,7 @@ public Task> GetAllForCommit(int repositoryId, stri Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.CommitComments(repositoryId, sha), options); + return ApiConnection.GetAll(ApiUrls.CommitComments(repositoryId, sha), null, AcceptHeaders.ReactionsPreview, options); } /// diff --git a/Octokit/Models/Response/CommitComment.cs b/Octokit/Models/Response/CommitComment.cs index 2d7f0824a9..5275a0d557 100644 --- a/Octokit/Models/Response/CommitComment.cs +++ b/Octokit/Models/Response/CommitComment.cs @@ -79,6 +79,8 @@ public CommitComment(int id, Uri url, Uri htmlUrl, string body, string path, int /// public DateTimeOffset? UpdatedAt { get; protected set; } + public ReactionSummary Reactions { get; protected set; } + internal string DebuggerDisplay { get diff --git a/Octokit/Models/Response/Issue.cs b/Octokit/Models/Response/Issue.cs index 5b87e577fe..e86fbe5c11 100644 --- a/Octokit/Models/Response/Issue.cs +++ b/Octokit/Models/Response/Issue.cs @@ -137,6 +137,8 @@ public Issue(Uri url, Uri htmlUrl, Uri commentsUrl, Uri eventsUrl, int number, I /// public Repository Repository { get; protected set; } + public ReactionSummary Reactions { get; protected set; } + internal string DebuggerDisplay { get diff --git a/Octokit/Models/Response/PullRequestReviewComment.cs b/Octokit/Models/Response/PullRequestReviewComment.cs index d90bef72de..32b952d8e7 100644 --- a/Octokit/Models/Response/PullRequestReviewComment.cs +++ b/Octokit/Models/Response/PullRequestReviewComment.cs @@ -102,6 +102,8 @@ public PullRequestReviewComment(Uri url, int id, string diffHunk, string path, i /// public Uri PullRequestUrl { get; protected set; } + public ReactionSummary Reactions { get; protected set; } + internal string DebuggerDisplay { get { return string.Format(CultureInfo.InvariantCulture, "Id: {0}, Path: {1}, User: {2}, Url: {3}", Id, Path, User.DebuggerDisplay, Url); }