public void ShouldRequireFrameworkCodeName(string frameworkCodeName, TrainingType trainingType, bool expectValid) { // Arrange. var viewModel = new TrainingDetailsViewModel { TrainingType = trainingType, FrameworkCodeName = frameworkCodeName }; var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).With(_furtherDetailsViewModel).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.FrameworkCodeName, viewModel); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.FrameworkCodeName, vacancyViewModel); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.FrameworkCodeName, vacancyViewModel, RuleSets.Errors); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.FrameworkCodeName, vacancyViewModel, RuleSets.Warnings); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.FrameworkCodeName, vacancyViewModel, RuleSets.ErrorsAndWarnings); } else { _validator.ShouldHaveValidationErrorFor(m => m.FrameworkCodeName, viewModel); _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.FrameworkCodeName, vacancyViewModel); _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.FrameworkCodeName, vacancyViewModel, RuleSets.Errors); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.FrameworkCodeName, vacancyViewModel, RuleSets.Warnings); _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.FrameworkCodeName, vacancyViewModel, RuleSets.ErrorsAndWarnings); } }
public void ShouldRequireStandardId(string standardIdString, TrainingType trainingType, bool expectValid) { // Arrange. int?standardId = null; int parsedStandardId; if (int.TryParse(standardIdString, out parsedStandardId)) { standardId = parsedStandardId; } var viewModel = new TrainingDetailsViewModel { TrainingType = trainingType, StandardId = standardId }; 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.StandardId, viewModel); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.StandardId, vacancyViewModel); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.StandardId, vacancyViewModel, RuleSets.Errors); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.StandardId, vacancyViewModel, RuleSets.Warnings); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.StandardId, vacancyViewModel, RuleSets.ErrorsAndWarnings); } else { _validator.ShouldHaveValidationErrorFor(m => m.StandardId, viewModel); _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.StandardId, vacancyViewModel); _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.StandardId, vacancyViewModel, RuleSets.Errors); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.StandardId, vacancyViewModel, RuleSets.Warnings); _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.StandardId, vacancyViewModel, RuleSets.ErrorsAndWarnings); } }
public static Domain.Entities.Vacancies.TrainingType GetTrainingType(this TrainingType trainingType) { switch (trainingType) { case TrainingType.Unknown: return(Domain.Entities.Vacancies.TrainingType.Unknown); case TrainingType.Frameworks: return(Domain.Entities.Vacancies.TrainingType.Frameworks); case TrainingType.Standards: return(Domain.Entities.Vacancies.TrainingType.Standards); case TrainingType.Sectors: return(Domain.Entities.Vacancies.TrainingType.Sectors); default: throw new ArgumentException("Training Type: " + trainingType + " was not recognized"); } }
public void ShouldRequireApprenticeshipLevel(ApprenticeshipLevel apprenticeshipLevel, TrainingType trainingType, bool expectValid) { // Arrange. var viewModel = new TrainingDetailsViewModel { TrainingType = trainingType, ApprenticeshipLevel = apprenticeshipLevel }; var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).With(_furtherDetailsViewModel).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.ApprenticeshipLevel, viewModel); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.Errors); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.Warnings); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.ErrorsAndWarnings); } else { _validator.ShouldHaveValidationErrorFor(m => m.ApprenticeshipLevel, viewModel); _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel); _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.Errors); _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.Warnings); _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.ErrorsAndWarnings); } }