Exemplo n.º 1
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"
                }
            );
        }