public async Task And_ExecuteMergeRequestSuccessful_Then_ReturnRedirectToComplete()
        {
            var viewModel = SetupViewModel();

            var result = await MergeController.ConfirmAndComplete(viewModel) as RedirectToActionResult;

            result.ActionName.Should().Be(nameof(MergeController.MergeComplete));
        }
        public async Task And_ExecuteMergeRequestSuccessful_Then_MarkMergeRequestComplete()
        {
            var viewModel = SetupViewModel();

            await MergeController.ConfirmAndComplete(viewModel);

            _mockMergeSessionService.Verify(ms => ms.UpdateMergeRequest(It.Is <MergeRequest>(r => r.Completed == true)));
        }
        public void Then_MapMergeRequest()
        {
            var result = MergeController.ConfirmAndComplete() as ViewResult;

            var model = result.Model as ConfirmAndCompleteViewModel;

            model.AcceptWarning.Should().BeFalse();
            model.PrimaryEpaoName.Should().Be(_mergeRequest.PrimaryEpao.Name);
            model.SecondaryEpaoName.Should().Be(_mergeRequest.SecondaryEpao.Name);
        }
        public async Task And_MergeCommandThrowsException_Then_MergeRequestIsNotUpdated()
        {
            _mockApiClient.Setup(c => c.MergeOrganisations(It.IsAny <MergeOrganisationsCommand>()))
            .ThrowsAsync(new Exception());

            var viewModel = SetupViewModel();

            await MergeController.ConfirmAndComplete(viewModel);

            _mockMergeSessionService.Verify(ms => ms.UpdateMergeRequest(It.IsAny <MergeRequest>()), Times.Never());
        }
        public async Task And_MergeCommandThrowsException_Then_RedirectToErrorPage()
        {
            _mockApiClient.Setup(c => c.MergeOrganisations(It.IsAny <MergeOrganisationsCommand>()))
            .ThrowsAsync(new Exception());

            var viewModel = SetupViewModel();

            var result = await MergeController.ConfirmAndComplete(viewModel) as RedirectToActionResult;

            result.ActionName.Should().Be(nameof(MergeController.MergeError));
        }
        public async Task Then_ExecuteMergeRequest()
        {
            var viewModel = SetupViewModel();

            await MergeController.ConfirmAndComplete(viewModel);

            _mockApiClient.Verify(client => client.MergeOrganisations(It.Is <MergeOrganisationsCommand>(
                                                                          c => c.ActionedByUser == "*****@*****.**" &&
                                                                          c.PrimaryEndPointAssessorOrganisationId == _mergeRequest.PrimaryEpao.Id &&
                                                                          c.SecondaryEndPointAssessorOrganisationId == _mergeRequest.SecondaryEpao.Id &&
                                                                          c.SecondaryStandardsEffectiveTo == _mergeRequest.SecondaryEpaoEffectiveTo.Value)), Times.Once());
        }
        public async Task And_WarningIsNotAccepted_Then_ReturnView()
        {
            MergeController.ModelState.AddModelError("Error", "Error message");

            var viewModel = _autoFixture.Build <ConfirmAndCompleteViewModel>()
                            .With(c => c.AcceptWarning, false)
                            .Create();

            var result = await MergeController.ConfirmAndComplete(viewModel) as ViewResult;

            var model = result.Model as ConfirmAndCompleteViewModel;

            model.Should().BeEquivalentTo(viewModel);
        }