Beispiel #1
0
        protected async Task <IActionResult> ValidateAndUpdatePageAnswer <RAVM>(SubmitClarificationPageAnswerCommand command,
                                                                                Func <Task <RAVM> > viewModelBuilder,
                                                                                string errorView) where RAVM : ClarifierReviewAnswersViewModel
        {
            var validationResponse = await _clarificationPageValidator.Validate(command);

            if (validationResponse.Errors.Any())
            {
                foreach (var error in validationResponse.Errors)
                {
                    ModelState.AddModelError(error.Field, error.ErrorMessage);
                }
            }

            var submittedPageOutcomeSuccessfully = false;

            if (ModelState.IsValid)
            {
                var userId   = HttpContext.User.UserId();
                var userName = HttpContext.User.UserDisplayName();

                submittedPageOutcomeSuccessfully = await _clarificationApiClient.SubmitClarificationPageReviewOutcome(command.ApplicationId,
                                                                                                                      command.SequenceNumber,
                                                                                                                      command.SectionNumber,
                                                                                                                      command.PageId,
                                                                                                                      userId,
                                                                                                                      userName,
                                                                                                                      command.ClarificationResponse,
                                                                                                                      command.Status,
                                                                                                                      command.ReviewComment,
                                                                                                                      command.FilesToUpload);

                if (!submittedPageOutcomeSuccessfully)
                {
                    ModelState.AddModelError(string.Empty, "Unable to save outcome as this time");
                }
            }

            if (!submittedPageOutcomeSuccessfully)
            {
                var viewModel = await viewModelBuilder.Invoke();

                viewModel.Status               = command.Status;
                viewModel.OptionFailText       = command.OptionFailText;
                viewModel.OptionInProgressText = command.OptionInProgressText;
                viewModel.OptionPassText       = command.OptionPassText;

                viewModel.ClarificationResponse = command.ClarificationResponse;

                return(View(errorView, viewModel));
            }
            else if (string.IsNullOrEmpty(command.NextPageId))
            {
                return(RedirectToAction("ViewApplication", "ClarificationOverview", new { applicationId = command.ApplicationId }, $"sequence-{command.SequenceNumber}"));
            }
            else
            {
                return(RedirectToAction("ReviewPageAnswers", new { applicationId = command.ApplicationId, sequenceNumber = command.SequenceNumber, sectionNumber = command.SectionNumber, pageId = command.NextPageId }));
            }
        }
 public void SetUp()
 {
     _validator = new ClarificationPageValidator();
     _command   = new SubmitClarificationPageAnswerCommand {
         Heading = "heading", Status = ClarificationPageReviewStatus.Pass, ClarificationResponse = "valid response"
     };
 }
Beispiel #3
0
        protected async Task <IActionResult> ValidateAndUpdateSectorPageAnswer <SVM>(SubmitClarificationPageAnswerCommand command,
                                                                                     Func <Task <SVM> > viewModelBuilder,
                                                                                     string errorView) where SVM : ClarifierSectorDetailsViewModel
        {
            var validationResponse = await _clarificationPageValidator.Validate(command);

            if (validationResponse.Errors.Any())
            {
                foreach (var error in validationResponse.Errors)
                {
                    ModelState.AddModelError(error.Field, error.ErrorMessage);
                }
            }

            var submittedPageOutcomeSuccessfully = false;

            if (ModelState.IsValid)
            {
                var userId   = HttpContext.User.UserId();
                var userName = HttpContext.User.UserDisplayName();

                submittedPageOutcomeSuccessfully = await _clarificationApiClient.SubmitClarificationPageReviewOutcome(command.ApplicationId,
                                                                                                                      SequenceIds.DeliveringApprenticeshipTraining,
                                                                                                                      SectionIds.DeliveringApprenticeshipTraining.YourSectorsAndEmployees,
                                                                                                                      command.PageId,
                                                                                                                      userId,
                                                                                                                      userName,
                                                                                                                      command.ClarificationResponse,
                                                                                                                      command.Status,
                                                                                                                      command.ReviewComment,
                                                                                                                      null);

                if (!submittedPageOutcomeSuccessfully)
                {
                    ModelState.AddModelError(string.Empty, "Unable to save outcome as this time");
                }
            }

            if (!submittedPageOutcomeSuccessfully)
            {
                var viewModel = await viewModelBuilder.Invoke();

                viewModel.Status               = command.Status;
                viewModel.OptionFailText       = command.OptionFailText;
                viewModel.OptionInProgressText = command.OptionInProgressText;
                viewModel.OptionPassText       = command.OptionPassText;

                viewModel.ClarificationResponse = command.ClarificationResponse;

                return(View(errorView, viewModel));
            }

            return(RedirectToAction("ReviewPageAnswers", new
            {
                applicationId = command.ApplicationId,
                sequenceNumber = SequenceIds.DeliveringApprenticeshipTraining,
                sectionNumber = SectionIds.DeliveringApprenticeshipTraining.YourSectorsAndEmployees
            }));
        }
        public async Task POST_ReviewPageAnswers_When_Valid_submits_ClarificationPageReviewOutcome()
        {
            var viewModel = new ClarifierReviewAnswersViewModel
            {
                ApplicationId         = _applicationId,
                SequenceNumber        = _sequenceNumber,
                SectionNumber         = _sectionNumber,
                PageId                = _pageId,
                Status                = ClarificationPageReviewStatus.Pass,
                OptionPassText        = "test",
                ClarificationResponse = "All good"
            };

            var command = new SubmitClarificationPageAnswerCommand(viewModel);

            _sectionReviewOrchestrator.Setup(x => x.GetReviewAnswersViewModel(It.IsAny <GetReviewAnswersRequest>())).ReturnsAsync(viewModel);

            var validationResponse = new ValidationResponse();

            _clarificationPageValidator.Setup(x => x.Validate(command)).ReturnsAsync(validationResponse);

            _clarificationApiClient.Setup(x => x.SubmitClarificationPageReviewOutcome(command.ApplicationId,
                                                                                      command.SequenceNumber,
                                                                                      command.SectionNumber,
                                                                                      command.PageId,
                                                                                      _controller.User.UserId(),
                                                                                      _controller.User.UserDisplayName(),
                                                                                      command.ClarificationResponse,
                                                                                      command.Status,
                                                                                      command.ReviewComment,
                                                                                      It.IsAny <IFormFileCollection>())).ReturnsAsync(true);

            // act
            var result = await _controller.ReviewPageAnswers(command) as RedirectToActionResult;

            // assert
            Assert.AreEqual("ClarificationOverview", result.ControllerName);
            Assert.AreEqual("ViewApplication", result.ActionName);

            _clarificationApiClient.Verify(x => x.SubmitClarificationPageReviewOutcome(command.ApplicationId,
                                                                                       command.SequenceNumber,
                                                                                       command.SectionNumber,
                                                                                       command.PageId,
                                                                                       _controller.User.UserId(),
                                                                                       _controller.User.UserDisplayName(),
                                                                                       command.ClarificationResponse,
                                                                                       command.Status,
                                                                                       command.ReviewComment,
                                                                                       It.IsAny <IFormFileCollection>()), Times.Once);
        }
        public async Task POST_ReviewPageAnswers_When_Invalid_does_not_submit_ClarificationPageReviewOutcome()
        {
            var viewModel = new ClarifierReviewAnswersViewModel
            {
                ApplicationId         = _applicationId,
                SequenceNumber        = _sequenceNumber,
                SectionNumber         = _sectionNumber,
                PageId                = _pageId,
                Status                = ClarificationPageReviewStatus.Pass,
                OptionPassText        = "test",
                ClarificationResponse = null
            };

            var command = new SubmitClarificationPageAnswerCommand(viewModel);

            _sectionReviewOrchestrator.Setup(x => x.GetReviewAnswersViewModel(It.IsAny <GetReviewAnswersRequest>())).ReturnsAsync(viewModel);

            var error = new ValidationErrorDetail {
                Field = "Status", ErrorMessage = "Error"
            };
            var validationResponse = new ValidationResponse {
                Errors = new List <ValidationErrorDetail> {
                    error
                }
            };

            _clarificationPageValidator.Setup(x => x.Validate(command)).ReturnsAsync(validationResponse);

            // act
            var result = await _controller.ReviewPageAnswers(command) as ViewResult;

            var actualViewModel = result?.Model as ReviewAnswersViewModel;

            // assert
            Assert.That(result, Is.Not.Null);
            Assert.That(actualViewModel, Is.Not.Null);
            Assert.That(actualViewModel, Is.SameAs(viewModel));

            _clarificationApiClient.Verify(x => x.SubmitClarificationPageReviewOutcome(command.ApplicationId,
                                                                                       command.SequenceNumber,
                                                                                       command.SectionNumber,
                                                                                       command.PageId,
                                                                                       _controller.User.UserId(),
                                                                                       _controller.User.UserDisplayName(),
                                                                                       command.ClarificationResponse,
                                                                                       command.Status,
                                                                                       command.ReviewComment,
                                                                                       It.IsAny <IFormFileCollection>()), Times.Never);
        }
        public async Task <IActionResult> ReviewSectorAnswers(SubmitClarificationPageAnswerCommand command)
        {
            if (command.ClarificationRequired)
            {
                var userId = HttpContext.User.UserId();
                Func <Task <ClarifierSectorDetailsViewModel> > viewModelBuilder = () => _sectionReviewOrchestrator.GetSectorDetailsViewModel(new GetSectorDetailsRequest(command.ApplicationId, command.PageId, userId));

                return(await ValidateAndUpdateSectorPageAnswer(command, viewModelBuilder, $"~/Views/ClarificationSectionReview/ReviewSectorAnswers.cshtml"));
            }
            else
            {
                return(RedirectToAction("ReviewPageAnswers", "ClarificationSectionReview", new
                {
                    applicationId = command.ApplicationId,
                    sequenceNumber = SequenceIds.DeliveringApprenticeshipTraining,
                    sectionNumber = SectionIds.DeliveringApprenticeshipTraining.YourSectorsAndEmployees
                }));
            }
        }
        public async Task <IActionResult> ReviewPageAnswers(SubmitClarificationPageAnswerCommand command)
        {
            if (command.ClarificationRequired)
            {
                var userId = HttpContext.User.UserId();
                command.FilesToUpload = HttpContext.Request.Form.Files;

                Func <Task <ClarifierReviewAnswersViewModel> > viewModelBuilder = () => _sectionReviewOrchestrator.GetReviewAnswersViewModel(new GetReviewAnswersRequest(command.ApplicationId, userId, command.SequenceNumber, command.SectionNumber, command.PageId, command.NextPageId));

                return(await ValidateAndUpdatePageAnswer(command, viewModelBuilder, $"~/Views/ClarificationSectionReview/ReviewAnswers.cshtml"));
            }
            else if (string.IsNullOrEmpty(command.NextPageId))
            {
                return(RedirectToAction("ViewApplication", "ClarificationOverview", new { applicationId = command.ApplicationId }, $"sequence-{command.SequenceNumber}"));
            }
            else
            {
                return(RedirectToAction("ReviewPageAnswers", "ClarificationSectionReview", new { applicationId = command.ApplicationId, sequenceNumber = command.SequenceNumber, sectionNumber = command.SectionNumber, pageId = command.NextPageId }));
            }
        }
Beispiel #8
0
        public async Task <ValidationResponse> Validate(SubmitClarificationPageAnswerCommand command)
        {
            var validationResponse = new ValidationResponse
            {
                Errors = new List <ValidationErrorDetail>()
            };

            if (string.IsNullOrWhiteSpace(command.ClarificationResponse))
            {
                validationResponse.Errors.Add(new ValidationErrorDetail(nameof(command.ClarificationResponse), ClarificationResponseRequired));
            }
            else
            {
                var wordCount = ValidationHelper.GetWordCount(command.ClarificationResponse);
                if (wordCount > ClarificationResponseMaxWordsCount)
                {
                    validationResponse.Errors.Add(new ValidationErrorDetail(nameof(command.ClarificationResponse), ClarificationResponseTooManyWords));
                }
            }

            if (string.IsNullOrWhiteSpace(command.Status))
            {
                validationResponse.Errors.Add(new ValidationErrorDetail("OptionPass", ValidationHelper.StatusMandatoryValidationMessage(command.PageId, command.Heading)));
            }
            else
            {
                switch (command.Status)
                {
                case ClarificationPageReviewStatus.Pass:
                {
                    var wordCount = ValidationHelper.GetWordCount(command.OptionPassText);
                    if (wordCount > MaxWordsCount)
                    {
                        validationResponse.Errors.Add(new ValidationErrorDetail(nameof(command.OptionPassText), TooManyWords));
                    }

                    break;
                }

                case ClarificationPageReviewStatus.Fail:
                {
                    var wordCount = ValidationHelper.GetWordCount(command.OptionFailText);
                    if (wordCount < RequiredMinimumWordsCount)
                    {
                        validationResponse.Errors.Add(new ValidationErrorDetail(nameof(command.OptionFailText), CommentRequired));
                    }
                    else if (wordCount > MaxWordsCount)
                    {
                        validationResponse.Errors.Add(new ValidationErrorDetail(nameof(command.OptionFailText), TooManyWords));
                    }

                    break;
                }

                case ClarificationPageReviewStatus.InProgress:
                {
                    var wordCount = ValidationHelper.GetWordCount(command.OptionInProgressText);
                    if (wordCount > MaxWordsCount)
                    {
                        validationResponse.Errors.Add(new ValidationErrorDetail(nameof(command.OptionInProgressText), TooManyWords));
                    }

                    break;
                }
                }
            }

            if (command.FilesToUpload != null)
            {
                foreach (var file in command.FilesToUpload)
                {
                    if (!FileContentIsValidForPdfFile(file))
                    {
                        validationResponse.Errors.Add(new ValidationErrorDetail("ClarificationFile", FileMustBePdf));
                        break;
                    }
                    else if (file.Length > MaxFileSizeInBytes)
                    {
                        validationResponse.Errors.Add(new ValidationErrorDetail("ClarificationFile", MaxFileSizeExceeded));
                        break;
                    }
                }
            }

            return(await Task.FromResult(validationResponse));
        }