Пример #1
0
        public void Validator_returns_error_if_month_and_year_are_current_date()
        {
            var errorMessages = DateOfBirthAnswerValidator.ValidateDateOfBirth(DateTime.Now.Month.ToString(), DateTime.Now.Year.ToString(), FieldPrefix);

            var fieldKey = $"{FieldPrefix}Month";

            var validationError = errorMessages.FirstOrDefault(x => x.Field == fieldKey);

            validationError.Should().NotBeNull();
            validationError.ErrorMessage.Should().Be(DateOfBirthAnswerValidator.DateOfBirthInFutureErrorMessage);
        }
Пример #2
0
        public void Validator_returns_error_if_year_value_invalid(string yearValue)
        {
            var errorMessages = DateOfBirthAnswerValidator.ValidateDateOfBirth("12", yearValue, FieldPrefix);

            var fieldKey = $"{FieldPrefix}Year";

            var validationError = errorMessages.FirstOrDefault(x => x.Field == fieldKey);

            validationError.Should().NotBeNull();
            validationError.ErrorMessage.Should().Be(DateOfBirthAnswerValidator.DateOfBirthYearLengthErrorMessage);
        }
Пример #3
0
        public void Validator_returns_error_if_month_value_is_invalid(string monthValue)
        {
            var errorMessages = DateOfBirthAnswerValidator.ValidateDateOfBirth(monthValue, "2000", FieldPrefix);

            var fieldKey = $"{FieldPrefix}Month";

            var validationError = errorMessages.FirstOrDefault(x => x.Field == fieldKey);

            validationError.Should().NotBeNull();
            validationError.ErrorMessage.Should().Be(DateOfBirthAnswerValidator.InvalidIncompleteDateOfBirthErrorMessage);
        }
Пример #4
0
        public void Validator_returns_errors_if_both_fields_missing()
        {
            var errorMessages = DateOfBirthAnswerValidator.ValidateDateOfBirth(null, null, FieldPrefix);

            var fieldKey = $"{FieldPrefix}Month";

            var validationError = errorMessages.FirstOrDefault(x => x.Field == fieldKey);

            validationError.Should().NotBeNull();
            validationError.ErrorMessage.Should().Be(DateOfBirthAnswerValidator.InvalidIncompleteDateOfBirthErrorMessage);
        }
        public void Validator_returns_error_if_month_and_year_in_future()
        {
            var fieldMonthOrYear = "Month";
            var dobDate          = DateTime.Now.AddMonths(1);

            if (DateTime.Now.Month == 12)
            {
                fieldMonthOrYear = "Year";
            }

            var errorMessages = DateOfBirthAnswerValidator.ValidateDateOfBirth(dobDate.Month.ToString(), dobDate.Year.ToString(), FieldPrefix);

            var fieldKey = $"{FieldPrefix}{fieldMonthOrYear}";

            var validationError = errorMessages.FirstOrDefault(x => x.Field == fieldKey);

            validationError.Should().NotBeNull();
            validationError.ErrorMessage.Should().Be(DateOfBirthAnswerValidator.DateOfBirthInFutureErrorMessage);
        }
        public async Task <IActionResult> SoleTradeDobConfirmed(SoleTradeDobViewModel model)
        {
            var errorMessages = DateOfBirthAnswerValidator.ValidateDateOfBirth(model.SoleTraderDobMonth, model.SoleTraderDobYear, SoleTradeDobViewModel.DobFieldPrefix);

            if (errorMessages.Any())
            {
                model.ErrorMessages = errorMessages;
                return(View("~/Views/Roatp/WhosInControl/AddSoleTradeDob.cshtml", model));
            }

            var answerValue        = $"{model.SoleTraderDobMonth},{model.SoleTraderDobYear}";
            var soleTradeDobAnswer = new List <Answer>
            {
                new Answer
                {
                    QuestionId = RoatpYourOrganisationQuestionIdConstants.AddSoleTradeDob,
                    Value      = answerValue
                }
            };

            var result = await _qnaApiClient.UpdatePageAnswers(model.ApplicationId, RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl, RoatpWorkflowPageIds.WhosInControl.AddSoleTraderDob, soleTradeDobAnswer);

            return(RedirectToAction("TaskList", "RoatpApplication", new { applicationId = model.ApplicationId }, "Sequence_1"));
        }