public void DateYearValidation(bool expectValid) { var currentYear = DateTime.UtcNow.Year; var year = expectValid ? currentYear : currentYear - 2000; //Either 20XX or XX //Arrange var view = new ValidationSummary(); var viewModel = new ModelStateDictionary(); var viewModelToValidate = new FurtherVacancyDetailsViewModel { VacancyDatesViewModel = new VacancyDatesViewModel { ClosingDate = new DateViewModel { Day = 1, Month = 2, Year = year }, PossibleStartDate = new DateViewModel { Day = 1, Month = 2, Year = year } }, Wage = new WageViewModel() { CustomType = CustomWageType.Fixed } }; var validator = new VacancySummaryViewModelServerValidator(); var results = validator.Validate(viewModelToValidate, ruleSet: RuleSets.ErrorsAndWarnings); results.AddToModelStateWithSeverity(viewModel, string.Empty); //Act var document = new ValidationSummaryDocument(view.RenderAsHtml(viewModel)); var closingDateYearError = document.Errors.FirstOrDefault(n => n.FirstChild.Attributes["href"].Value == "#vacancydatesviewmodel_closingdate_year"); var possibleStartDateError = document.Errors.FirstOrDefault(n => n.FirstChild.Attributes["href"].Value == "#vacancydatesviewmodel_possiblestartdate_year"); //Assert if (expectValid) { closingDateYearError.Should().BeNull(); possibleStartDateError.Should().BeNull(); } else { closingDateYearError.Should().NotBeNull(); possibleStartDateError.Should().NotBeNull(); } }
public VacancyMediator(IVacancyQAProvider vacancyQaProvider, VacancyViewModelValidator vacancyViewModelValidator, VacancySummaryViewModelServerValidator vacancySummaryViewModelServerValidator, NewVacancyViewModelServerValidator newVacancyViewModelServerValidator, VacancyQuestionsViewModelServerValidator vacancyQuestionsViewModelServerValidator, VacancyRequirementsProspectsViewModelServerValidator vacancyRequirementsProspectsViewModelServerValidator, VacancyOwnerRelationshipViewModelValidator vacancyOwnerRelationshipViewModelValidator, IProviderQAProvider providerQaProvider, LocationSearchViewModelServerValidator locationSearchViewModelServerValidator, ILocationsProvider locationsProvider, TrainingDetailsViewModelServerValidator trainingDetailsViewModelServerValidator) { _vacancyQaProvider = vacancyQaProvider; _vacancyViewModelValidator = vacancyViewModelValidator; _vacancySummaryViewModelServerValidator = vacancySummaryViewModelServerValidator; _newVacancyViewModelServerValidator = newVacancyViewModelServerValidator; _vacancyQuestionsViewModelServerValidator = vacancyQuestionsViewModelServerValidator; _vacancyRequirementsProspectsViewModelServerValidator = vacancyRequirementsProspectsViewModelServerValidator; _vacancyOwnerRelationshipViewModelValidator = vacancyOwnerRelationshipViewModelValidator; _providerQaProvider = providerQaProvider; _locationSearchViewModelServerValidator = locationSearchViewModelServerValidator; _locationsProvider = locationsProvider; _trainingDetailsViewModelServerValidator = trainingDetailsViewModelServerValidator; }
public void SetUp() { _validator = new VacancySummaryViewModelServerValidator(); _aggregateValidator = new VacancyViewModelValidator(); }