public async Task CanListReactions()
        {
            var commit = await SetupCommitForRepository(_github);

            var comment = new NewCommitComment("test");

            var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
                                                                 commit.Sha, comment);

            Assert.NotNull(result);

            var confusedReaction = new NewReaction(ReactionType.Confused);
            var firstReaction    = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, confusedReaction);

            var rocketReaction = new NewReaction(ReactionType.Rocket);
            var secondReaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, rocketReaction);

            var reactions = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id);

            Assert.NotEmpty(reactions);

            Assert.Equal(firstReaction.Id, reactions[0].Id);
            Assert.Equal(firstReaction.Content, reactions[0].Content);

            Assert.Equal(secondReaction.Id, reactions[1].Id);
            Assert.Equal(secondReaction.Content, reactions[1].Content);
        }
예제 #2
0
        public async Task ReturnsCorrectCountOfReactionsWithStartWithRepositoryId()
        {
            var commit = await SetupCommitForRepository(_github);

            var comment = new NewCommitComment("test");

            var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
                                                                 commit.Sha, comment);

            Assert.NotNull(result);

            var reactions        = new List <Reaction>();
            var reactionsContent = new[] { ReactionType.Confused, ReactionType.Hooray };

            for (var i = 0; i < 2; i++)
            {
                var newReaction = new NewReaction(reactionsContent[i]);
                var reaction    = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction);

                reactions.Add(reaction);
            }

            var options = new ApiOptions
            {
                PageSize  = 1,
                PageCount = 1,
                StartPage = 2
            };
            var reactionsInfo = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, options);

            Assert.Equal(1, reactionsInfo.Count);

            Assert.Equal(reactions.Last().Id, reactionsInfo[0].Id);
            Assert.Equal(reactions.Last().Content, reactionsInfo[0].Content);
        }
        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.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>(reaction);
                Assert.Equal(reactionType, reaction.Content);
                Assert.Equal(issueComment.User.Id, reaction.User.Id);
            }
        }
예제 #4
0
        public async Task ReturnsCorrectCountOfReactionsWithoutStart()
        {
            var commit = await SetupCommitForRepository(_github);

            var comment = new NewCommitComment("test");

            var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
                                                                 commit.Sha, comment);

            Assert.NotNull(result);

            var newReaction = new NewReaction(ReactionType.Confused);
            var reaction    = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction);

            var options = new ApiOptions
            {
                PageSize  = 1,
                PageCount = 1
            };
            var reactions = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id, options);

            Assert.Equal(1, reactions.Count);

            Assert.Equal(reaction.Id, reactions[0].Id);
            Assert.Equal(reaction.Content, reactions[0].Content);
        }
예제 #5
0
            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.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction);

                    Assert.IsType <Reaction>(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);
            }
        /// <summary>
        /// Creates a reaction for a specified Issue Comment
        /// </summary>
        /// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment</remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="number">The comment id</param>
        /// <param name="reaction">The reaction to create </param>
        public IObservable <Reaction> Create(string owner, string name, int number, NewReaction reaction)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(reaction, "reaction");

            return(_client.Create(owner, name, number, reaction).ToObservable());
        }
        /// <summary>
        /// Creates a reaction for a specified Issue Comment
        /// </summary>
        /// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment</remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="number">The comment id</param>
        /// <param name="reaction">The reaction to create </param>
        public IObservable<Reaction> Create(string owner, string name, int number, NewReaction reaction)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(reaction, "reaction");

            return _client.Create(owner, name, number, reaction).ToObservable();
        }
예제 #8
0
            public void RequestsCorrectUrl()
            {
                var githubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableReactionsClient(githubClient);
                var newReaction  = new NewReaction(ReactionType.Confused);

                client.CommitComment.Create("fake", "repo", 1, newReaction);
                githubClient.Received().Reaction.CommitComment.Create("fake", "repo", 1, newReaction);
            }
            public void RequestsCorrectUrl()
            {
                var githubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableReactionsClient(githubClient);
                var newReaction = new NewReaction(ReactionType.Confused);

                client.CommitComment.Create("fake", "repo", 1, newReaction);
                githubClient.Received().Reaction.CommitComment.Create("fake", "repo", 1, newReaction);
            }
예제 #10
0
            public void RequestsCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableIssueCommentReactionsClient(gitHubClient);
                var newReaction  = new NewReaction(ReactionType.Confused);

                client.Create(1, 1, newReaction);

                gitHubClient.Received().Reaction.IssueComment.Create(1, 1, newReaction);
            }
            public void RequestsCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservablePullRequestReviewCommentReactionsClient(gitHubClient);
                var newReaction = new NewReaction(ReactionType.Confused);

                client.Create(1, 1, newReaction);

                gitHubClient.Received().Reaction.PullRequestReviewComment.Create(1, 1, newReaction);
            }
            public void RequestsCorrectUrl()
            {
                NewReaction newReaction = new NewReaction(ReactionType.Heart);

                var connection = Substitute.For <IApiConnection>();
                var client     = new ReactionsClient(connection);

                client.Issue.Create("fake", "repo", 1, newReaction);

                connection.Received().Post <Reaction>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/issues/1/reactions"), Arg.Any <object>(), "application/vnd.github.squirrel-girl-preview");
            }
            public void RequestsCorrectUrl()
            {
                NewReaction newReaction = new NewReaction(ReactionType.Heart);

                var connection = Substitute.For<IApiConnection>();
                var client = new ReactionsClient(connection);

                client.CommitComment.Create("fake", "repo", 1, newReaction);

                connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/1/reactions"), Arg.Any<object>(), "application/vnd.github.squirrel-girl-preview");
            }
예제 #14
0
            public void RequestsCorrectUrl()
            {
                NewReaction newReaction = new NewReaction(ReactionType.Heart);

                var connection = Substitute.For <IApiConnection>();
                var client     = new PullRequestReviewCommentReactionsClient(connection);

                client.Create("fake", "repo", 1, newReaction);

                connection.Received().Post <Reaction>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/pulls/comments/1/reactions"), newReaction, "application/vnd.github.squirrel-girl-preview+json");
            }
            public void RequestsCorrectUrlWithRepositoryId()
            {
                NewReaction newReaction = new NewReaction(ReactionType.Heart);

                var connection = Substitute.For <IApiConnection>();
                var client     = new CommitCommentReactionsClient(connection);

                client.Create(1, 1, newReaction);

                connection.Received().Post <Reaction>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/comments/1/reactions"), newReaction, "application/vnd.github.squirrel-girl-preview");
            }
            public void RequestsCorrectUrlWithRepositoryId()
            {
                NewReaction newReaction = new NewReaction(ReactionType.Heart);

                var connection = Substitute.For<IApiConnection>();
                var client = new IssueCommentReactionsClient(connection);

                client.Create(1, 1, newReaction);

                connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/comments/1/reactions"), newReaction, "application/vnd.github.squirrel-girl-preview");
            }
예제 #17
0
        public async Task CanCreateReactionWithRepositoryId()
        {
            var commit = await SetupCommitForRepository(_github);

            var comment = new NewCommitComment("test");

            var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
                                                                 commit.Sha, comment);

            Assert.NotNull(result);

            var newReaction = new NewReaction(ReactionType.Confused);
            var reaction    = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction);

            Assert.IsType <Reaction>(reaction);

            Assert.Equal(ReactionType.Confused, reaction.Content);

            Assert.Equal(result.User.Id, reaction.User.Id);
        }
예제 #18
0
    async static Task <int> 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>(reaction);
            Assert.Equal(reactionType, reaction.Content);
            Assert.Equal(issueComment.User.Id, reaction.User.Id);
        }

        return(issueComment.Id);
    }
예제 #19
0
        private async static Task <int> 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>(reaction);
                Assert.Equal(reactionType, reaction.Content);
                Assert.Equal(commitComment.User.Id, reaction.User.Id);
            }

            return(commitComment.Id);
        }
예제 #20
0
        public async Task ReturnsDistinctReactionsBasedOnStartPageWithRepositoryId()
        {
            var commit = await SetupCommitForRepository(_github);

            var comment = new NewCommitComment("test");

            var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
                                                                 commit.Sha, comment);

            Assert.NotNull(result);

            var reactionsContent = new[] { ReactionType.Confused, ReactionType.Hooray };

            for (var i = 0; i < 2; i++)
            {
                var newReaction = new NewReaction(reactionsContent[i]);
                var reaction    = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction);
            }

            var startOptions = new ApiOptions
            {
                PageSize  = 1,
                PageCount = 1,
                StartPage = 1
            };
            var firstPage = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, startOptions);

            var skipStartOptions = new ApiOptions
            {
                PageSize  = 1,
                PageCount = 1,
                StartPage = 1
            };
            var secondPage = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, skipStartOptions);

            Assert.Equal(1, firstPage.Count);
            Assert.Equal(1, secondPage.Count);
            Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
            Assert.NotEqual(firstPage[0].Content, secondPage[0].Content);
        }
예제 #21
0
    async Task <int> 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>(reaction);
            Assert.Equal(reactionType, reaction.Content);
            Assert.Equal(reviewComment.User.Id, reaction.User.Id);
        }

        return(reviewComment.Id);
    }
예제 #22
0
        public async Task CanCreateReaction()
        {
            var commit = await SetupCommitForRepository(_github);

            var comment = new NewCommitComment("test");

            var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
                                                                 commit.Sha, comment);

            Assert.NotNull(result);

            foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType)))
            {
                var newReaction = new NewReaction(reactionType);

                var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction);

                Assert.IsType <Reaction>(reaction);
                Assert.Equal(reactionType, reaction.Content);
                Assert.Equal(result.User.Id, reaction.User.Id);
            }
        }
예제 #23
0
    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);

        foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType)))
        {
            var newReaction = new NewReaction(reactionType);

            var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, newReaction);

            Assert.IsType <Reaction>(reaction);
            Assert.Equal(reactionType, reaction.Content);
            Assert.Equal(commentFromGitHub.User.Id, reaction.User.Id);
        }
    }
        /// <summary>
        /// Creates a reaction for a specified Issue Comment
        /// </summary>
        /// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The comment id</param>
        /// <param name="reaction">The reaction to create </param>
        public IObservable <Reaction> Create(int repositoryId, int number, NewReaction reaction)
        {
            Ensure.ArgumentNotNull(reaction, "reaction");

            return(_client.Create(repositoryId, number, reaction).ToObservable());
        }
        /// <summary>
        /// Creates a reaction for a specified Issue Comment
        /// </summary>
        /// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment</remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="number">The comment id</param>
        /// <param name="reaction">The reaction to create </param>
        public IObservable<Reaction> Create(int repositoryId, int number, NewReaction reaction)
        {
            Ensure.ArgumentNotNull(reaction, "reaction");

            return _client.Create(repositoryId, number, reaction).ToObservable();
        }
예제 #26
0
 protected virtual void OnRaiseCustomEvent(NewReactionEventArgs e)
 {
     NewReaction?.Invoke(this, e);
 }