public void VacancyTypeRequired(VacancyType vacancyType, bool expectValid)
        {
            var viewModel = new NewVacancyViewModel
            {
                VacancyType = vacancyType
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).With(_furtherDetailsViewModel).Build();

            _validator.Validate(viewModel);
            _aggregateValidator.Validate(vacancyViewModel);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Errors);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Warnings);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.ErrorsAndWarnings);

            if (expectValid)
            {
                _validator.ShouldNotHaveValidationErrorFor(vm => vm.VacancyType, viewModel);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.NewVacancyViewModel, vm => vm.NewVacancyViewModel.VacancyType, vacancyViewModel);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.NewVacancyViewModel, vm => vm.NewVacancyViewModel.VacancyType, vacancyViewModel, RuleSets.Errors);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.NewVacancyViewModel, vm => vm.NewVacancyViewModel.VacancyType, vacancyViewModel, RuleSets.Warnings);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.NewVacancyViewModel, vm => vm.NewVacancyViewModel.VacancyType, vacancyViewModel, RuleSets.ErrorsAndWarnings);
            }
            else
            {
                _validator.ShouldHaveValidationErrorFor(vm => vm.VacancyType, viewModel);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.NewVacancyViewModel, vm => vm.NewVacancyViewModel.VacancyType, vacancyViewModel);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.NewVacancyViewModel, vm => vm.NewVacancyViewModel.VacancyType, vacancyViewModel, RuleSets.Errors);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.NewVacancyViewModel, vm => vm.NewVacancyViewModel.VacancyType, vacancyViewModel, RuleSets.Warnings);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.NewVacancyViewModel, vm => vm.NewVacancyViewModel.VacancyType, vacancyViewModel, RuleSets.ErrorsAndWarnings);
            }
        }
        public void ShouldRequireSectorCodeName(string sectorCodeName, VacancyType vacancyType, bool expectValid)
        {
            // Arrange.
            var viewModel = new TrainingDetailsViewModel
            {
                VacancyType    = vacancyType,
                SectorCodeName = sectorCodeName
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(_furtherDetailsViewModel).With(viewModel).Build();

            // Act.
            _validator.Validate(viewModel);
            _aggregateValidator.Validate(vacancyViewModel);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Errors);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Warnings);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.ErrorsAndWarnings);

            // Assert.
            if (expectValid)
            {
                _validator.ShouldNotHaveValidationErrorFor(m => m.SectorCodeName, viewModel);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.SectorCodeName, vacancyViewModel);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.SectorCodeName, vacancyViewModel, RuleSets.Errors);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.SectorCodeName, vacancyViewModel, RuleSets.Warnings);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.SectorCodeName, vacancyViewModel, RuleSets.ErrorsAndWarnings);
            }
            else
            {
                _validator.ShouldHaveValidationErrorFor(m => m.SectorCodeName, viewModel);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.SectorCodeName, vacancyViewModel);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.SectorCodeName, vacancyViewModel, RuleSets.Errors);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.SectorCodeName, vacancyViewModel, RuleSets.Warnings);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.SectorCodeName, vacancyViewModel, RuleSets.ErrorsAndWarnings);
            }
        }
        public static List <SelectListItem> GetDurationTypes(VacancyType vacancyType)
        {
            var durationTypes =
                Enum.GetValues(typeof(DurationType))
                .Cast <DurationType>()
                .Where(al => al != DurationType.Unknown && (vacancyType != VacancyType.Traineeship || al != DurationType.Years))
                .Select(al => new SelectListItem {
                Value = al.ToString(), Text = al.ToString().ToLower()
            })
                .ToList();

            return(durationTypes);
        }
Esempio n. 4
0
        public VacancyViewModel BuildValid(VacancyStatus status, VacancyType vacancyType)
        {
            var viewModel = new Fixture().Build <VacancyViewModel>().Create();

            viewModel.NewVacancyViewModel.VacancyType                    = vacancyType;
            viewModel.NewVacancyViewModel.OfflineVacancy                 = false;
            viewModel.NewVacancyViewModel.OfflineApplicationUrl          = null;
            viewModel.NewVacancyViewModel.OfflineApplicationInstructions = null;
            viewModel.TrainingDetailsViewModel.VacancyType               = vacancyType;
            viewModel.TrainingDetailsViewModel.TrainingType              = TrainingType.Frameworks;
            viewModel.TrainingDetailsViewModel.ApprenticeshipLevel       = ApprenticeshipLevel.Higher;
            viewModel.TrainingDetailsViewModel.ContactName               = null;
            viewModel.TrainingDetailsViewModel.ContactNumber             = null;
            viewModel.TrainingDetailsViewModel.ContactEmail              = null;
            viewModel.FurtherVacancyDetailsViewModel.Status              = status;
            viewModel.FurtherVacancyDetailsViewModel.VacancyType         = vacancyType;
            viewModel.FurtherVacancyDetailsViewModel.Duration            = 12;
            viewModel.FurtherVacancyDetailsViewModel.DurationType        = DurationType.Months;
            viewModel.FurtherVacancyDetailsViewModel.Wage                = new WageViewModel()
            {
                Type             = WageType.NationalMinimum,
                Classification   = WageClassification.NationalMinimum,
                Amount           = null,
                AmountLowerBound = null,
                AmountUpperBound = null,
                Text             = null,
                Unit             = WageUnit.NotApplicable,
                HoursPerWeek     = 30
            };
            viewModel.FurtherVacancyDetailsViewModel.VacancyDatesViewModel = new VacancyDatesViewModel
            {
                PossibleStartDate = new DateViewModel(DateTime.UtcNow.AddDays(28)),
                ClosingDate       = new DateViewModel(DateTime.UtcNow.AddDays(14))
            };
            viewModel.VacancyRequirementsProspectsViewModel.VacancyType = vacancyType;
            viewModel.Status               = status;
            viewModel.VacancyType          = vacancyType;
            viewModel.IsCandidateView      = false;
            viewModel.IsManageReviewerView = false;
            viewModel.VacancySource        = VacancySource.Raa;

            return(viewModel);
        }