diff --git a/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs new file mode 100644 index 00000000..d3b420f9 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/IssueCommentReactionsClientTests.cs @@ -0,0 +1,52 @@ +using Octokit; +using Octokit.Tests.Integration; +using Octokit.Tests.Integration.Helpers; +using System; +using System.Threading.Tasks; +using Xunit; + +public class IssueCommentReactionsClientTests +{ + public class TheCreateReactionMethod : IDisposable + { + private readonly RepositoryContext _context; + private readonly IIssuesClient _issuesClient; + private readonly IGitHubClient _github; + + public TheCreateReactionMethod() + { + _github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + _issuesClient = _github.Issue; + _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result; + } + + [IntegrationTest] + public async Task CanCreateReaction() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueComment = await _issuesClient.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Id, "A test comment"); + + Assert.NotNull(issueComment); + + var issueCommentReaction = await _github.Reaction.IssueComment.Create(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, new NewReaction(ReactionType.Heart)); + + Assert.NotNull(issueCommentReaction); + + Assert.IsType(issueCommentReaction); + + Assert.Equal(ReactionType.Heart, issueCommentReaction.Content); + + Assert.Equal(issueComment.User.Id, issueCommentReaction.UserId); + } + + public void Dispose() + { + _context.Dispose(); + } + } +} diff --git a/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs new file mode 100644 index 00000000..d01de5a3 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/IssueReactionsClientTests.cs @@ -0,0 +1,49 @@ +using Octokit; +using Octokit.Tests.Integration; +using Octokit.Tests.Integration.Helpers; +using System; +using System.Threading.Tasks; +using Xunit; + +public class IssueReactionsClientTests +{ + public class TheCreateReactionMethod : IDisposable + { + private readonly RepositoryContext _context; + private readonly IIssuesClient _issuesClient; + private readonly IGitHubClient _github; + + public TheCreateReactionMethod() + { + _github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + _issuesClient = _github.Issue; + _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result; + } + + [IntegrationTest] + public async Task CanCreateReaction() + { + var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + + Assert.NotNull(issue); + + var issueReaction = await _github.Reaction.Issue.Create(_context.RepositoryOwner, _context.RepositoryName, issue.Id, new NewReaction(ReactionType.Heart)); + + Assert.NotNull(issueReaction); + + Assert.IsType(issueReaction); + + Assert.Equal(ReactionType.Heart, issueReaction.Content); + + Assert.Equal(issue.User.Id, issueReaction.UserId); + } + + public void Dispose() + { + _context.Dispose(); + } + } +} + diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs new file mode 100644 index 00000000..745fd5f0 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentReactionsClientTests.cs @@ -0,0 +1,151 @@ +using Octokit; +using Octokit.Tests.Integration; +using Octokit.Tests.Integration.Helpers; +using System.Threading.Tasks; +using Xunit; + +public class PullRequestReviewCommentReactionsClientTests +{ + private readonly IGitHubClient _github; + private readonly IPullRequestReviewCommentsClient _client; + 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 PullRequestReviewCommentReactionsClientTests() + { + _github = Helper.GetAuthenticatedClient(); + + _client = _github.PullRequest.Comment; + + // We'll create a pull request that can be used by most tests + _context = _github.CreateRepositoryContext("test-repo").Result; + } + + [IntegrationTest] + public async Task CanCreateReaction() + { + var pullRequest = await CreatePullRequest(_context); + + const string body = "A review comment message"; + const int position = 1; + + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); + + var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id); + + AssertComment(commentFromGitHub, body, position); + + var pullRequestReviewCommentReaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, new NewReaction(ReactionType.Heart)); + + Assert.NotNull(pullRequestReviewCommentReaction); + + Assert.IsType(pullRequestReviewCommentReaction); + + Assert.Equal(ReactionType.Heart, pullRequestReviewCommentReaction.Content); + + Assert.Equal(commentFromGitHub.User.Id, pullRequestReviewCommentReaction.UserId); + } + + /// + /// 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) + { + var repoName = context.RepositoryName; + + // Creating a commit in master + + var createdCommitInMaster = await CreateCommit(repoName, "Hello World!", "README.md", "heads/master", "A master commit message"); + + // Creating a branch + + var newBranch = new NewReference(branchRef, createdCommitInMaster.Sha); + await _github.Git.Reference.Create(Helper.UserName, repoName, newBranch); + + // Creating a commit in the branch + + var createdCommitInBranch = await CreateCommit(repoName, "Hello from the fork!", path, branchHead, "A branch commit message"); + + // Creating a pull request + + var pullRequest = new NewPullRequest("Nice title for the pull request", branchName, "master"); + var createdPullRequest = await _github.PullRequest.Create(Helper.UserName, repoName, pullRequest); + + var data = new PullRequestData + { + Sha = createdCommitInBranch.Sha, + Number = createdPullRequest.Number + }; + + return data; + } + + async Task CreateCommit(string repoName, string blobContent, string treePath, string reference, string commitMessage) + { + // Creating a blob + var blob = new NewBlob + { + Content = blobContent, + Encoding = EncodingType.Utf8 + }; + + var createdBlob = await _github.Git.Blob.Create(Helper.UserName, repoName, blob); + + // Creating a tree + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem + { + Type = TreeType.Blob, + Mode = FileMode.File, + Path = treePath, + Sha = createdBlob.Sha + }); + + var createdTree = await _github.Git.Tree.Create(Helper.UserName, repoName, newTree); + var treeSha = createdTree.Sha; + + // Creating a commit + var parent = await _github.Git.Reference.Get(Helper.UserName, repoName, reference); + var commit = new NewCommit(commitMessage, treeSha, parent.Object.Sha); + + var createdCommit = await _github.Git.Commit.Create(Helper.UserName, repoName, commit); + await _github.Git.Reference.Update(Helper.UserName, repoName, reference, new ReferenceUpdate(createdCommit.Sha)); + + return createdCommit; + } + + async Task CreateComment(string body, int position, string commitId, int number) + { + return await CreateComment(body, position, _context.RepositoryName, commitId, number); + } + + async Task CreateComment(string body, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) + { + var comment = new PullRequestReviewCommentCreate(body, pullRequestCommitId, path, position); + + var createdComment = await _client.Create(Helper.UserName, repoName, pullRequestNumber, comment); + + AssertComment(createdComment, body, position); + + return createdComment; + } + + static void AssertComment(PullRequestReviewComment comment, string body, int position) + { + Assert.NotNull(comment); + Assert.Equal(body, comment.Body); + Assert.Equal(position, comment.Position); + } + + class PullRequestData + { + public int Number { get; set; } + public string Sha { get; set; } + } +} + diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index a2a98af7..9f208c78 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -84,6 +84,8 @@ + + @@ -97,6 +99,7 @@ +