Esempio n. 1
0
        public void ShouldErrorIfClosingDateIsInvalid(string propertyName, object actualPropertyValue, string expectedErrorPropertyName, string expectedErrorMessage)
        {
            //a valid model
            var m = new TrainingEditModel
            {
                EmployerAccountId   = "valid",
                VacancyId           = Guid.Parse("53b54daa-4702-4b69-97e5-12123a59f8ad"),
                ClosingDay          = "01",
                ClosingMonth        = "3",
                ClosingYear         = "2018",
                StartDay            = "7",
                StartMonth          = "04",
                StartYear           = "2018",
                SelectedProgrammeId = "valid"
            };

            var context = new ValidationContext(m, null, null);
            var result  = new List <ValidationResult>();

            //ensure we are starting with a valid model
            var isInitiallyValid = Validator.TryValidateObject(m, context, result, true);

            isInitiallyValid.Should().BeTrue();

            //set the property we are testing
            m.GetType().GetProperty(propertyName).SetValue(m, actualPropertyValue);

            // Act
            var isValid = Validator.TryValidateObject(m, context, result, true);

            isValid.Should().BeFalse();
            result.Should().HaveCount(1);
            result.Single(r => r.MemberNames.Single() == expectedErrorPropertyName).ErrorMessage.Should().Be(expectedErrorMessage);
        }
Esempio n. 2
0
        private async Task <IActionResult> ProgrammeNotFound(TrainingEditModel m, bool wizard)
        {
            ModelState.AddModelError(nameof(TrainingEditModel.SelectedProgrammeId), InvalidTraining);

            var vm = await _orchestrator.GetTrainingViewModelAsync(m, User.ToVacancyUser());

            vm.PageInfo.SetWizard(wizard);
            return(View(ViewNames.Training, vm));
        }
Esempio n. 3
0
        public async Task <IActionResult> ConfirmTraining(VacancyRouteModel vrm, string programmeId, [FromQuery] bool wizard)
        {
            var vm = await _orchestrator.GetConfirmTrainingViewModelAsync(vrm, programmeId);

            if (vm == null)
            {
                var m = new TrainingEditModel {
                    SelectedProgrammeId = programmeId, EmployerAccountId = vrm.EmployerAccountId, VacancyId = vrm.VacancyId
                };
                return(await ProgrammeNotFound(m, wizard));
            }

            vm.PageInfo.SetWizard(wizard);

            return(View(vm));
        }
Esempio n. 4
0
        public async Task <IActionResult> Training(TrainingEditModel m, [FromQuery] bool wizard)
        {
            var programme = await _orchestrator.GetProgrammeAsync(m.SelectedProgrammeId);

            if (programme == null)
            {
                return(await ProgrammeNotFound(m, wizard));
            }

            if (!ModelState.IsValid)
            {
                var vm = await _orchestrator.GetTrainingViewModelAsync(m, User.ToVacancyUser());

                vm.PageInfo.SetWizard(wizard);

                return(View(vm));
            }

            return(RedirectToRoute(RouteNames.Training_Confirm_Get, new { programmeId = m.SelectedProgrammeId, wizard }));
        }
Esempio n. 5
0
        public async Task <IActionResult> Training(TrainingEditModel m, [FromQuery] bool wizard)
        {
            var response = await _orchestrator.PostTrainingEditModelAsync(m, User.ToVacancyUser());

            if (!response.Success)
            {
                response.AddErrorsToModelState(ModelState);
            }

            if (!ModelState.IsValid)
            {
                var vm = await _orchestrator.GetTrainingViewModelAsync(m);

                vm.PageInfo.SetWizard(wizard);
                return(View(vm));
            }

            return(wizard
                ? RedirectToRoute(RouteNames.Wage_Get)
                : RedirectToRoute(RouteNames.Vacancy_Preview_Get));
        }