From b06097bd1c6fd75a6bb8fe7a4debdac04e86ecd6 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Tue, 21 Jun 2016 10:02:56 +0200 Subject: [PATCH 01/24] add reactions to issue response payload --- Octokit.Reactive/Clients/ObservableIssuesClient.cs | 8 ++++---- Octokit/Clients/IssuesClient.cs | 10 +++++----- Octokit/Models/Response/Issue.cs | 2 ++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservableIssuesClient.cs b/Octokit.Reactive/Clients/ObservableIssuesClient.cs index 343c057d67..cf66e7d36a 100644 --- a/Octokit.Reactive/Clients/ObservableIssuesClient.cs +++ b/Octokit.Reactive/Clients/ObservableIssuesClient.cs @@ -126,7 +126,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); } /// @@ -189,7 +189,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); } /// @@ -257,7 +257,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); } /// @@ -333,7 +333,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/Clients/IssuesClient.cs b/Octokit/Clients/IssuesClient.cs index 690e17ebde..e74ae4b7e6 100644 --- a/Octokit/Clients/IssuesClient.cs +++ b/Octokit/Clients/IssuesClient.cs @@ -62,7 +62,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); } /// @@ -127,7 +127,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); } /// @@ -190,7 +190,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); } /// @@ -258,7 +258,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); } /// @@ -327,7 +327,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); } /// 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 From 71e5eab4fdee30a6f8e591ed2eb44e8b4b5918ac Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Tue, 21 Jun 2016 10:08:53 +0200 Subject: [PATCH 02/24] add reactions to commit comment payload --- .../Clients/ObservableRepositoryCommentsClient.cs | 8 ++++---- Octokit/Clients/RepositoryCommentsClient.cs | 12 ++++++------ Octokit/Models/Response/CommitComment.cs | 2 ++ 3 files changed, 12 insertions(+), 10 deletions(-) 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/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 From 1f9aa88600f387f732eb78e04894254cab110fc5 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Tue, 21 Jun 2016 10:19:05 +0200 Subject: [PATCH 03/24] add reactions to review comment payload --- .../Clients/ObservablePullRequestReviewCommentsClient.cs | 4 ++-- Octokit/Clients/PullRequestReviewCommentsClient.cs | 6 +++--- Octokit/Models/Response/PullRequestReviewComment.cs | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs index 5ae71eda0f..bbb82b89b9 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs @@ -49,7 +49,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); } /// @@ -117,7 +117,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); } diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs index 439e70d809..ac22d7eda4 100644 --- a/Octokit/Clients/PullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -48,7 +48,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); } /// @@ -116,7 +116,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); } /// @@ -132,7 +132,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), null, AcceptHeaders.ReactionsPreview); } /// 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); } From 6a2ad51e8ef047239e6d8bc4ca9a93560f618867 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Tue, 21 Jun 2016 18:06:31 +0200 Subject: [PATCH 04/24] create tests for issue client --- .../Clients/IssuesClientTests.cs | 22 +++++++++++++++++++ Octokit.Tests/Clients/IssuesClientTests.cs | 14 ++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index 8d07644856..a31a7c1701 100644 --- a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs @@ -11,12 +11,14 @@ public class IssuesClientTests : IDisposable { private readonly RepositoryContext _context; private readonly IIssuesClient _issuesClient; + private readonly IReactionsClient _reactionsClient; public IssuesClientTests() { var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); _issuesClient = github.Issue; + _reactionsClient = github.Reaction; _context = github.CreateRepositoryContext(new NewRepository(repoName)).Result; } @@ -33,12 +35,20 @@ public async Task CanDeserializeIssue() Assert.Equal(title, issue.Title); Assert.Equal(description, issue.Body); + var reaction = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new NewReaction(ReactionType.Confused)); var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.True(retrieved.Id > 0); Assert.False(retrieved.Locked); Assert.Equal(title, retrieved.Title); Assert.Equal(description, retrieved.Body); + Assert.Equal(1, retrieved.Reactions.TotalCount); + Assert.Equal(0, retrieved.Reactions.Plus1); + Assert.Equal(0, retrieved.Reactions.Hooray); + Assert.Equal(0, retrieved.Reactions.Heart); + Assert.Equal(0, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(0, retrieved.Reactions.Minus1); } [IntegrationTest] @@ -219,6 +229,10 @@ public async Task CanRetrieveAllIssues() var issue2 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); var issue3 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue3); var issue4 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue4); + var reaction1 = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue1.Number, new NewReaction(ReactionType.Plus1)); + var reaction2 = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue2.Number, new NewReaction(ReactionType.Minus1)); + var reaction3 = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue3.Number, new NewReaction(ReactionType.Confused)); + var reaction4 = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue4.Number, new NewReaction(ReactionType.Laugh)); await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue4.Number, new IssueUpdate { State = ItemState.Closed }); var request = new RepositoryIssueRequest { State = ItemStateFilter.All }; @@ -230,6 +244,14 @@ public async Task CanRetrieveAllIssues() Assert.True(retrieved.Any(i => i.Number == issue2.Number)); Assert.True(retrieved.Any(i => i.Number == issue3.Number)); Assert.True(retrieved.Any(i => i.Number == issue4.Number)); + var issue = retrieved[0]; + Assert.Equal(4, issue.Reactions.TotalCount); + Assert.Equal(0, issue.Reactions.Plus1); + Assert.Equal(0, issue.Reactions.Hooray); + Assert.Equal(0, issue.Reactions.Heart); + Assert.Equal(0, issue.Reactions.Laugh); + Assert.Equal(1, issue.Reactions.Confused); + Assert.Equal(0, issue.Reactions.Minus1); } [IntegrationTest] diff --git a/Octokit.Tests/Clients/IssuesClientTests.cs b/Octokit.Tests/Clients/IssuesClientTests.cs index 131f6ac5c3..4b038cf8c1 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -20,7 +20,9 @@ public void RequestsCorrectUrl() 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>(), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); } [Fact] @@ -55,7 +57,9 @@ public void RequestsCorrectUrl() client.GetAllForCurrent(); connection.Received().GetAll(Arg.Is(u => u.ToString() == "issues"), - Arg.Any>(), Args.ApiOptions); + Arg.Any>(), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + Args.ApiOptions); } [Fact] @@ -72,6 +76,7 @@ public void SendsAppropriateParameters() && d["sort"] == "created" && d["state"] == "open" && d["direction"] == "asc"), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); } } @@ -99,6 +104,7 @@ public void RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/issues"), Arg.Any>(), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); } } @@ -140,6 +146,7 @@ public void RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/issues"), Arg.Any>(), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); } @@ -160,6 +167,7 @@ public void SendsAppropriateParameters() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); } } @@ -211,6 +219,7 @@ public void RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), Arg.Any>(), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); } @@ -231,6 +240,7 @@ public void SendsAppropriateParameters() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); } } From 0f8f345ef925bd40532f854918c15ac5a8698b2e Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 23 Jun 2016 09:07:37 +0200 Subject: [PATCH 05/24] tests for commitcomment client --- .../Clients/RepositoryCommentsClientTests.cs | 26 ++++++++++++++++- .../Clients/RepositoryCommentsClientTests.cs | 29 ++++++++++++------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs index 8421cfdaa6..f8c49bec36 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs @@ -310,12 +310,13 @@ public class TheCreateMethod : IDisposable { private readonly IGitHubClient _github; private readonly RepositoryContext _context; + private readonly IReactionsClient _reactionsClient; public TheCreateMethod() { _github = Helper.GetAuthenticatedClient(); - _context = _github.CreateRepositoryContext("public-repo").Result; + _reactionsClient = _github.Reaction; } private async Task SetupCommitForRepository(IGitHubClient client) @@ -377,6 +378,29 @@ 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); + + var reaction = await _reactionsClient.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, new NewReaction(ReactionType.Confused)); + var retrieved = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id); + + Assert.True(retrieved.Id > 0); + Assert.Equal(1, retrieved.Reactions.TotalCount); + Assert.Equal(0, retrieved.Reactions.Plus1); + Assert.Equal(0, retrieved.Reactions.Hooray); + Assert.Equal(0, retrieved.Reactions.Heart); + Assert.Equal(0, retrieved.Reactions.Laugh); + Assert.Equal(1, retrieved.Reactions.Confused); + Assert.Equal(0, retrieved.Reactions.Minus1); + } + public void Dispose() { _context.Dispose(); diff --git a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs index b54ef6a693..47a3295ab8 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>(), Arg.Is(s => s == "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>(), Arg.Is(s => s == "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>(), Arg.Is(s => s == "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>(), Arg.Is(s => s == "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>(), Arg.Is(s => s == "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>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); } [Fact] @@ -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>(), + Arg.Is(s => s == "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>(), + Arg.Is(s => s == "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>(), + Arg.Is(s => s == "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>(), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); } [Fact] From 3cd92ef2ec339657890cd812294bce60d845bf95 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 23 Jun 2016 09:25:44 +0200 Subject: [PATCH 06/24] tests for pull request review comment --- .../PullRequestReviewCommentsClientTests.cs | 31 ++++++++++++++++++- .../PullRequestReviewCommentsClientTests.cs | 23 +++++++++----- .../Clients/RepositoryCommentsClientTests.cs | 4 +-- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index f7e3f16dc6..8d849f0dfb 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -12,6 +12,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable private readonly IGitHubClient _github; private readonly IPullRequestReviewCommentsClient _client; private readonly RepositoryContext _context; + private readonly IReactionsClient _reactionsClient; const string branchName = "new-branch"; const string branchHead = "heads/" + branchName; @@ -24,6 +25,8 @@ public PullRequestReviewCommentsClientTests() _client = _github.PullRequest.Comment; + _reactionsClient = _github.Reaction; + // We'll create a pull request that can be used by most tests _context = _github.CreateRepositoryContext("test-repo").Result; } @@ -137,7 +140,7 @@ public async Task ReturnsCorrectCountOfPullRequestReviewCommentWithoutStart() var commentsToCreate = new List { "Comment 1", "Comment 2", "Comment 3" }; await CreateComments(commentsToCreate, position, _context.RepositoryName, pullRequest.Sha, pullRequest.Number); - + var options = new ApiOptions { PageSize = 3, @@ -216,6 +219,32 @@ public async Task CanGetForRepository() AssertComments(pullRequestComments, commentsToCreate, position); } + [IntegrationTest] + public async Task CanGetReactionPayload() + { + var pullRequest = await CreatePullRequest(_context); + + const int position = 1; + var commentsToCreate = new List { "Comment One", "Comment Two" }; + + await CreateComments(commentsToCreate, position, _context.RepositoryName, pullRequest.Sha, pullRequest.Number); + + var pullRequestComments = await _client.GetAllForRepository(Helper.UserName, _context.RepositoryName); + + AssertComments(pullRequestComments, commentsToCreate, position); + + var reaction = await _reactionsClient.PullRequestReviewComment.Create(Helper.UserName, _context.RepositoryName, pullRequestComments[0].Id, new NewReaction(ReactionType.Confused)); + var retrieved = await _github.PullRequest.Comment.GetAll(_context.RepositoryOwner, _context.RepositoryName, pullRequest.Number); + + Assert.Equal(1, retrieved[0].Reactions.TotalCount); + Assert.Equal(0, retrieved[0].Reactions.Plus1); + Assert.Equal(0, retrieved[0].Reactions.Hooray); + Assert.Equal(0, retrieved[0].Reactions.Heart); + Assert.Equal(0, retrieved[0].Reactions.Laugh); + Assert.Equal(1, retrieved[0].Reactions.Confused); + Assert.Equal(0, retrieved[0].Reactions.Minus1); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfPullRequestReviewCommentWithoutStartForRepository() { diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index ac37ac1faa..dcc1d8add0 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -98,7 +98,9 @@ public async Task RequestsCorrectUrl() await client.GetAll("fakeOwner", "fakeRepoName", 7); connection.Received().GetAll( - Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments"), Args.ApiOptions); + Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments"), + Arg.Any>(), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); } [Fact] @@ -117,7 +119,9 @@ public async Task RequestsCorrectUrlWithApiOptions() await client.GetAll("fakeOwner", "fakeRepoName", 7, options); connection.Received().GetAll( - Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments"), options); + Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments"), + Arg.Any>(), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); } [Fact] @@ -162,7 +166,8 @@ 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"), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); } [Fact] @@ -191,7 +196,8 @@ 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"), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); } [Fact] @@ -205,7 +211,8 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArguments() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments"), Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), Args.ApiOptions); + && d["sort"] == "created"), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); } [Fact] @@ -226,7 +233,8 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOption connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments"), Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), options); + && d["sort"] == "created"), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); } [Fact] @@ -272,7 +280,8 @@ public void RequestsCorrectUrl() client.GetComment("fakeOwner", "fakeRepoName", 53); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/53")); + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/53"), Arg.Any>(), + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); } [Fact] diff --git a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs index 47a3295ab8..28d3a1f473 100644 --- a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs @@ -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)); @@ -214,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", "")); From 93b4d98469898b306e836215b1077340fa89af56 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 23 Jun 2016 13:08:16 +0200 Subject: [PATCH 07/24] change observable tests --- .../Reactive/ObservableIssuesClientTests.cs | 22 ++++++------ ...blePullRequestReviewCommentsClientTests.cs | 36 +++++++++---------- ...ObservableRepositoryCommentsClientTests.cs | 16 ++++----- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs index 0360cac12d..d3fdbe2f3c 100644 --- a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs @@ -117,9 +117,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>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); @@ -192,11 +192,11 @@ public async Task ReturnsEveryPageOfIssues() && d["state"] == "open" && d["sort"] == "created" && d["filter"] == "assigned"), - Arg.Any()) + Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); @@ -278,11 +278,11 @@ public async Task ReturnsEveryPageOfIssues() && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "created" - && d["filter"] == "assigned"), Arg.Any()) + && d["filter"] == "assigned"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); @@ -351,11 +351,11 @@ public async Task ReturnsEveryPageOfIssues() && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "created" - && d["filter"] == "assigned"), Arg.Any()) + && d["filter"] == "assigned"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), null) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), Arg.Is(s => s == "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 4bc6a063c3..353e513783 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs @@ -97,11 +97,11 @@ public async Task RequestsCorrectUrlMulti() ); var gitHubClient = Substitute.For(); - gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) + gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, null) + gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, null) + gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -109,9 +109,9 @@ public async Task RequestsCorrectUrlMulti() var results = await client.GetAll("fakeOwner", "fakeRepoName", 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, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + gitHubClient.Connection.Received(1).Get>(secondPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); } [Fact] @@ -223,17 +223,17 @@ 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"), Arg.Is(s => s == "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"), Arg.Is(s => s == "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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -252,15 +252,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"), Arg.Is(s => s == "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"), Arg.Is(s => s == "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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); } [Fact] @@ -334,15 +334,15 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMulti() gitHubClient.Connection.Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), null) + && d["sort"] == "created"), Arg.Is(s => s == "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"), Arg.Is(s => s == "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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -353,13 +353,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"), Arg.Is(s => s == "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"), Arg.Is(s => s == "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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); } [Fact] diff --git a/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs index 02d87fdfb5..84dd42048b 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, Arg.Is(s => s == "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, Arg.Is(s => s == "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), Arg.Is(s => s == "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), Arg.Is(s => s == "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, Arg.Is(s => s == "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, Arg.Is(s => s == "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), Arg.Is(s => s == "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), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); } [Fact] From 30cbd8e3e424ad3a94f27a0ca7cc11da5ba4a4da Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 23 Jun 2016 13:39:17 +0200 Subject: [PATCH 08/24] simplify strings --- Octokit.Tests/Clients/IssuesClientTests.cs | 16 ++++----- .../PullRequestReviewCommentsClientTests.cs | 14 ++++---- .../Clients/RepositoryCommentsClientTests.cs | 20 +++++------ .../Reactive/ObservableIssuesClientTests.cs | 24 ++++++------- ...blePullRequestReviewCommentsClientTests.cs | 36 +++++++++---------- ...ObservableRepositoryCommentsClientTests.cs | 16 ++++----- 6 files changed, 63 insertions(+), 63 deletions(-) diff --git a/Octokit.Tests/Clients/IssuesClientTests.cs b/Octokit.Tests/Clients/IssuesClientTests.cs index 4b038cf8c1..fad2bb5aee 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -22,7 +22,7 @@ public void RequestsCorrectUrl() connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -58,7 +58,7 @@ public void RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "issues"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -76,7 +76,7 @@ public void SendsAppropriateParameters() && d["sort"] == "created" && d["state"] == "open" && d["direction"] == "asc"), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } } @@ -104,7 +104,7 @@ public void RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/issues"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } } @@ -146,7 +146,7 @@ public void RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/issues"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -167,7 +167,7 @@ public void SendsAppropriateParameters() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } } @@ -219,7 +219,7 @@ public void RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -240,7 +240,7 @@ public void SendsAppropriateParameters() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } } diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index dcc1d8add0..32f9f7f838 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -100,7 +100,7 @@ public async Task RequestsCorrectUrl() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } [Fact] @@ -121,7 +121,7 @@ public async Task RequestsCorrectUrlWithApiOptions() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); + "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -167,7 +167,7 @@ public async Task RequestsCorrectUrl() && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } [Fact] @@ -197,7 +197,7 @@ public async Task RequestsCorrectUrlWithApiOptions() && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); + "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -212,7 +212,7 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArguments() Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), Args.ApiOptions); + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } [Fact] @@ -234,7 +234,7 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOption Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); + "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -281,7 +281,7 @@ public void RequestsCorrectUrl() client.GetComment("fakeOwner", "fakeRepoName", 53); connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/53"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + "application/vnd.github.squirrel-girl-preview"); } [Fact] diff --git a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs index 28d3a1f473..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"), Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + 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"), Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + 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"), Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), 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"), Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), 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"), Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), 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"), Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -141,7 +141,7 @@ public async Task RequestsCorrectUrl() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/comments"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -155,7 +155,7 @@ public async Task RequestsCorrectUrlWithRepositoryId() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/commits/sha/comments"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -175,7 +175,7 @@ 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"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); + "application/vnd.github.squirrel-girl-preview", options); } [Fact] @@ -195,7 +195,7 @@ public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/commits/sha/comments"), Arg.Any>(), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview"), options); + "application/vnd.github.squirrel-girl-preview", options); } [Fact] diff --git a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs index d3fdbe2f3c..87c7efed39 100644 --- a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs @@ -117,9 +117,9 @@ public async Task ReturnsEveryPageOfIssues() && d["sort"] == "created" && d["filter"] == "assigned"), Arg.Any()) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); @@ -192,11 +192,11 @@ public async Task ReturnsEveryPageOfIssues() && d["state"] == "open" && d["sort"] == "created" && d["filter"] == "assigned"), - Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); @@ -278,13 +278,13 @@ public async Task ReturnsEveryPageOfIssues() && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "created" - && d["filter"] == "assigned"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + && d["filter"] == "assigned"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + 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(); @@ -351,11 +351,11 @@ public async Task ReturnsEveryPageOfIssues() && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "created" - && d["filter"] == "assigned"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + && d["filter"] == "assigned"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + gitHubClient.Connection.Get>(secondPageUrl, Arg.Any>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Arg.Any>(), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + 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 353e513783..1e141ff9ec 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs @@ -97,11 +97,11 @@ public async Task RequestsCorrectUrlMulti() ); var gitHubClient = Substitute.For(); - gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -109,9 +109,9 @@ public async Task RequestsCorrectUrlMulti() var results = await client.GetAll("fakeOwner", "fakeRepoName", 7).ToArray(); Assert.Equal(7, results.Length); - gitHubClient.Connection.Received(1).Get>(firstPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); - gitHubClient.Connection.Received(1).Get>(secondPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); - gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Args.EmptyDictionary, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + gitHubClient.Connection.Received(1).Get>(firstPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); + gitHubClient.Connection.Received(1).Get>(secondPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); + gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -223,17 +223,17 @@ public async Task RequestsCorrectUrlMulti() Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + && 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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + && 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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -252,15 +252,15 @@ public async Task RequestsCorrectUrlMulti() Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + && 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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + && 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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + && d["sort"] == "updated"), "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -334,15 +334,15 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMulti() gitHubClient.Connection.Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + && 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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + && 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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")) + && d["sort"] == "created"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -353,13 +353,13 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMulti() gitHubClient.Connection.Received(1).Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + && 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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + && 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"), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + && 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 84dd42048b..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, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + 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, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + 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), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + 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), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + 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, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + 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, Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + 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), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + 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), Arg.Is(s => s == "application/vnd.github.squirrel-girl-preview")); + Arg.Is>(d => d.Count == 2), "application/vnd.github.squirrel-girl-preview"); } [Fact] From 3c883112006d02f22e11f468fca150878ac10945 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 23 Jun 2016 13:56:26 +0200 Subject: [PATCH 09/24] remove unnecessary clients --- .../Clients/PullRequestReviewCommentsClientTests.cs | 5 +---- .../Clients/RepositoryCommentsClientTests.cs | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index 8d849f0dfb..cf0c9240a0 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -12,7 +12,6 @@ public class PullRequestReviewCommentsClientTests : IDisposable private readonly IGitHubClient _github; private readonly IPullRequestReviewCommentsClient _client; private readonly RepositoryContext _context; - private readonly IReactionsClient _reactionsClient; const string branchName = "new-branch"; const string branchHead = "heads/" + branchName; @@ -25,8 +24,6 @@ public PullRequestReviewCommentsClientTests() _client = _github.PullRequest.Comment; - _reactionsClient = _github.Reaction; - // We'll create a pull request that can be used by most tests _context = _github.CreateRepositoryContext("test-repo").Result; } @@ -233,7 +230,7 @@ public async Task CanGetReactionPayload() AssertComments(pullRequestComments, commentsToCreate, position); - var reaction = await _reactionsClient.PullRequestReviewComment.Create(Helper.UserName, _context.RepositoryName, pullRequestComments[0].Id, new NewReaction(ReactionType.Confused)); + var reaction = await _github.Reaction.PullRequestReviewComment.Create(Helper.UserName, _context.RepositoryName, pullRequestComments[0].Id, new NewReaction(ReactionType.Confused)); var retrieved = await _github.PullRequest.Comment.GetAll(_context.RepositoryOwner, _context.RepositoryName, pullRequest.Number); Assert.Equal(1, retrieved[0].Reactions.TotalCount); diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs index f8c49bec36..6f1a363697 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs @@ -310,13 +310,11 @@ public class TheCreateMethod : IDisposable { private readonly IGitHubClient _github; private readonly RepositoryContext _context; - private readonly IReactionsClient _reactionsClient; public TheCreateMethod() { _github = Helper.GetAuthenticatedClient(); _context = _github.CreateRepositoryContext("public-repo").Result; - _reactionsClient = _github.Reaction; } private async Task SetupCommitForRepository(IGitHubClient client) @@ -388,7 +386,7 @@ public async Task CanGetReactionPayload() var result = await _github.Repository.Comment.Create(_context.Repository.Id, commit.Sha, comment); - var reaction = await _reactionsClient.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, new NewReaction(ReactionType.Confused)); + var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, new NewReaction(ReactionType.Confused)); var retrieved = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id); Assert.True(retrieved.Id > 0); From 05b451b5d514f3b5e1d417ca5c19873e5921f7d1 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 24 Jun 2016 08:51:27 +0200 Subject: [PATCH 10/24] change integration tests to retrieve all reaction types --- .../Clients/IssuesClientTests.cs | 24 +++++++++++++------ .../PullRequestReviewCommentsClientTests.cs | 23 ++++++++++++------ .../Clients/RepositoryCommentsClientTests.cs | 23 ++++++++++++------ 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index a31a7c1701..7991db8e44 100644 --- a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs @@ -35,20 +35,30 @@ public async Task CanDeserializeIssue() Assert.Equal(title, issue.Title); Assert.Equal(description, issue.Body); - var reaction = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new NewReaction(ReactionType.Confused)); + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Id, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(issue.User.Id, reaction.User.Id); + } + var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.True(retrieved.Id > 0); Assert.False(retrieved.Locked); Assert.Equal(title, retrieved.Title); Assert.Equal(description, retrieved.Body); - Assert.Equal(1, retrieved.Reactions.TotalCount); - Assert.Equal(0, retrieved.Reactions.Plus1); - Assert.Equal(0, retrieved.Reactions.Hooray); - Assert.Equal(0, retrieved.Reactions.Heart); - Assert.Equal(0, retrieved.Reactions.Laugh); + 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(0, retrieved.Reactions.Minus1); + Assert.Equal(1, retrieved.Reactions.Minus1); } [IntegrationTest] diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index cf0c9240a0..1aabbeec67 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -230,16 +230,25 @@ public async Task CanGetReactionPayload() AssertComments(pullRequestComments, commentsToCreate, position); - var reaction = await _github.Reaction.PullRequestReviewComment.Create(Helper.UserName, _context.RepositoryName, pullRequestComments[0].Id, new NewReaction(ReactionType.Confused)); + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, pullRequestComments[0].Id, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(pullRequestComments[0].User.Id, reaction.User.Id); + } var retrieved = await _github.PullRequest.Comment.GetAll(_context.RepositoryOwner, _context.RepositoryName, pullRequest.Number); - Assert.Equal(1, retrieved[0].Reactions.TotalCount); - Assert.Equal(0, retrieved[0].Reactions.Plus1); - Assert.Equal(0, retrieved[0].Reactions.Hooray); - Assert.Equal(0, retrieved[0].Reactions.Heart); - Assert.Equal(0, retrieved[0].Reactions.Laugh); + Assert.Equal(6, retrieved[0].Reactions.TotalCount); + Assert.Equal(1, retrieved[0].Reactions.Plus1); + Assert.Equal(1, retrieved[0].Reactions.Hooray); + Assert.Equal(1, retrieved[0].Reactions.Heart); + Assert.Equal(1, retrieved[0].Reactions.Laugh); Assert.Equal(1, retrieved[0].Reactions.Confused); - Assert.Equal(0, retrieved[0].Reactions.Minus1); + Assert.Equal(1, retrieved[0].Reactions.Minus1); } [IntegrationTest] diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs index 6f1a363697..140651913f 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs @@ -386,17 +386,26 @@ public async Task CanGetReactionPayload() var result = await _github.Repository.Comment.Create(_context.Repository.Id, commit.Sha, comment); - var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, new NewReaction(ReactionType.Confused)); + 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(1, retrieved.Reactions.TotalCount); - Assert.Equal(0, retrieved.Reactions.Plus1); - Assert.Equal(0, retrieved.Reactions.Hooray); - Assert.Equal(0, retrieved.Reactions.Heart); - Assert.Equal(0, retrieved.Reactions.Laugh); + 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(0, retrieved.Reactions.Minus1); + Assert.Equal(1, retrieved.Reactions.Minus1); } public void Dispose() From 6552b2e8220708f728dbbb504d94b7e3f9299714 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Mon, 4 Jul 2016 14:28:58 +0200 Subject: [PATCH 11/24] create integration test for issue comment client --- .../Clients/IssueCommentsClientTests.cs | 85 +++++++++++-------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs index ceb375a04b..f582ff100b 100644 --- a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs @@ -6,48 +6,59 @@ using Octokit; using Octokit.Tests.Integration; using Xunit; +using Octokit.Tests.Integration.Helpers; public class IssueCommentsClientTests { - private readonly IIssueCommentsClient _issueCommentsClient; - - public IssueCommentsClientTests() + public class TheCreateMethod : IDisposable { - var github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; - } + private readonly IGitHubClient _github; + private readonly RepositoryContext _context; - [IntegrationTest] - public async Task CanDeserializeIssueCommentWhenGettingAllForRepository() - { - var comments = await _issueCommentsClient.GetAllForRepository("alfhenrik-test", "repo-with-issue-comment-reactions"); - - Assert.NotEmpty(comments); - var comment = comments[0]; - Assert.NotNull(comment.Reactions); - Assert.Equal(3, comment.Reactions.TotalCount); - Assert.Equal(1, comment.Reactions.Plus1); - Assert.Equal(1, comment.Reactions.Hooray); - Assert.Equal(1, comment.Reactions.Heart); - Assert.Equal(0, comment.Reactions.Laugh); - Assert.Equal(0, comment.Reactions.Confused); - Assert.Equal(0, comment.Reactions.Minus1); - } + public TheCreateMethod() + { + _github = Helper.GetAuthenticatedClient(); + _context = _github.CreateRepositoryContext("public-repo").Result; + } - [IntegrationTest] - public async Task CanDeserializeIssueComment() - { - var comments = await _issueCommentsClient.GetAllForIssue("alfhenrik-test", "repo-with-issue-comment-reactions", 1); - - Assert.NotEmpty(comments); - var comment = comments[0]; - Assert.NotNull(comment.Reactions); - Assert.Equal(3, comment.Reactions.TotalCount); - Assert.Equal(1, comment.Reactions.Plus1); - Assert.Equal(1, comment.Reactions.Hooray); - Assert.Equal(1, comment.Reactions.Heart); - Assert.Equal(0, comment.Reactions.Laugh); - Assert.Equal(0, comment.Reactions.Confused); - Assert.Equal(0, comment.Reactions.Minus1); + [IntegrationTest] + public async Task CanGetReactionPayload() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _github.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueComment = await _github.Issue.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); + + Assert.NotNull(issueComment); + + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(issueComment.User.Id, reaction.User.Id); + } + + var retrieved = await _github.Issue.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, issueComment.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(); + } } } From e1c97fe2df99bbf56db340d70df5936793eab9cd Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Wed, 6 Jul 2016 15:43:53 +0200 Subject: [PATCH 12/24] fix merge conflicts --- .../PullRequestReviewCommentsClientTests.cs | 22 ++++++++++++------- .../PullRequestReviewCommentsClientTests.cs | 16 ++------------ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index d96fb4feaf..375afea583 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -396,11 +396,7 @@ public async Task CanGetForRepository() } [IntegrationTest] -<<<<<<< HEAD public async Task CanGetReactionPayload() -======= - public async Task CanGetForRepositoryWithRepositoryId() ->>>>>>> refs/remotes/octokit/master { var pullRequest = await CreatePullRequest(_context); @@ -409,7 +405,6 @@ public async Task CanGetForRepositoryWithRepositoryId() await CreateComments(commentsToCreate, position, _context.RepositoryName, pullRequest.Sha, pullRequest.Number); -<<<<<<< HEAD var pullRequestComments = await _client.GetAllForRepository(Helper.UserName, _context.RepositoryName); AssertComments(pullRequestComments, commentsToCreate, position); @@ -418,7 +413,7 @@ public async Task CanGetForRepositoryWithRepositoryId() { var newReaction = new NewReaction(reactionType); - var reaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, pullRequestComments[0].Id, newReaction); + var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, pullRequestComments[0].Id, newReaction); Assert.IsType(reaction); Assert.Equal(reactionType, reaction.Content); @@ -433,11 +428,22 @@ public async Task CanGetForRepositoryWithRepositoryId() Assert.Equal(1, retrieved[0].Reactions.Laugh); Assert.Equal(1, retrieved[0].Reactions.Confused); Assert.Equal(1, retrieved[0].Reactions.Minus1); -======= + } + + [IntegrationTest] + public async Task CanGetForRepositoryWithRepositoryId() + { + var pullRequest = await CreatePullRequest(_context); + + const int position = 1; + var commentsToCreate = new List { "Comment One", "Comment Two" }; + + await CreateComments(commentsToCreate, position, _context.RepositoryName, pullRequest.Sha, pullRequest.Number); + var pullRequestComments = await _client.GetAllForRepository(_context.Repository.Id); AssertComments(pullRequestComments, commentsToCreate, position); ->>>>>>> refs/remotes/octokit/master + } [IntegrationTest] diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index 04bcdbe45b..adfd3c3965 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -98,12 +98,9 @@ public async Task RequestsCorrectUrl() await client.GetAll("owner", "name", 7); connection.Received().GetAll( -<<<<<<< HEAD - Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments"), + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); -======= - Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), Args.ApiOptions); } [Fact] @@ -116,7 +113,6 @@ public async Task RequestsCorrectUrlWithRepositoryId() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repositories/1/pulls/7/comments"), Args.ApiOptions); ->>>>>>> refs/remotes/octokit/master } [Fact] @@ -135,12 +131,9 @@ public async Task RequestsCorrectUrlWithApiOptions() await client.GetAll("owner", "name", 7, options); connection.Received().GetAll( -<<<<<<< HEAD - Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments"), + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview", options); -======= - Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), options); } [Fact] @@ -160,7 +153,6 @@ public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repositories/1/pulls/7/comments"), options); ->>>>>>> refs/remotes/octokit/master } [Fact] @@ -418,11 +410,8 @@ public void RequestsCorrectUrl() client.GetComment("owner", "name", 53); -<<<<<<< HEAD connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/53"), Arg.Any>(), "application/vnd.github.squirrel-girl-preview"); -======= - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/53")); } [Fact] @@ -434,7 +423,6 @@ public void RequestsCorrectUrlWithRepositoryId() client.GetComment(1, 53); connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/53")); ->>>>>>> refs/remotes/octokit/master } [Fact] From 730dcd94bea21e5085e52eadc0dd6f67eec0e158 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 7 Jul 2016 08:41:25 +0200 Subject: [PATCH 13/24] fix merge conflicts --- .../Clients/IssueCommentsClientTests.cs | 90 ++++++++----------- 1 file changed, 38 insertions(+), 52 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs index aabf18c640..a897767ae9 100644 --- a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs @@ -4,60 +4,10 @@ using Octokit.Tests.Integration.Helpers; using Xunit; using Octokit.Tests.Integration.Helpers; +using System; public class IssueCommentsClientTests { -<<<<<<< HEAD - public class TheCreateMethod : IDisposable - { - private readonly IGitHubClient _github; - private readonly RepositoryContext _context; - - public TheCreateMethod() - { - _github = Helper.GetAuthenticatedClient(); - _context = _github.CreateRepositoryContext("public-repo").Result; - } - - [IntegrationTest] - public async Task CanGetReactionPayload() - { - var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; - var issue = await _github.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); - - Assert.NotNull(issue); - - var issueComment = await _github.Issue.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); - - Assert.NotNull(issueComment); - - foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) - { - var newReaction = new NewReaction(reactionType); - - var reaction = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction); - - Assert.IsType(reaction); - Assert.Equal(reactionType, reaction.Content); - Assert.Equal(issueComment.User.Id, reaction.User.Id); - } - - var retrieved = await _github.Issue.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, issueComment.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(); -======= public class TheGetMethod { readonly IIssueCommentsClient _issueCommentsClient; @@ -385,6 +335,7 @@ public class TheCreateMethod readonly IIssueCommentsClient _issueCommentsClient; readonly RepositoryContext _context; readonly IIssuesClient _issuesClient; + readonly IReactionsClient _reactionsClient; public TheCreateMethod() { @@ -396,6 +347,42 @@ public TheCreateMethod() _issuesClient = gitHubClient.Issue; _issueCommentsClient = gitHubClient.Issue.Comment; + _reactionsClient = gitHubClient.Reaction; + } + + [IntegrationTest] + public async Task CanGetReactionPayload() + { + 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 _issueCommentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); + + Assert.NotNull(issueComment); + + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await _reactionsClient.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(issueComment.User.Id, reaction.User.Id); + } + + var retrieved = await _issueCommentsClient.Get(_context.RepositoryOwner, _context.RepositoryName, issueComment.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); } [IntegrationTest] @@ -522,7 +509,6 @@ public async Task DeleteIssueWithRepositoryId() await _issueCommentsClient.Delete(_context.Repository.Id, comment.Id); await Assert.ThrowsAsync(() => _issueCommentsClient.Get(_context.Repository.Id, comment.Id)); ->>>>>>> refs/remotes/octokit/master } } } From e588c2903dd7a7b68bea643892865e631f014b24 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 7 Jul 2016 10:59:55 +1000 Subject: [PATCH 14/24] gets tests passing again --- ...servablePullRequestReviewCommentsClient.cs | 5 +- .../PullRequestReviewCommentsClientTests.cs | 20 +++++-- ...blePullRequestReviewCommentsClientTests.cs | 54 +++++++++++-------- .../PullRequestReviewCommentsClient.cs | 4 +- 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs index ca8ac4f991..5fa2f93fb5 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs @@ -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.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index adfd3c3965..2217f9b59a 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -199,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] @@ -251,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] @@ -295,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] @@ -331,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] @@ -410,7 +418,9 @@ public void RequestsCorrectUrl() client.GetComment("owner", "name", 53); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/53"), Arg.Any>(), + connection.Received().Get( + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/53"), + Arg.Any>(), "application/vnd.github.squirrel-girl-preview"); } diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs index 58025c5921..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, "application/vnd.github.squirrel-girl-preview") + 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, "application/vnd.github.squirrel-girl-preview") + gitHubClient.Connection.Get>(secondPageUrl, Args.EmptyDictionary, acceptHeader) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.Get>(thirdPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview") + 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)); @@ -191,9 +194,9 @@ public async Task RequestsCorrectUrlMultiWithRepositoryId() var results = await client.GetAll(1, 7).ToArray(); Assert.Equal(7, results.Length); - gitHubClient.Connection.Received(1).Get>(firstPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); - gitHubClient.Connection.Received(1).Get>(secondPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); - gitHubClient.Connection.Received(1).Get>(thirdPageUrl, Args.EmptyDictionary, "application/vnd.github.squirrel-girl-preview"); + 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); } [Fact] @@ -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] @@ -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] @@ -660,10 +666,12 @@ public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsMultiWithRepo gitHubClient.Connection.Received(1).Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" - && d["sort"] == "created"), "application/vnd.github.squirrel-girl-preview"); + && 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"), "application/vnd.github.squirrel-girl-preview"); + && 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"), "application/vnd.github.squirrel-girl-preview"); diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs index 1ebdebcc32..6ff2667e3a 100644 --- a/Octokit/Clients/PullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -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), null, AcceptHeaders.ReactionsPreview); + return ApiConnection.Get(ApiUrls.PullRequestReviewComment(owner, name, number), new Dictionary(), AcceptHeaders.ReactionsPreview); } /// From 43411b8e9f8350b72d75fff00a66f49e83766a4f Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 7 Jul 2016 09:47:37 +0200 Subject: [PATCH 15/24] fix some reaction integration tests --- .../Clients/IssueCommentReactionsClientTests.cs | 2 +- Octokit.Tests.Integration/Clients/IssuesClientTests.cs | 2 +- .../Clients/PullRequestReviewCommentReactionsClientTests.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index dfc0980197..7574cbb50b 100644 --- a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs @@ -39,7 +39,7 @@ public async Task CanDeserializeIssue() { var newReaction = new NewReaction(reactionType); - var reaction = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Id, newReaction); + var reaction = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReaction); Assert.IsType(reaction); Assert.Equal(reactionType, reaction.Content); 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); From 1185da2bdd670246e54759638d406fed9317d12a Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 7 Jul 2016 22:00:32 +1000 Subject: [PATCH 16/24] Fixup unit tests wth preview accepts header Also applied preview header to a couple of repositoryId based calls that were added by another PR --- .../Clients/IssueCommentsClientTests.cs | 36 +++++++++++++------ Octokit.Tests/Clients/IssuesClientTests.cs | 14 ++++++-- .../Reactive/ObservableIssuesClientTests.cs | 11 +++--- Octokit/Clients/IssueCommentsClient.cs | 6 ++-- Octokit/Clients/IssuesClient.cs | 4 +-- 5 files changed, 49 insertions(+), 22 deletions(-) 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 644685994e..981f69b6ef 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -33,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] @@ -234,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); } @@ -266,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] @@ -286,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); } @@ -327,6 +334,7 @@ public async Task SendsAppropriateParametersWithRepositoryId() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -354,6 +362,7 @@ public async Task SendsAppropriateParametersWithApiOptions() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + "application/vnd.github.squirrel-girl-preview", options); } @@ -381,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/Reactive/ObservableIssuesClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs index e272aa1081..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] 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 614ea3db83..f085acb14a 100644 --- a/Octokit/Clients/IssuesClient.cs +++ b/Octokit/Clients/IssuesClient.cs @@ -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); } /// @@ -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); } /// From 0a7bfc6c7f00285950e65740cc70ecaa87a66d92 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 7 Jul 2016 22:00:32 +1000 Subject: [PATCH 17/24] Fixup unit tests wth preview accepts header Also applied preview header to a couple of repositoryId based calls that were added by another PR --- .../Clients/IssueCommentsClientTests.cs | 36 +++++++++++++------ Octokit.Tests/Clients/IssuesClientTests.cs | 14 ++++++-- .../Reactive/ObservableIssuesClientTests.cs | 11 +++--- Octokit/Clients/IssueCommentsClient.cs | 6 ++-- Octokit/Clients/IssuesClient.cs | 4 +-- 5 files changed, 49 insertions(+), 22 deletions(-) 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 644685994e..981f69b6ef 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -33,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] @@ -234,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); } @@ -266,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] @@ -286,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); } @@ -327,6 +334,7 @@ public async Task SendsAppropriateParametersWithRepositoryId() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); } @@ -354,6 +362,7 @@ public async Task SendsAppropriateParametersWithApiOptions() && d["direction"] == "asc" && d["sort"] == "created" && d["filter"] == "assigned"), + "application/vnd.github.squirrel-girl-preview", options); } @@ -381,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/Reactive/ObservableIssuesClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs index e272aa1081..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] 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 614ea3db83..f085acb14a 100644 --- a/Octokit/Clients/IssuesClient.cs +++ b/Octokit/Clients/IssuesClient.cs @@ -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); } /// @@ -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); } /// From 65352554fffa17d509046b0354beda1886fa6547 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 7 Jul 2016 23:05:11 +1000 Subject: [PATCH 18/24] Rework reaction payload tests for IssueComments to handle Get, GetAllForIssue and GetAllForRepository calls --- .../Clients/IssueCommentsClientTests.cs | 191 ++++++++++++++---- 1 file changed, 148 insertions(+), 43 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs index a897767ae9..7710b3569d 100644 --- a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs @@ -3,15 +3,17 @@ using Octokit.Tests.Integration; using Octokit.Tests.Integration.Helpers; using Xunit; -using Octokit.Tests.Integration.Helpers; 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; @@ -19,9 +21,9 @@ public class TheGetMethod public TheGetMethod() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; + _issueCommentsClient = _github.Issue.Comment; } [IntegrationTest] @@ -39,10 +41,37 @@ public async Task ReturnsIssueCommentWithRepositoryId() Assert.NotNull(comment); } + + [IntegrationTest] + public async Task CanGetReactionPayload() + { + using (var context = await _github.CreateRepositoryContext(new NewRepository(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 issue + 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"; @@ -51,9 +80,9 @@ public class TheGetAllForRepositoryMethod public TheGetAllForRepositoryMethod() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; + _issueCommentsClient = _github.Issue.Comment; } [IntegrationTest] @@ -183,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(new NewRepository(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"; @@ -196,9 +265,9 @@ public class TheGetAllForIssueMethod public TheGetAllForIssueMethod() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; + _issueCommentsClient = _github.Issue.Comment; } [IntegrationTest] @@ -328,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(new NewRepository(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 @@ -350,41 +458,6 @@ public TheCreateMethod() _reactionsClient = gitHubClient.Reaction; } - [IntegrationTest] - public async Task CanGetReactionPayload() - { - 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 _issueCommentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); - - Assert.NotNull(issueComment); - - foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) - { - var newReaction = new NewReaction(reactionType); - - var reaction = await _reactionsClient.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction); - - Assert.IsType(reaction); - Assert.Equal(reactionType, reaction.Content); - Assert.Equal(issueComment.User.Id, reaction.User.Id); - } - - var retrieved = await _issueCommentsClient.Get(_context.RepositoryOwner, _context.RepositoryName, issueComment.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); - } - [IntegrationTest] public async Task ReturnsIssueComment() { @@ -511,4 +584,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; + } } From a6179b0f21a3ddfe36bfd3ae5eafae0e69b52252 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 7 Jul 2016 16:40:20 +0200 Subject: [PATCH 19/24] [WIP] reaction payload tests --- .../Clients/RepositoryCommentsClientTests.cs | 212 ++++++++---------- 1 file changed, 97 insertions(+), 115 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs index 140651913f..90262f341e 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs @@ -4,6 +4,8 @@ using Octokit.Tests.Integration; using Octokit.Tests.Integration.Helpers; using Xunit; +using System.Collections.Generic; +using System.Linq; public class RepositoryCommentsClientTests { @@ -38,6 +40,7 @@ public async Task CanGetCommentWithRepositoryId() public class TheGetAllForRepositoryMethod { + readonly IGitHubClient _client; readonly IRepositoryCommentsClient _fixture; const string owner = "octocat"; const string name = "Hello-World"; @@ -45,9 +48,9 @@ public class TheGetAllForRepositoryMethod public TheGetAllForRepositoryMethod() { - var client = Helper.GetAuthenticatedClient(); + _client = Helper.GetAuthenticatedClient(); - _fixture = client.Repository.Comment; + _fixture = _client.Repository.Comment; } [IntegrationTest] @@ -169,6 +172,45 @@ 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 _client.CreateRepositoryContext("public-repo")) + { + var commentIds = new List(); + + // Create multiple test commits + for (int count = 1; count <= numberToCreate; count++) + { + var commit = await SetupCommitForRepository(_client, context.RepositoryOwner, context.RepositoryName); + + // Each with a comment with reactions + var commentId = await HelperCreateCommitCommentWithReactions(_client, context.RepositoryOwner, context.RepositoryName, commit.Sha); + commentIds.Add(commentId); + } + Assert.Equal(numberToCreate, commentIds.Count); + + // Retrieve all comments for the commit + 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 @@ -317,35 +359,10 @@ public TheCreateMethod() _context = _github.CreateRepositoryContext("public-repo").Result; } - private async Task SetupCommitForRepository(IGitHubClient client) - { - var blob = new NewBlob - { - Content = "Hello World!", - Encoding = EncodingType.Utf8 - }; - var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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(_context.RepositoryOwner, _context.RepositoryName, newTree); - - var newCommit = new NewCommit("test-commit", treeResult.Sha); - - return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit); - } - [IntegrationTest] public async Task CanCreateComment() { - var commit = await SetupCommitForRepository(_github); + var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); var comment = new NewCommitComment("test"); @@ -362,7 +379,7 @@ public async Task CanCreateComment() [IntegrationTest] public async Task CanCreateCommentWithRepositoryId() { - var commit = await SetupCommitForRepository(_github); + var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); var comment = new NewCommitComment("test"); @@ -376,38 +393,6 @@ 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(); @@ -426,35 +411,10 @@ public TheUpdateMethod() _context = _github.CreateRepositoryContext("public-repo").Result; } - private async Task SetupCommitForRepository(IGitHubClient client) - { - var blob = new NewBlob - { - Content = "Hello World!", - Encoding = EncodingType.Utf8 - }; - var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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(_context.RepositoryOwner, _context.RepositoryName, newTree); - - var newCommit = new NewCommit("test-commit", treeResult.Sha); - - return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit); - } - [IntegrationTest] public async Task CanUpdateComment() { - var commit = await SetupCommitForRepository(_github); + var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); var comment = new NewCommitComment("test"); @@ -477,7 +437,7 @@ public async Task CanUpdateComment() [IntegrationTest] public async Task CanUpdateCommentWithRepositoryId() { - var commit = await SetupCommitForRepository(_github); + var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); var comment = new NewCommitComment("test"); @@ -515,35 +475,10 @@ public TheDeleteMethod() _context = _github.CreateRepositoryContext("public-repo").Result; } - private async Task SetupCommitForRepository(IGitHubClient client) - { - var blob = new NewBlob - { - Content = "Hello World!", - Encoding = EncodingType.Utf8 - }; - var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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(_context.RepositoryOwner, _context.RepositoryName, newTree); - - var newCommit = new NewCommit("test-commit", treeResult.Sha); - - return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit); - } - [IntegrationTest] public async Task CanDeleteComment() { - var commit = await SetupCommitForRepository(_github); + var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); var comment = new NewCommitComment("test"); @@ -575,7 +510,7 @@ public async Task CanDeleteComment() [IntegrationTest] public async Task CanDeleteCommentWithRepositoryId() { - var commit = await SetupCommitForRepository(_github); + var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); var comment = new NewCommitComment("test"); @@ -609,4 +544,51 @@ public void Dispose() _context.Dispose(); } } + + async static Task SetupCommitForRepository(IGitHubClient client, string owner, string name) + { + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + var blobResult = await client.Git.Blob.Create(owner, name, 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, name, newTree); + + var newCommit = new NewCommit("test-commit", treeResult.Sha); + + return await client.Git.Commit.Create(owner, name, newCommit); + } + + async static Task HelperCreateCommitCommentWithReactions(IGitHubClient client, string owner, string name, string sha) + { + var newCommitComment = new NewCommitComment("test comment"); + + var commitComment = await client.Repository.Comment.Create(owner, name, sha, newCommitComment); + + Assert.NotNull(commitComment); + + foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) + { + var newReaction = new NewReaction(reactionType); + + var reaction = await client.Reaction.CommitComment.Create(owner, name, commitComment.Id, newReaction); + + Assert.IsType(reaction); + Assert.Equal(reactionType, reaction.Content); + Assert.Equal(commitComment.User.Id, reaction.User.Id); + } + + return commitComment.Id; + } } From bd10c351b8adcf453b651d75bbb7fed743ae81d1 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 8 Jul 2016 01:00:41 +1000 Subject: [PATCH 20/24] Rework reaction payload tests for IssueComments to handle Get, GetAllForIssue and GetAllForRepository calls --- .../Clients/IssueCommentsClientTests.cs | 193 ++++++++++++++---- 1 file changed, 148 insertions(+), 45 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs index a897767ae9..b772e21238 100644 --- a/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssueCommentsClientTests.cs @@ -3,15 +3,17 @@ using Octokit.Tests.Integration; using Octokit.Tests.Integration.Helpers; using Xunit; -using Octokit.Tests.Integration.Helpers; 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; @@ -19,9 +21,9 @@ public class TheGetMethod public TheGetMethod() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; + _issueCommentsClient = _github.Issue.Comment; } [IntegrationTest] @@ -39,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"; @@ -51,9 +80,9 @@ public class TheGetAllForRepositoryMethod public TheGetAllForRepositoryMethod() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; + _issueCommentsClient = _github.Issue.Comment; } [IntegrationTest] @@ -183,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"; @@ -196,9 +265,9 @@ public class TheGetAllForIssueMethod public TheGetAllForIssueMethod() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _issueCommentsClient = github.Issue.Comment; + _issueCommentsClient = _github.Issue.Comment; } [IntegrationTest] @@ -328,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 @@ -335,7 +443,6 @@ public class TheCreateMethod readonly IIssueCommentsClient _issueCommentsClient; readonly RepositoryContext _context; readonly IIssuesClient _issuesClient; - readonly IReactionsClient _reactionsClient; public TheCreateMethod() { @@ -347,42 +454,6 @@ public TheCreateMethod() _issuesClient = gitHubClient.Issue; _issueCommentsClient = gitHubClient.Issue.Comment; - _reactionsClient = gitHubClient.Reaction; - } - - [IntegrationTest] - public async Task CanGetReactionPayload() - { - 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 _issueCommentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, "A test comment"); - - Assert.NotNull(issueComment); - - foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) - { - var newReaction = new NewReaction(reactionType); - - var reaction = await _reactionsClient.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, newReaction); - - Assert.IsType(reaction); - Assert.Equal(reactionType, reaction.Content); - Assert.Equal(issueComment.User.Id, reaction.User.Id); - } - - var retrieved = await _issueCommentsClient.Get(_context.RepositoryOwner, _context.RepositoryName, issueComment.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); } [IntegrationTest] @@ -511,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; + } } From 50cd04c48aa56e3610b992d8ba2728ce97988a51 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 8 Jul 2016 01:00:56 +1000 Subject: [PATCH 21/24] Rework reaction payload tests for Issues client --- .../Clients/IssuesClientTests.cs | 121 +++++++++++++----- 1 file changed, 86 insertions(+), 35 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index 7574cbb50b..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,17 +10,16 @@ public class IssuesClientTests : IDisposable { + private readonly IGitHubClient _github; private readonly RepositoryContext _context; private readonly IIssuesClient _issuesClient; - private readonly IReactionsClient _reactionsClient; public IssuesClientTests() { - var github = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _issuesClient = github.Issue; - _reactionsClient = github.Reaction; - _context = github.CreateRepositoryContext(new NewRepository(repoName)).Result; + _issuesClient = _github.Issue; + _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result; } [IntegrationTest] @@ -35,30 +35,12 @@ public async Task CanDeserializeIssue() Assert.Equal(title, issue.Title); Assert.Equal(description, issue.Body); - foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) - { - var newReaction = new NewReaction(reactionType); - - var reaction = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Number, newReaction); - - Assert.IsType(reaction); - Assert.Equal(reactionType, reaction.Content); - Assert.Equal(issue.User.Id, reaction.User.Id); - } - var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.True(retrieved.Id > 0); Assert.False(retrieved.Locked); Assert.Equal(title, retrieved.Title); Assert.Equal(description, retrieved.Body); - 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] @@ -573,10 +555,6 @@ public async Task CanRetrieveAllIssues() var issue2 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); var issue3 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue3); var issue4 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue4); - var reaction1 = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue1.Number, new NewReaction(ReactionType.Plus1)); - var reaction2 = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue2.Number, new NewReaction(ReactionType.Minus1)); - var reaction3 = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue3.Number, new NewReaction(ReactionType.Confused)); - var reaction4 = await _reactionsClient.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue4.Number, new NewReaction(ReactionType.Laugh)); await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue4.Number, new IssueUpdate { State = ItemState.Closed }); var request = new RepositoryIssueRequest { State = ItemStateFilter.All }; @@ -588,14 +566,6 @@ public async Task CanRetrieveAllIssues() Assert.True(retrieved.Any(i => i.Number == issue2.Number)); Assert.True(retrieved.Any(i => i.Number == issue3.Number)); Assert.True(retrieved.Any(i => i.Number == issue4.Number)); - var issue = retrieved[0]; - Assert.Equal(4, issue.Reactions.TotalCount); - Assert.Equal(0, issue.Reactions.Plus1); - Assert.Equal(0, issue.Reactions.Hooray); - Assert.Equal(0, issue.Reactions.Heart); - Assert.Equal(0, issue.Reactions.Laugh); - Assert.Equal(1, issue.Reactions.Confused); - Assert.Equal(0, issue.Reactions.Minus1); } [IntegrationTest] @@ -1085,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(); From 9528faaaf8d22ea705f84f9612ee67a70891a6c7 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 8 Jul 2016 01:01:09 +1000 Subject: [PATCH 22/24] Rework reaction payload tests for PullRequestReviews client --- .../PullRequestReviewCommentsClientTests.cs | 148 +++++++++++++----- 1 file changed, 108 insertions(+), 40 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index 375afea583..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() @@ -395,41 +393,6 @@ public async Task CanGetForRepository() AssertComments(pullRequestComments, commentsToCreate, position); } - [IntegrationTest] - public async Task CanGetReactionPayload() - { - var pullRequest = await CreatePullRequest(_context); - - const int position = 1; - var commentsToCreate = new List { "Comment One", "Comment Two" }; - - await CreateComments(commentsToCreate, position, _context.RepositoryName, pullRequest.Sha, pullRequest.Number); - - var pullRequestComments = await _client.GetAllForRepository(Helper.UserName, _context.RepositoryName); - - AssertComments(pullRequestComments, commentsToCreate, position); - - foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) - { - var newReaction = new NewReaction(reactionType); - - var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, pullRequestComments[0].Id, newReaction); - - Assert.IsType(reaction); - Assert.Equal(reactionType, reaction.Content); - Assert.Equal(pullRequestComments[0].User.Id, reaction.User.Id); - } - var retrieved = await _github.PullRequest.Comment.GetAll(_context.RepositoryOwner, _context.RepositoryName, pullRequest.Number); - - Assert.Equal(6, retrieved[0].Reactions.TotalCount); - Assert.Equal(1, retrieved[0].Reactions.Plus1); - Assert.Equal(1, retrieved[0].Reactions.Hooray); - Assert.Equal(1, retrieved[0].Reactions.Heart); - Assert.Equal(1, retrieved[0].Reactions.Laugh); - Assert.Equal(1, retrieved[0].Reactions.Confused); - Assert.Equal(1, retrieved[0].Reactions.Minus1); - } - [IntegrationTest] public async Task CanGetForRepositoryWithRepositoryId() { @@ -885,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"); @@ -904,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 @@ -955,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 From 6770990b380921fd40da3b495b1be932073e693c Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 8 Jul 2016 01:01:24 +1000 Subject: [PATCH 23/24] Rework reaction payload tests for CommitComments client --- .../Clients/RepositoryCommentsClientTests.cs | 201 ++++++++++++++---- 1 file changed, 163 insertions(+), 38 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs index 140651913f..e2772df013 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 @@ -376,38 +485,6 @@ 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(); @@ -609,4 +686,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; + } } From 86bc30e00905dfded58824084c4c67ab86bff18b Mon Sep 17 00:00:00 2001 From: lrz-hal Date: Thu, 7 Jul 2016 17:18:34 +0200 Subject: [PATCH 24/24] Revert "[WIP] reaction payload tests" This reverts commit a6179b0f21a3ddfe36bfd3ae5eafae0e69b52252. --- .../Clients/RepositoryCommentsClientTests.cs | 212 ++++++++++-------- 1 file changed, 115 insertions(+), 97 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs index 90262f341e..140651913f 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs @@ -4,8 +4,6 @@ using Octokit.Tests.Integration; using Octokit.Tests.Integration.Helpers; using Xunit; -using System.Collections.Generic; -using System.Linq; public class RepositoryCommentsClientTests { @@ -40,7 +38,6 @@ public async Task CanGetCommentWithRepositoryId() public class TheGetAllForRepositoryMethod { - readonly IGitHubClient _client; readonly IRepositoryCommentsClient _fixture; const string owner = "octocat"; const string name = "Hello-World"; @@ -48,9 +45,9 @@ public class TheGetAllForRepositoryMethod public TheGetAllForRepositoryMethod() { - _client = Helper.GetAuthenticatedClient(); + var client = Helper.GetAuthenticatedClient(); - _fixture = _client.Repository.Comment; + _fixture = client.Repository.Comment; } [IntegrationTest] @@ -172,45 +169,6 @@ 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 _client.CreateRepositoryContext("public-repo")) - { - var commentIds = new List(); - - // Create multiple test commits - for (int count = 1; count <= numberToCreate; count++) - { - var commit = await SetupCommitForRepository(_client, context.RepositoryOwner, context.RepositoryName); - - // Each with a comment with reactions - var commentId = await HelperCreateCommitCommentWithReactions(_client, context.RepositoryOwner, context.RepositoryName, commit.Sha); - commentIds.Add(commentId); - } - Assert.Equal(numberToCreate, commentIds.Count); - - // Retrieve all comments for the commit - 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 @@ -359,10 +317,35 @@ public TheCreateMethod() _context = _github.CreateRepositoryContext("public-repo").Result; } + private async Task SetupCommitForRepository(IGitHubClient client) + { + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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(_context.RepositoryOwner, _context.RepositoryName, newTree); + + var newCommit = new NewCommit("test-commit", treeResult.Sha); + + return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit); + } + [IntegrationTest] public async Task CanCreateComment() { - var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); + var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); @@ -379,7 +362,7 @@ public async Task CanCreateComment() [IntegrationTest] public async Task CanCreateCommentWithRepositoryId() { - var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); + var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); @@ -393,6 +376,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(); @@ -411,10 +426,35 @@ public TheUpdateMethod() _context = _github.CreateRepositoryContext("public-repo").Result; } + private async Task SetupCommitForRepository(IGitHubClient client) + { + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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(_context.RepositoryOwner, _context.RepositoryName, newTree); + + var newCommit = new NewCommit("test-commit", treeResult.Sha); + + return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit); + } + [IntegrationTest] public async Task CanUpdateComment() { - var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); + var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); @@ -437,7 +477,7 @@ public async Task CanUpdateComment() [IntegrationTest] public async Task CanUpdateCommentWithRepositoryId() { - var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); + var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); @@ -475,10 +515,35 @@ public TheDeleteMethod() _context = _github.CreateRepositoryContext("public-repo").Result; } + private async Task SetupCommitForRepository(IGitHubClient client) + { + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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(_context.RepositoryOwner, _context.RepositoryName, newTree); + + var newCommit = new NewCommit("test-commit", treeResult.Sha); + + return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit); + } + [IntegrationTest] public async Task CanDeleteComment() { - var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); + var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); @@ -510,7 +575,7 @@ public async Task CanDeleteComment() [IntegrationTest] public async Task CanDeleteCommentWithRepositoryId() { - var commit = await SetupCommitForRepository(_github, _context.RepositoryOwner, _context.RepositoryName); + var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); @@ -544,51 +609,4 @@ public void Dispose() _context.Dispose(); } } - - async static Task SetupCommitForRepository(IGitHubClient client, string owner, string name) - { - var blob = new NewBlob - { - Content = "Hello World!", - Encoding = EncodingType.Utf8 - }; - var blobResult = await client.Git.Blob.Create(owner, name, 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, name, newTree); - - var newCommit = new NewCommit("test-commit", treeResult.Sha); - - return await client.Git.Commit.Create(owner, name, newCommit); - } - - async static Task HelperCreateCommitCommentWithReactions(IGitHubClient client, string owner, string name, string sha) - { - var newCommitComment = new NewCommitComment("test comment"); - - var commitComment = await client.Repository.Comment.Create(owner, name, sha, newCommitComment); - - Assert.NotNull(commitComment); - - foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) - { - var newReaction = new NewReaction(reactionType); - - var reaction = await client.Reaction.CommitComment.Create(owner, name, commitComment.Id, newReaction); - - Assert.IsType(reaction); - Assert.Equal(reactionType, reaction.Content); - Assert.Equal(commitComment.User.Id, reaction.User.Id); - } - - return commitComment.Id; - } }