public async Task Handle_NoExistingBotCommentFound_InsertsNewComment()
        {
            //Arrange
            var fakeGitHubClientFactory = Substitute.For <IGitHubClientFactory>();

            var fakeGitHubClient = await fakeGitHubClientFactory.CreateInstallationClientAsync(1337);

            fakeGitHubClient
            .PullRequest
            .Get(
                1337,
                1337)
            .Returns(
                CreatePullRequestDto(
                    CreateGitReferenceDto(
                        CreateRepositoryDto(
                            1337))));

            fakeGitHubClient
            .Issue
            .Comment
            .GetAllForIssue(
                Arg.Any <long>(),
                Arg.Any <int>())
            .Returns(new[]
            {
                CreateIssueDto(CreateUserDto(1337)),
                CreateIssueDto(CreateUserDto(1338))
            });

            var handler = new UpsertPullRequestCommentCommandHandler(
                fakeGitHubClientFactory,
                Substitute.For <IMediator>());

            //Act
            await handler.Handle(
                new UpsertPullRequestCommentCommand(
                    new PullDogPullRequest()
            {
                Handle = "1337",
                PullDogRepository = new PullDogRepository()
                {
                    Handle = "1337",
                    GitHubInstallationId = 1337,
                    PullDogSettings = new PullDogSettings()
                }
            },
                    "some-content"),
                default);

            //Assert
            await fakeGitHubClient
            .Issue
            .Comment
            .Received(1)
            .Create(
                1337,
                Arg.Any <int>(),
                Arg.Any <string>());
        }
        public async Task Handle_InvalidPullRequestHandleGiven_ThrowsException()
        {
            //Arrange
            var fakeGitHubClientFactory = Substitute.For <IGitHubClientFactory>();

            var handler = new UpsertPullRequestCommentCommandHandler(
                fakeGitHubClientFactory,
                Substitute.For <IMediator>());

            //Act
            var exception = await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() =>
                                                                                          await handler.Handle(
                                                                                              new UpsertPullRequestCommentCommand(
                                                                                                  new PullDogPullRequest()
            {
                Handle            = "invalid-handle",
                PullDogRepository = new PullDogRepository()
                {
                    Handle = "1337",
                    GitHubInstallationId = 1337,
                    PullDogSettings      = new PullDogSettings()
                }
            },
                                                                                                  "some-content"),
                                                                                              default));

            //Assert
            Assert.IsNotNull(exception);
        }
        public async Task Handle_ExistingBotCommentFoundAndConversationModeIsMultipleComments_UpdatesExistingComment()
        {
            //Arrange
            var fakeGitHubClientFactory = Substitute.For <IGitHubClientFactory>();

            var fakeGitHubClient = await fakeGitHubClientFactory.CreateInstallationClientAsync(1337);

            fakeGitHubClient
            .PullRequest
            .Get(
                1337,
                1337)
            .Returns(
                CreatePullRequestDto(
                    CreateGitReferenceDto(
                        CreateRepositoryDto(
                            1337))));

            fakeGitHubClient
            .Issue
            .Comment
            .GetAllForIssue(
                Arg.Any <long>(),
                Arg.Any <int>())
            .Returns(new[]
            {
                CreateIssueDto(CreateUserDto(1337)),
                CreateIssueDto(CreateUserDto(64123634)),
                CreateIssueDto(CreateUserDto(1338))
            });

            var fakeMediator = Substitute.For <IMediator>();

            fakeMediator
            .Send(Arg.Any <GetConfigurationForPullRequestQuery>())
            .Returns(new ConfigurationFile(new List <string>())
            {
                ConversationMode = ConversationMode.MultipleComments
            });

            var handler = new UpsertPullRequestCommentCommandHandler(
                fakeGitHubClientFactory,
                fakeMediator);

            //Act
            await handler.Handle(
                new UpsertPullRequestCommentCommand(
                    new PullDogPullRequest()
            {
                Handle = "1337",
                PullDogRepository = new PullDogRepository()
                {
                    Handle = "1337",
                    GitHubInstallationId = 1337,
                    PullDogSettings = new PullDogSettings()
                }
            },
                    "some-content"),
                default);

            //Assert
            await fakeGitHubClient
            .Issue
            .Comment
            .Received(1)
            .Create(
                1337,
                Arg.Any <int>(),
                Arg.Any <string>());
        }