public async Task <ValidationResponse> Validate(SubmitClarificationOutcomeConfirmationCommand command) { var validationResponse = new ValidationResponse { Errors = new List <ValidationErrorDetail>() }; if (!string.IsNullOrEmpty(command.ConfirmStatus)) { return(await Task.FromResult(validationResponse)); } switch (command.Status) { case ClarificationConfirmationStatus.Pass: validationResponse.Errors.Add(new ValidationErrorDetail(nameof(command.ConfirmStatus), EnterAPassConfirmation)); break; case ClarificationConfirmationStatus.Fail: validationResponse.Errors.Add(new ValidationErrorDetail(nameof(command.ConfirmStatus), EnterAFailConfirmation)); break; default: validationResponse.Errors.Add(new ValidationErrorDetail(nameof(command.ConfirmStatus), "Pick a choice")); break; } return(await Task.FromResult(validationResponse)); }
public async Task Outcome_confirmation_redirect_back_to_application_when_status_is_fail_and_confirm_status_is_No() { var command = new SubmitClarificationOutcomeConfirmationCommand(ClarificationConfirmationStatus.Fail, "No"); _mockValidator.Setup(x => x.Validate(command)) .ReturnsAsync(new ValidationResponse() ); var reviewComment = "comment goes here"; var result = await _controller.SubmitClarificationOutcomeConfirmation(_applicationId, reviewComment, command) as ViewResult; _outcomeViewModel.OptionFailText = reviewComment; Assert.That(result.Model, Is.SameAs(_outcomeViewModel)); _mockOrchestrator.Verify(x => x.GetClarificationOutcomeViewModel(It.IsAny<GetClarificationOutcomeRequest>()), Times.Once); }
public async Task Outcome_confirmation_redirect_back_to_application_when_save_is_unsuccessful() { var command = new SubmitClarificationOutcomeConfirmationCommand(string.Empty, "Yes"); _mockValidator.Setup(x => x.Validate(command)) .ReturnsAsync(new ValidationResponse() ); _mockModerationApiClient.Setup(x => x.SubmitModerationOutcome(_applicationId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) .ReturnsAsync(false); var result = await _controller.SubmitClarificationOutcomeConfirmation(_applicationId, string.Empty, command) as ViewResult; Assert.That(result.Model, Is.SameAs(_outcomeViewModel)); _mockOrchestrator.Verify(x => x.GetClarificationOutcomeViewModel(It.IsAny<GetClarificationOutcomeRequest>()), Times.Once); }
public async Task Outcome_confirmation_redirect_back_to_outcome_when_error() { var command = new SubmitClarificationOutcomeConfirmationCommand("", ""); _mockValidator.Setup(x => x.Validate(command)) .ReturnsAsync(new ValidationResponse { Errors = new List<ValidationErrorDetail> { new ValidationErrorDetail {Field="Status", ErrorMessage = "error"} } } ); var result = await _controller.SubmitClarificationOutcomeConfirmation(_applicationId, string.Empty, command) as ViewResult; Assert.That(result.Model, Is.SameAs(_outcomeViewModel)); _mockOrchestrator.Verify(x => x.GetClarificationOutcomeViewModel(It.IsAny<GetClarificationOutcomeRequest>()), Times.Once); }
public void SetUp() { _validator = new ClarificationOutcomeValidator(); _submitClarificationOutcomeCommand = new SubmitClarificationOutcomeCommand(); _outcomeConfirmationCommand = new SubmitClarificationOutcomeConfirmationCommand(); }
public async Task <IActionResult> SubmitClarificationOutcomeConfirmation(Guid applicationId, string reviewComment, SubmitClarificationOutcomeConfirmationCommand command) { var validationResponse = await _validator.Validate(command); if (validationResponse.Errors.Any()) { foreach (var error in validationResponse.Errors) { ModelState.AddModelError(error.Field, error.ErrorMessage); } } var userId = HttpContext.User.UserId(); if (!ModelState.IsValid) { return(await GoToErrorView(applicationId, reviewComment, command.Status, userId)); } if (command.ConfirmStatus == "No") { var viewModel = await _outcomeOrchestrator.GetClarificationOutcomeViewModel(new GetClarificationOutcomeRequest(applicationId, userId)); viewModel.Status = command.Status; switch (command.Status) { case ModerationConfirmationStatus.Pass: viewModel.OptionPassText = reviewComment; break; case ModerationConfirmationStatus.Fail: viewModel.OptionFailText = reviewComment; break; } return(View("~/Views/ClarificationOutcome/Application.cshtml", viewModel)); } var userName = HttpContext.User.UserDisplayName(); var submittedStatus = ModerationStatus.InProgress; switch (command.Status) { case ClarificationConfirmationStatus.Pass: submittedStatus = ModerationStatus.Pass; break; case ClarificationConfirmationStatus.Fail: submittedStatus = ModerationStatus.Fail; break; } var submitSuccessful = await _moderationApiClient.SubmitModerationOutcome(applicationId, userId, userName, submittedStatus, reviewComment); if (!submitSuccessful) { _logger.LogError($"Unable to save moderation outcome for applicationId: [{applicationId}]"); ModelState.AddModelError(string.Empty, "Unable to save clarification outcome as this time"); return(await GoToErrorView(applicationId, reviewComment, command.Status, userId)); } var viewModelClarificationOutcomeSaved = await _outcomeOrchestrator.GetClarificationOutcomeReviewViewModel( new ReviewClarificationOutcomeRequest(applicationId, userId, command.Status, reviewComment)); return(View("~/Views/ModeratorOutcome/ModerationCompleted.cshtml", viewModelClarificationOutcomeSaved)); }