Пример #1
0
        public void ClosingDateAndPossibleStartNotAValidDateNoException()
        {
            var viewModel = new VacancyDatesViewModel
            {
                ClosingDate = new DateViewModel
                {
                    Day   = 31,
                    Month = 2,
                    Year  = 2015
                },
                PossibleStartDate = new DateViewModel
                {
                    Day   = 31,
                    Month = 2,
                    Year  = 2015
                }
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).With(_wageViewModel).Build();

            _serverWarningValidator.Validate(viewModel, ruleSet: RuleSet);
            _aggregateValidator.Validate(vacancyViewModel);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSet);

            _serverWarningValidator.ShouldNotHaveValidationErrorFor(vm => vm.ClosingDate, viewModel, RuleSet);
            _serverWarningValidator.ShouldNotHaveValidationErrorFor(vm => vm.PossibleStartDate, viewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel, RuleSet);
        }
        public void ClosingDateRequired()
        {
            var datesViewModel = new VacancyDatesViewModel
            {
                ClosingDate = new DateViewModel()
            };

            var vacancyViewModel = new VacancyViewModelBuilder().With(_wageViewModel).With(datesViewModel).Build();

            _serverCommonValidator.Validate(datesViewModel, ruleSet: RuleSet);

            _vacancyValidator.Validate(vacancyViewModel);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Errors);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Warnings);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.ErrorsAndWarnings);

            _serverValidator.Validate(datesViewModel, ruleSet: RuleSet);

            _serverCommonValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, datesViewModel);

            _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel);

            _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSets.Errors);

            _vacancyValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSets.Warnings);

            _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSets.ErrorsAndWarnings);

            _serverValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, datesViewModel);
            _serverValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, datesViewModel, RuleSets.Errors);
            _serverValidator.ShouldNotHaveValidationErrorFor(vm => vm.ClosingDate, datesViewModel, RuleSets.Warnings);
            _serverValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, datesViewModel, RuleSets.ErrorsAndWarnings);
        }
        public void PossibleStartDateCommentShouldNotAllowInvalidCharacters()
        {
            var viewModel = new VacancyDatesViewModel
            {
                PossibleStartDateComment = "<script>"
            };

            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).With(_wageViewModel).Build();

            _commonValidator.Validate(viewModel, ruleSet: RuleSet);

            _vacancyValidator.Validate(vacancyViewModel);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Errors);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Warnings);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.ErrorsAndWarnings);

            _commonValidator.ShouldHaveValidationErrorFor(vm => vm.PossibleStartDateComment, viewModel, RuleSet);

            _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDateComment, vacancyViewModel);

            _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDateComment, vacancyViewModel, RuleSets.Errors);

            _vacancyValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDateComment, vacancyViewModel, RuleSets.Warnings);

            _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDateComment, vacancyViewModel, RuleSets.ErrorsAndWarnings);
        }
        public void ClosingDateYearFormat(bool expectValid)
        {
            var currentYear = DateTime.UtcNow.Year;
            var year        = expectValid ? currentYear : currentYear - 2000; //Either 20XX or XX

            var viewModel = new VacancyDatesViewModel
            {
                ClosingDate = new DateViewModel
                {
                    Year = year
                }
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(_wageViewModel).With(viewModel).Build();

            _serverCommonValidator.Validate(viewModel, ruleSet: RuleSet);

            _vacancyValidator.Validate(vacancyViewModel);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Errors);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Warnings);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.ErrorsAndWarnings);

            _serverValidator.Validate(viewModel, ruleSet: RuleSet);

            if (expectValid)
            {
                _serverCommonValidator.ShouldNotHaveValidationErrorFor(vm => vm.ClosingDate, vm => vm.ClosingDate.Year, viewModel, RuleSet);

                _vacancyValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate.Year, vacancyViewModel);

                _vacancyValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate.Year, vacancyViewModel, RuleSets.Errors);

                _vacancyValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate.Year, vacancyViewModel, RuleSets.Warnings);

                _vacancyValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate.Year, vacancyViewModel, RuleSets.ErrorsAndWarnings);

                _serverValidator.ShouldNotHaveValidationErrorFor(vm => vm.ClosingDate.Year, viewModel);
                _serverValidator.ShouldNotHaveValidationErrorFor(vm => vm.ClosingDate.Year, viewModel, RuleSets.Errors);
                _serverValidator.ShouldNotHaveValidationErrorFor(vm => vm.ClosingDate.Year, viewModel, RuleSets.Warnings);
                _serverValidator.ShouldNotHaveValidationErrorFor(vm => vm.ClosingDate.Year, viewModel, RuleSets.ErrorsAndWarnings);
            }
            else
            {
                _serverCommonValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, vm => vm.ClosingDate.Year, viewModel, RuleSet);

                _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate.Year, vacancyViewModel);

                _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate.Year, vacancyViewModel, RuleSets.Errors);

                _vacancyValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate.Year, vacancyViewModel, RuleSets.Warnings);

                _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate.Year, vacancyViewModel, RuleSets.ErrorsAndWarnings);

                _serverValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, vm => vm.ClosingDate.Year, viewModel);
                _serverValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, vm => vm.ClosingDate.Year, viewModel, RuleSets.Errors);
                _serverValidator.ShouldNotHaveValidationErrorFor(vm => vm.ClosingDate, vm => vm.ClosingDate.Year, viewModel, RuleSets.Warnings);
                _serverValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, vm => vm.ClosingDate.Year, viewModel, RuleSets.ErrorsAndWarnings);
            }
        }
        public void ServerValidatorDefaultShouldHaveValidationErrors()
        {
            var datesViewModel = new VacancyDatesViewModel();

            var result = _serverValidator.Validate(datesViewModel, ruleSet: RuleSet);

            result.IsValid.Should().BeFalse();
            result.Errors.Count.Should().Be(2);
        }
        public void CommonValidatorDefaultShouldNotHaveValidationErrors()
        {
            var datesViewModel = new VacancyDatesViewModel();

            var result = _commonValidator.Validate(datesViewModel, ruleSet: RuleSet);

            result.IsValid.Should().BeTrue();
            result.Errors.Count.Should().Be(0);
        }
        public void VacancyViewModelValidatorDefaultShouldHaveMultipleValidationErrors()
        {
            var datesViewModel   = new VacancyDatesViewModel();
            var vacancyViewModel = new VacancyViewModelBuilder().With(datesViewModel).With(_wageViewModel).Build();

            var result = _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSet);

            result.IsValid.Should().BeFalse();
            result.Errors.Count.Should().BeGreaterThan(1);
        }
        public static WageRange GetWageRangeForPossibleStartDate(this VacancyDatesViewModel vacancyDatesViewModel, out DateTime possibleStartDate)
        {
            var wageRange = Wages.Ranges.Last();

            possibleStartDate = wageRange.ValidFrom;
            if (vacancyDatesViewModel != null && vacancyDatesViewModel.PossibleStartDate.HasValue)
            {
                possibleStartDate = vacancyDatesViewModel.PossibleStartDate.Date;
                wageRange         = Wages.GetWageRangeFor(possibleStartDate);
            }
            return(wageRange);
        }
Пример #9
0
        public void ClosingDateDateMustBeTwoWeeksInTheFutureWarning()
        {
            var viewModel = new VacancyDatesViewModel
            {
                ClosingDate = new DateViewModel(DateTime.Today.AddDays(13))
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).With(_wageViewModel).Build();

            _serverWarningValidator.Validate(viewModel, ruleSet: RuleSet);
            _aggregateValidator.Validate(vacancyViewModel);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSet);

            _serverWarningValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, viewModel, RuleSet);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSet);
        }
Пример #10
0
        public void PossibleStartDateInThePastWarning()
        {
            var viewModel = new VacancyDatesViewModel
            {
                PossibleStartDate = new DateViewModel(DateTime.Today.AddDays(-7))
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).With(_wageViewModel).Build();

            _serverWarningValidator.Validate(viewModel, ruleSet: RuleSet);
            _aggregateValidator.Validate(vacancyViewModel);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSet);

            _serverWarningValidator.ShouldHaveValidationErrorFor(vm => vm.PossibleStartDate, viewModel, RuleSet);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel, RuleSet);
        }
        public void ClosingDateMustBeAValidDateRequired()
        {
            var viewModel = new VacancyDatesViewModel
            {
                // VacancyStatus = VacancyStatus.Live,
                ClosingDate = new DateViewModel
                {
                    Day   = 31,
                    Month = 11,
                    Year  = 2015
                }
            };

            var vacancyViewModel = new VacancyViewModelBuilder().With(_wageViewModel).With(viewModel).Build();

            _serverCommonValidator.Validate(viewModel, ruleSet: RuleSet);

            _vacancyValidator.Validate(vacancyViewModel);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Errors);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Warnings);
            _vacancyValidator.Validate(vacancyViewModel, ruleSet: RuleSets.ErrorsAndWarnings);

            _serverValidator.Validate(viewModel, ruleSet: RuleSet);

            _serverCommonValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, viewModel);

            _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel);

            _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSets.Errors);

            _vacancyValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSets.Warnings);

            _vacancyValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSets.ErrorsAndWarnings);

            _serverValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, viewModel);
            _serverValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, viewModel, RuleSets.Errors);
            _serverValidator.ShouldNotHaveValidationErrorFor(vm => vm.ClosingDate, viewModel, RuleSets.Warnings);
            _serverValidator.ShouldHaveValidationErrorFor(vm => vm.ClosingDate, viewModel, RuleSets.ErrorsAndWarnings);
        }
Пример #12
0
        public void PossibleStartDateLessThanTwoWeeks()
        {
            var today = DateTime.Today;

            var viewModel = new VacancyDatesViewModel
            {
                PossibleStartDate = new DateViewModel(today)
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).With(_wageViewModel).Build();

            var result = _serverWarningValidator.Validate(viewModel, ruleSet: RuleSet);

            _aggregateValidator.Validate(vacancyViewModel);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSet);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.ErrorsAndWarnings);

            _serverWarningValidator.ShouldHaveValidationErrorFor(vm => vm.PossibleStartDate, viewModel, RuleSet);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel, RuleSet);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel, RuleSets.ErrorsAndWarnings);
            result.IsValid.Should().BeFalse();
            result.Errors.Count.Should().Be(1);
        }
        public static ValidationFailure PossibleStartDateShouldBeAfterClosingDate(this VacancyDatesViewModel viewModel, DateViewModel closingDate, string parentPropertyName)
        {
            if (closingDate == null || !closingDate.HasValue || viewModel.PossibleStartDate == null || !viewModel.PossibleStartDate.HasValue || !Common.BeValidDate(closingDate) || !Common.BeValidDate(viewModel.PossibleStartDate))
            {
                return(null);
            }

            if (viewModel.PossibleStartDate.Date <= closingDate.Date)
            {
                var propertyName = "PossibleStartDate";
                if (!string.IsNullOrEmpty(parentPropertyName))
                {
                    propertyName = parentPropertyName + "." + propertyName;
                }
                var validationFailure = new ValidationFailure(propertyName, VacancyViewModelMessages.PossibleStartDate.BeforePublishDateErrorText)
                {
                    CustomState = ValidationType.Warning
                };
                return(validationFailure);
            }

            return(null);
        }
Пример #14
0
 private static bool IsNewVacancy(VacancyDatesViewModel x)
 {
     return(!(x.VacancyStatus == VacancyStatus.Live || x.VacancyStatus == VacancyStatus.Closed));
 }
Пример #15
0
 public VacancyViewModelBuilder With(VacancyDatesViewModel vacancyDatesViewModel)
 {
     _vacancyDatesViewModel = vacancyDatesViewModel;
     _furtherVacancyDetailsViewModel.VacancyDatesViewModel = vacancyDatesViewModel;
     return(this);
 }