public async Task <ActionResult <PostCommentResponseBody> > PostComment(
            string owner,
            string repository,
            string pullRequestId,
            [FromBody] PostCommentRequestBody requestBody)
        {
            var commentId    = _guidGenerator.GenerateString();
            var repositoryId = new RepositoryId(owner, repository);
            var command      = new AddSingleComment
                               (
                pullRequestId: pullRequestId,
                repositoryId: repositoryId.ToString(),
                commentId: commentId,
                author: requestBody.Author,
                text: requestBody.Text
                               );

            var streamName = new PullRequestCommentStreamName(commentId).ToString();
            await _applicationService.ExecuteAsync(streamName, history => _comments.AddSingleComment(history, command));

            return(Created(
                       $"repositories/{repositoryId}/pulls/{pullRequestId}/comments",
                       new PostCommentResponseBody {
                CommentId = commentId
            }
                       ));
        }
예제 #2
0
        public async Task UpdatePullRequestCommentsReadModelWhenSingleCommentWasAdded()
        {
            //When
            var randomOwner = _guidGenerator.GenerateString();
            var randomRepository = _guidGenerator.GenerateString();
            var repositoryId = new RepositoryId(randomOwner, randomRepository);
            var pullRequestId = _guidGenerator.GenerateString();
            var commentId = _guidGenerator.GenerateString();
            var singleCommentWasAdded = new SingleCommentWasAdded
            {
                OccurredAt = DateTime.UtcNow,
                PullRequestId = pullRequestId,
                RepositoryId = repositoryId.ToString(),
                CommentId = commentId,
                Author = "LoggedUser",
                Text = "Comment text"
            };

            var streamName = $"PullRequestComment-{commentId}";
            await _eventStore.Publish(streamName, singleCommentWasAdded, _eventSerializer);

            //Then
            var getUrl = $"/rest-api/{randomOwner}/{randomRepository}/pulls/{pullRequestId}/comments";
            await AssertionHelper.WaitUntil(async () => (await GetPullRequestComments(getUrl)).Comments.Count > 0);
            var responseBody = await GetPullRequestComments(getUrl);
            responseBody.Comments.Should().HaveCount(1);
            responseBody.Comments.Should().HaveElementAt(
                0,
                new PullRequestComment
                {
                    Author = "LoggedUser",
                    CommentId = commentId,
                    PostedAt = singleCommentWasAdded.OccurredAt,
                    PullRequestId = pullRequestId,
                    Text = "Comment text"
                }
            );
        }
        public async Task PostCommentShouldResultsWithSingleCommentWasAdded()
        {
            //Given
            var randomOwner      = _guidGenerator.GenerateString();
            var randomRepository = _guidGenerator.GenerateString();
            var repositoryId     = new RepositoryId(randomOwner, randomRepository);
            var pullRequestId    = _guidGenerator.GenerateString();

            //When
            var postRequest = new
            {
                Url  = $"/rest-api/{randomOwner}/{randomRepository}/pulls/{pullRequestId}/comments",
                Body = new
                {
                    Text   = "Comment text",
                    Author = "LoggedUser"
                }
            };
            var response = await _client.PostAsync(postRequest.Url, postRequest.Body.ToJson());

            //Then
            var responseBody =
                JsonConvert.DeserializeObject <PostCommentResponseBody>(await response.Content.ReadAsStringAsync());
            var expectedStreamName = $"PullRequestComment-{responseBody.CommentId}";
            var streamLastEvent    = await _eventStore.StreamLastEvent(expectedStreamName, _eventSerializer);

            streamLastEvent.Should().BeEquivalentTo(
                new SingleCommentWasAdded
                (
                    pullRequestId: pullRequestId,
                    repositoryId: repositoryId.ToString(),
                    commentId: responseBody.CommentId,
                    author: "LoggedUser",
                    text: "Comment text",
                    occurredAt: _clock.Now
                )
                );
        }