public async Task ShouldCallMediatorToDelete()
        {
            //Arrange
            var model = new DeleteApprenticeshipConfirmationViewModel
            {
                HashedAccountId        = "ABC123",
                HashedCommitmentId     = "ABC321",
                HashedApprenticeshipId = "ABC456"
            };

            MockMediator.Setup(x => x.SendAsync(It.IsAny <GetApprenticeshipQueryRequest>()))
            .ReturnsAsync(new GetApprenticeshipQueryResponse
            {
                Apprenticeship = new Apprenticeship()
            });

            MockMediator.Setup(x => x.SendAsync(It.IsAny <DeleteApprenticeshipCommand>())).ReturnsAsync(new Unit());

            var expectedName         = "Bob";
            var expectedEmailAddress = "*****@*****.**";

            //Act
            await EmployerCommitmentOrchestrator.DeleteApprenticeship(model, "externalUserId", expectedName, expectedEmailAddress);

            //Assert
            MockMediator.Verify(
                x =>
                x.SendAsync(
                    It.Is <DeleteApprenticeshipCommand>(
                        c => c.AccountId == 123L && c.ApprenticeshipId == 456L && c.UserId == "externalUserId" && c.UserDisplayName == expectedName && c.UserEmailAddress == expectedEmailAddress)),
                Times.Once);
        }
Exemple #2
0
        public async Task <ActionResult> DeleteApprenticeshipConfirmation(DeleteApprenticeshipConfirmationViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var errorResponse = await _employerCommitmentsOrchestrator.GetDeleteApprenticeshipViewModel(viewModel.HashedAccountId, OwinWrapper.GetClaimValue(@"sub"), viewModel.HashedCommitmentId, viewModel.HashedApprenticeshipId);

                return(View(errorResponse));
            }

            if (viewModel.DeleteConfirmed.HasValue && viewModel.DeleteConfirmed.Value)
            {
                await _employerCommitmentsOrchestrator.DeleteApprenticeship(viewModel, OwinWrapper.GetClaimValue(@"sub"), OwinWrapper.GetClaimValue(DasClaimTypes.DisplayName), OwinWrapper.GetClaimValue(DasClaimTypes.Email));

                var flashMessage = new FlashMessageViewModel {
                    Severity = FlashMessageSeverityLevel.Okay, Message = string.Format($"Apprentice record for {viewModel.ApprenticeshipName} deleted")
                };
                AddFlashMessageToCookie(flashMessage);

                return(RedirectToAction("Details", new { viewModel.HashedAccountId, viewModel.HashedCommitmentId }));
            }

            return(RedirectToAction("EditApprenticeship", new { viewModel.HashedAccountId, viewModel.HashedCommitmentId, viewModel.HashedApprenticeshipId }));
        }