public void TraineeshipDuration(int expectedDuration, DurationType durationType, bool expectValid)
        {
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Duration      = expectedDuration,
                DurationType  = durationType,
                VacancyType   = VacancyType.Traineeship,
                VacancySource = VacancySource.Raa,
                Wage          = new WageViewModel()
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

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

            if (expectValid)
            {
                _validator.ShouldNotHaveValidationErrorFor(vm => vm.Duration, viewModel, RuleSet);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Duration, vacancyViewModel);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Duration, vacancyViewModel, RuleSet);
            }
            else
            {
                _validator.ShouldHaveValidationErrorFor(vm => vm.Duration, viewModel, RuleSet);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Duration, vacancyViewModel);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Duration, vacancyViewModel, RuleSet);
            }
        }
Пример #2
0
        public void ShouldReturnAWarningHashIfTheModelHasOnlyWarnings()
        {
            const int vacancyReferenceNumber = 1;

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel()
                {
                    Type = WageType.NationalMinimum, Classification = WageClassification.NationalMinimum, CustomType = CustomWageType.NotApplicable, Amount = null, AmountLowerBound = null, AmountUpperBound = null, Text = null, Unit = WageUnit.Weekly, HoursPerWeek = 30
                },
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(DateTime.Now.AddDays(7)),
                    PossibleStartDate = new DateViewModel(DateTime.Now.AddDays(7))
                }
            };

            VacancyPostingProvider.Setup(p => p.GetVacancySummaryViewModel(vacancyReferenceNumber)).Returns(viewModel);
            var mediator = GetMediator();

            var result = mediator.GetVacancySummaryViewModel(vacancyReferenceNumber, true, false);

            result.Code.Should().Be(VacancyPostingMediatorCodes.GetVacancySummaryViewModel.FailedValidation);
            result.ViewModel.WarningsHash.Should().NotBe(0);
            result.ViewModel.Should().Be(viewModel);
        }
        public void RuleTwo_HoursPerWeek30to40_And_DurationLessThan12months(decimal hoursPerWeek, int expectedDuration, DurationType durationType)
        {
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel()
                {
                    HoursPerWeek = hoursPerWeek
                },
                Duration      = expectedDuration,
                DurationType  = durationType,
                VacancySource = VacancySource.Raa
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

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

            _validator.ShouldNotHaveValidationErrorFor(vm => vm.Wage, vm => vm.Wage.HoursPerWeek, viewModel, RuleSet);
            _validator.ShouldHaveValidationErrorFor(vm => vm.Duration, viewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.HoursPerWeek, vacancyViewModel);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.HoursPerWeek, vacancyViewModel, RuleSet);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Duration, vacancyViewModel);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Duration, vacancyViewModel, RuleSet);
        }
        public static FurtherVacancyDetailsViewModel ConvertToVacancySummaryViewModel(this Vacancy vacancy)
        {
            var vacancyViewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyReferenceNumber = vacancy.VacancyReferenceNumber,
                WorkingWeek            = vacancy.WorkingWeek,
                //this is set via automapper
                //Wage = new WageViewModel(vacancy.Wage),
                WageUnits             = GetWageUnits(),
                WageTextPresets       = GetWageTextPresets(),
                DurationType          = vacancy.DurationType,
                DurationTypes         = GetDurationTypes(vacancy.VacancyType),
                Duration              = vacancy.Duration,
                ExpectedDuration      = vacancy.ExpectedDuration,
                Status                = vacancy.Status,
                VacancyDatesViewModel = new VacancyDatesViewModel {
                    ClosingDate              = new DateViewModel(vacancy.ClosingDate),
                    PossibleStartDate        = new DateViewModel(vacancy.PossibleStartDate),
                    ClosingDateComment       = vacancy.ClosingDateComment,
                    PossibleStartDateComment = vacancy.PossibleStartDateComment,
                    VacancyStatus            = vacancy.Status
                },
                LongDescription        = vacancy.LongDescription,
                WageComment            = vacancy.WageComment,
                DurationComment        = vacancy.DurationComment,
                LongDescriptionComment = vacancy.LongDescriptionComment,
                WorkingWeekComment     = vacancy.WorkingWeekComment,
                VacancyType            = vacancy.VacancyType,
                VacancySource          = vacancy.VacancySource
            };

            return(vacancyViewModel);
        }
        public void RuleFour_HoursPerWeek16to30_And_DurationGreaterThanOrEqualTo12months_And_ExpectedDurationNotGreaterThanOrEqualToMinimumDuration(decimal hoursPerWeek, int expectedDuration, DurationType durationType)
        {
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel()
                {
                    HoursPerWeek = hoursPerWeek
                },
                Duration     = expectedDuration,
                DurationType = durationType
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

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

            //Assert. This rule will be a warning rather than being mandatory and so is not implemented by the VacancySummaryViewModelServerValidator
            _validator.ShouldNotHaveValidationErrorFor(vm => vm.Wage, vm => vm.Wage.HoursPerWeek, viewModel, RuleSet);
            _validator.ShouldNotHaveValidationErrorFor(vm => vm.Duration, viewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.HoursPerWeek, vacancyViewModel);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.HoursPerWeek, vacancyViewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Duration, vacancyViewModel);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Duration, vacancyViewModel, RuleSet);
        }
Пример #6
0
        public void ClosingDateLessThanTwoWeeksAway_PossibleStartDateBeforeClosingDate()
        {
            var today = DateTime.Today;

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(today.AddDays(13)),
                    PossibleStartDate = new DateViewModel(today.AddDays(12))
                },
                Wage = new WageViewModel()
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

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

            //Assert. This rule will be a warning rather than being mandatory and so is not implemented by the VacancySummaryViewModelServerValidator
            _validator.ShouldNotHaveValidationErrorFor(vm => vm.VacancyDatesViewModel.ClosingDate, viewModel, RuleSet);
            _validator.ShouldNotHaveValidationErrorFor(vm => vm.VacancyDatesViewModel.PossibleStartDate, viewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel, RuleSet);
        }
        public ActionResult Summary(FurtherVacancyDetailsViewModel viewModel)
        {
            var response = _vacancyMediator.UpdateVacancy(viewModel);

            ModelState.Clear();

            switch (response.Code)
            {
            case VacancyMediatorCodes.UpdateVacancy.FailedValidation:
                response.ValidationResult.AddToModelStateWithSeverity(ModelState, string.Empty);
                return(View(response.ViewModel));

            case VacancyMediatorCodes.UpdateVacancy.Ok:
                return(RedirectToRoute(ManagementRouteNames.ReviewVacancy,
                                       new
                {
                    vacancyReferenceNumber = response.ViewModel.VacancyReferenceNumber
                }));

            case VacancyMediatorCodes.UpdateVacancy.InvalidVacancy:
                SetUserMessage(response.Message);
                return(RedirectToRoute(ManagementRouteNames.Dashboard));

            default:
                throw new InvalidMediatorCodeException(response.Code);
            }
        }
Пример #8
0
        public void ShouldUpdateWage()
        {
            //Arrange.
            const int vacancyReferenceNumber = 1;
            var       closingDate            = DateTime.Today.AddDays(20);
            var       possibleStartDate      = DateTime.Today.AddDays(30);

            var wageViewModel = new WageViewModel()
            {
                Type             = WageType.Custom,
                CustomType       = CustomWageType.Fixed,
                Amount           = 450,
                AmountLowerBound = null,
                AmountUpperBound = null,
                Text             = null,
                Unit             = WageUnit.Monthly,
                HoursPerWeek     = 37.5m
            };
            var wage = new Wage(WageType.Custom, 450, null, null, null, WageUnit.Monthly, 37.5m, null);

            var updatedViewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(closingDate),
                    PossibleStartDate = new DateViewModel(possibleStartDate)
                },
                VacancyReferenceNumber = vacancyReferenceNumber,
                Wage = wageViewModel
            };

            var dbApprenticeshipVacancy = new Vacancy
            {
                VacancyReferenceNumber = vacancyReferenceNumber,
                Wage = new Wage(WageType.NationalMinimum, null, null, null, "Legacy text", WageUnit.Weekly, 30, null)
            };

            MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(vacancyReferenceNumber))
            .Returns(dbApprenticeshipVacancy);
            MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>()))
            .Returns(dbApprenticeshipVacancy);
            MockMapper.Setup(m => m.Map <WageViewModel, Wage>(It.IsAny <WageViewModel>())).Returns(wage);
            MockMapper.Setup(m => m.Map <Wage, WageViewModel>(It.IsAny <Wage>())).Returns(wageViewModel); //this line kind of invalidates this test.
            MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(dbApprenticeshipVacancy))
            .Returns(updatedViewModel);

            var provider = GetVacancyPostingProvider();

            //Act.
            provider.UpdateVacancyDates(updatedViewModel);

            //Assert.
            MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>(
                                                                      v => v.PossibleStartDate == possibleStartDate &&
                                                                      v.Wage.Type == updatedViewModel.Wage.Type &&
                                                                      v.Wage.Amount == updatedViewModel.Wage.Amount &&
                                                                      v.Wage.Text == dbApprenticeshipVacancy.Wage.Text &&
                                                                      v.Wage.Unit == updatedViewModel.Wage.Unit &&
                                                                      v.Wage.HoursPerWeek == dbApprenticeshipVacancy.Wage.HoursPerWeek)));
        }
Пример #9
0
        public void ClosingDateTwoWeeksAway_PossibleStartDateAfterClosingDate()
        {
            var today = DateTime.Today;

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(today.AddDays(14)),
                    PossibleStartDate = new DateViewModel(today.AddDays(15))
                },
                Wage = new WageViewModel()
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

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

            _validator.ShouldNotHaveValidationErrorFor(vm => vm.VacancyDatesViewModel.ClosingDate, viewModel, RuleSet);
            _validator.ShouldNotHaveValidationErrorFor(vm => vm.VacancyDatesViewModel.PossibleStartDate, viewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel, RuleSet);
        }
        public void ShouldReturnOkIfThereIsntAnyValidationError()
        {
            var vacancyReferenceNumber = 1;

            var closingDate = DateTime.Now;

            var apprenticeshipVacancy = new Vacancy
            {
                VacancyReferenceNumber = vacancyReferenceNumber,
                Wage = new Wage(WageType.NationalMinimum, null, null, null, null, WageUnit.Weekly, 30, null)
            };

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel(),
                VacancyReferenceNumber = vacancyReferenceNumber,
                VacancyDatesViewModel  = new VacancyDatesViewModel
                {
                    ClosingDate = new DateViewModel(closingDate)
                },
            };

            MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(vacancyReferenceNumber))
            .Returns(apprenticeshipVacancy);
            MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>()))
            .Returns(apprenticeshipVacancy);
            MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(apprenticeshipVacancy))
            .Returns(viewModel);

            var provider = GetVacancyPostingProvider();

            provider.CloseVacancy(viewModel);
            MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>(v => v.Status == VacancyStatus.Closed)));
        }
Пример #11
0
        public void RuleFour_HoursPerWeek16to30_And_DurationGreaterThanOrEqualTo12months_And_ExpectedDurationLessThanMinimumDuration(decimal hoursPerWeek, int expectedDuration, DurationType durationType, string expectedMessage)
        {
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel()
                {
                    HoursPerWeek = hoursPerWeek
                },
                Duration     = expectedDuration,
                DurationType = durationType
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

            var response = _validator.Validate(viewModel, ruleSet: RuleSet);

            _aggregateValidator.Validate(vacancyViewModel);
            var aggregateResponse = _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSet);

            _validator.ShouldNotHaveValidationErrorFor(vm => vm.Wage, vm => vm.Wage.HoursPerWeek, viewModel, RuleSet);
            _validator.ShouldHaveValidationErrorFor(vm => vm.Duration, viewModel, RuleSet);
            _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.HoursPerWeek, vacancyViewModel, RuleSet);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Duration, vacancyViewModel, RuleSet);
            var error = response.Errors.SingleOrDefault(e => e.PropertyName == "Duration");

            error.Should().NotBeNull();
            error?.ErrorMessage.Should().Be(expectedMessage);
            var aggregateError = aggregateResponse.Errors.SingleOrDefault(e => e.PropertyName == "FurtherVacancyDetailsViewModel.Duration");

            aggregateError.Should().NotBeNull();
            aggregateError?.ErrorMessage.Should().Be(expectedMessage);
        }
        public void ClosingDateWarnings()
        {
            //Arrange
            var yesterday = DateTime.Today.AddDays(-1);

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(yesterday),
                    PossibleStartDate = new DateViewModel(yesterday)
                },
                Wage = new WageViewModel()
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

            VacancyPostingProvider.Setup(p => p.GetVacancy(It.IsAny <int>())).Returns(vacancyViewModel);
            var mediator = GetMediator();

            //Act
            var result = mediator.GetPreviewVacancyViewModel(0);

            //Assert
            result.Code.Should().Be(VacancyPostingMediatorCodes.GetPreviewVacancyViewModel.FailedValidation);
            result.ValidationResult.Errors.Count(e => e.PropertyName == "FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate").Should().Be(2);
            result.ValidationResult.Errors.Count(e => e.PropertyName == "FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate").Should().Be(2);
        }
Пример #13
0
        public void ShouldNotUpdateTheVacancyIfWeAcceptTheWarningsButTheyAreDifferentFromThePreviousOnes()
        {
            const int vacancyReferenceNumber = 1;
            const int oldWarningHash         = -1011218820;

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel()
                {
                    Type = WageType.NationalMinimum, Classification = WageClassification.NationalMinimum, CustomType = CustomWageType.NotApplicable, Amount = null, AmountLowerBound = null, AmountUpperBound = null, Text = null, Unit = WageUnit.NotApplicable, HoursPerWeek = null
                },
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(DateTime.Now.AddDays(20)),
                    PossibleStartDate = new DateViewModel(DateTime.Now.AddDays(20))
                },
                VacancyReferenceNumber = vacancyReferenceNumber,
                WarningsHash           = oldWarningHash
            };

            var mediator = GetMediator();

            var result = mediator.UpdateVacancyDates(viewModel, true);

            result.Code.Should().Be(VacancyPostingMediatorCodes.ManageDates.FailedValidation);
        }
Пример #14
0
        public static ValidationFailure HaveAValidHourRate(this FurtherVacancyDetailsViewModel viewModel, decimal?amount, string parentPropertyName, string nameOfTestedProperty)
        {
            var unitToMeasure = viewModel.Wage.CustomType == CustomWageType.Ranged
                ? viewModel.Wage.RangeUnit
                : viewModel.Wage.Unit;
            var unitPrecondition = unitToMeasure != WageUnit.NotApplicable;

            if (amount.HasValue && viewModel.Wage.Classification == WageClassification.Custom && unitPrecondition && viewModel.Wage.HoursPerWeek.HasValue && viewModel.Wage.HoursPerWeek > 0)
            {
                var hourRate = GetHourRate(amount.Value, unitToMeasure, viewModel.Wage.HoursPerWeek.Value);

                DateTime possibleStartDate;
                var      wageRange = viewModel.VacancyDatesViewModel.GetWageRangeForPossibleStartDate(out possibleStartDate);

                if (hourRate < wageRange.ApprenticeMinimumWage)
                {
                    var propertyName = nameOfTestedProperty;
                    if (!string.IsNullOrEmpty(parentPropertyName))
                    {
                        propertyName = parentPropertyName + "." + propertyName;
                    }

                    var validationFailure = new ValidationFailure(propertyName, wageRange.ValidationErrorMessage, amount);
                    return(validationFailure);
                }
            }

            return(null);
        }
 public void SetUp()
 {
     _validator               = new NewVacancyViewModelServerValidator();
     _aggregateValidator      = new VacancyViewModelValidator();
     _furtherDetailsViewModel = new FurtherVacancyDetailsViewModel()
     {
         Wage = new WageViewModel()
     };
 }
        public void DefaultShouldNotHaveAnyValidationErrors()
        {
            var viewModel = new FurtherVacancyDetailsViewModel()
            {
                Wage = new WageViewModel()
            };

            var result = _validator.Validate(viewModel);

            result.IsValid.Should().BeTrue();
        }
        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();
            }
        }
Пример #18
0
        public void ClosingDateCanBeTodayIfLive(VacancyStatus vacancyStatus, bool expectValid)
        {
            var today = DateTime.Today;

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate   = new DateViewModel(today),
                    VacancyStatus = vacancyStatus
                },
                Wage = new WageViewModel()
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

            var response = _validator.Validate(viewModel, ruleSet: RuleSet);

            _aggregateValidator.Validate(vacancyViewModel);
            var aggregateResponse = _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSet);

            if (expectValid)
            {
                _validator.ShouldNotHaveValidationErrorFor(vm => vm.VacancyDatesViewModel,
                                                           vm => vm.VacancyDatesViewModel.ClosingDate, viewModel, RuleSet);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel,
                                                                    vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel,
                                                                    vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel,
                                                                    vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel,
                                                                    vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSet);
            }
            else
            {
                _validator.ShouldHaveValidationErrorFor(vm => vm.VacancyDatesViewModel,
                                                        vm => vm.VacancyDatesViewModel.ClosingDate, viewModel, RuleSet);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel,
                                                                 vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel,
                                                                 vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel,
                                                                 vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel,
                                                                 vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSet);

                var error = response.Errors.SingleOrDefault(e => e.PropertyName == "VacancyDatesViewModel.ClosingDate");
                error.Should().NotBeNull();
                error?.ErrorMessage.Should().Be(VacancyViewModelMessages.ClosingDate.AfterTodayErrorText);
                var aggregateError = aggregateResponse.Errors.SingleOrDefault(e => e.PropertyName == "FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate");
                aggregateError.Should().NotBeNull();
                aggregateError?.ErrorMessage.Should().Be(VacancyViewModelMessages.ClosingDate.AfterTodayErrorText);
            }
        }
Пример #19
0
        public void ShouldSetVacancyApplicationStateAfterUpdate(int applicationCount, VacancyApplicationsState expectedState)
        {
            // Arrange.
            const int vacancyId = 1;
            const int vacancyReferenceNumber = 2;

            var closingDate       = DateTime.Today.AddDays(20);
            var possibleStartDate = DateTime.Today.AddDays(30);

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel(),
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(closingDate),
                    PossibleStartDate = new DateViewModel(possibleStartDate)
                },
                VacancyReferenceNumber = vacancyReferenceNumber
            };

            var vacancy = new Vacancy
            {
                VacancyId = vacancyId,
                VacancyReferenceNumber = vacancyReferenceNumber,
                Wage = new Wage(WageType.NationalMinimum, null, null, null, null, WageUnit.Weekly, 30, null)
            };

            MockVacancyPostingService.Setup(mock => mock
                                            .GetVacancyByReferenceNumber(vacancyReferenceNumber))
            .Returns(vacancy);

            MockVacancyPostingService.Setup(mock => mock
                                            .UpdateVacancy(It.IsAny <Vacancy>()))
            .Returns(vacancy);

            MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(vacancy))
            .Returns(viewModel);

            MockApprenticeshipApplicationService.Setup(mock => mock.
                                                       GetApplicationCount(vacancyId))
            .Returns(applicationCount);

            var provider = GetVacancyPostingProvider();

            // Act.
            var result = provider.UpdateVacancyDates(viewModel);

            // Assert.
            result.VacancyApplicationsState.Should().Be(expectedState);
        }
Пример #20
0
        public static bool DurationBetweenSixWeeksAndSixMonths(this FurtherVacancyDetailsViewModel viewModel)
        {
            switch (viewModel.DurationType)
            {
            case DurationType.Weeks:
                return(viewModel.Duration >= 6 && viewModel.Duration <= SixMonthsInWeeks);

            case DurationType.Months:
                return(viewModel.Duration >= 2 && viewModel.Duration <= 6);

            default:
                return(false);
            }
        }
        public void ShouldShowSaveAndExitButton()
        {
            var details = new VacancySummary();

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                WageUnits       = ApprenticeshipVacancyConverter.GetWageUnits(),
                WageTextPresets = ApprenticeshipVacancyConverter.GetWageTextPresets(),
                DurationTypes   = ApprenticeshipVacancyConverter.GetDurationTypes(VacancyType.Apprenticeship)
            };

            var view = details.RenderAsHtml(viewModel);

            view.GetElementbyId("vacancySummaryAndExit").Should().NotBeNull("Should exists a save and exit button");
        }
Пример #22
0
        public void DateCannotBeYesterday(VacancyStatus vacancyStatus, string expectedMessage)
        {
            var yesterday = DateTime.Today.AddDays(-1);

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(yesterday),
                    PossibleStartDate = new DateViewModel(yesterday),
                    VacancyStatus     = vacancyStatus
                },
                Wage = new WageViewModel()
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

            var response = _validator.Validate(viewModel, ruleSet: RuleSet);

            _aggregateValidator.Validate(vacancyViewModel);
            var aggregateResponse = _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSet);

            _validator.ShouldHaveValidationErrorFor(vm => vm.VacancyDatesViewModel, vm => vm.VacancyDatesViewModel.ClosingDate, viewModel, RuleSet);
            _validator.ShouldHaveValidationErrorFor(vm => vm.VacancyDatesViewModel, vm => vm.VacancyDatesViewModel.PossibleStartDate, viewModel, RuleSet);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate, vacancyViewModel, RuleSet);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel, vm => vm.FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate, vacancyViewModel, RuleSet);

            var closingDateError = response.Errors.SingleOrDefault(e => e.PropertyName == "VacancyDatesViewModel.ClosingDate");

            closingDateError.Should().NotBeNull();
            closingDateError?.ErrorMessage.Should().Be(expectedMessage);
            var closingDateAggregateError = aggregateResponse.Errors.SingleOrDefault(e => e.PropertyName == "FurtherVacancyDetailsViewModel.VacancyDatesViewModel.ClosingDate");

            closingDateAggregateError.Should().NotBeNull();
            closingDateAggregateError?.ErrorMessage.Should().Be(expectedMessage);

            var possibleStartDateError = response.Errors.SingleOrDefault(e => e.PropertyName == "VacancyDatesViewModel.PossibleStartDate");

            possibleStartDateError.Should().NotBeNull();
            possibleStartDateError?.ErrorMessage.Should().Be(VacancyViewModelMessages.PossibleStartDate.AfterTodayErrorText);
            var possibleStartDateAggregateError = aggregateResponse.Errors.SingleOrDefault(e => e.PropertyName == "FurtherVacancyDetailsViewModel.VacancyDatesViewModel.PossibleStartDate");

            possibleStartDateAggregateError.Should().NotBeNull();
            possibleStartDateAggregateError?.ErrorMessage.Should().Be(VacancyViewModelMessages.PossibleStartDate.AfterTodayErrorText);
        }
Пример #23
0
        public static bool DurationGreaterThanOrEqualTo12Months(this FurtherVacancyDetailsViewModel viewModel)
        {
            switch (viewModel.DurationType)
            {
            case DurationType.Weeks:
                return(viewModel.Duration >= AYearInWeeks);

            case DurationType.Months:
                return(viewModel.Duration >= AYearInMonths);

            case DurationType.Years:
                return(viewModel.Duration >= 1);

            default:
                return(false);
            }
        }
        private static bool HaveAValidApprenticeshipDuration(FurtherVacancyDetailsViewModel furtherVacancy, decimal?duration)
        {
            if (!furtherVacancy.Wage.HoursPerWeek.HasValue || !furtherVacancy.Duration.HasValue)
            {
                return(true);
            }

            if (duration.HasValue && duration.Value % 1 != 0)
            {
                return(false);
            }

            if (furtherVacancy.HoursPerWeekBetween30And40() || furtherVacancy.HoursPerWeekGreaterThanOrEqualTo16())
            {
                return(furtherVacancy.DurationGreaterThanOrEqualTo12Months());
            }

            return(true);
        }
        public void LongDescriptionInvalidCharacters(string longDescription, bool expectValid)
        {
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage            = new WageViewModel(),
                LongDescription = longDescription
            };

            _validator.Validate(viewModel);

            if (expectValid)
            {
                _validator.ShouldNotHaveValidationErrorFor(vm => vm.LongDescription, viewModel);
            }
            else
            {
                _validator.ShouldHaveValidationErrorFor(vm => vm.LongDescription, viewModel);
            }
        }
        public void RuleSix_HoursPerWeekLessThan16OrGreaterThan40(decimal hoursPerWeek)
        {
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel()
                {
                    HoursPerWeek = hoursPerWeek
                }
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

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

            _validator.ShouldHaveValidationErrorFor(vm => vm.Wage, vm => vm.Wage.HoursPerWeek, viewModel, RuleSet);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.HoursPerWeek, vacancyViewModel);
            _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.HoursPerWeek, vacancyViewModel, RuleSet);
        }
        private static bool HaveAValidTraineeshipDuration(FurtherVacancyDetailsViewModel furtherVacancy, decimal?duration)
        {
            if (!furtherVacancy.Duration.HasValue)
            {
                return(true);
            }

            if (furtherVacancy.DurationType == DurationType.Years)
            {
                return(false);
            }

            if (duration.HasValue && duration.Value % 1 != 0)
            {
                return(false);
            }

            return(furtherVacancy.DurationBetweenSixWeeksAndSixMonths());
        }
        public void WorkingWeekLength(string workingWeek, bool expectValid)
        {
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage        = new WageViewModel(),
                WorkingWeek = workingWeek
            };

            _validator.Validate(viewModel);

            if (expectValid)
            {
                _validator.ShouldNotHaveValidationErrorFor(vm => vm.WorkingWeek, viewModel);
            }
            else
            {
                _validator.ShouldHaveValidationErrorFor(vm => vm.WorkingWeek, viewModel);
            }
        }
Пример #29
0
        public void FailedMinimumWageValidation()
        {
            var closingDate           = DateTime.Now.AddDays(7);
            var minimumWageChangeDate = new DateTime(2016, 10, 1);

            if (closingDate < minimumWageChangeDate)
            {
                closingDate = minimumWageChangeDate;
            }

            var viewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(closingDate),
                    PossibleStartDate = new DateViewModel(closingDate.AddDays(7))
                }
            };

            var existingViewModel = new VacancyViewModelBuilder().BuildValid(VacancyStatus.Live, VacancyType.Apprenticeship).FurtherVacancyDetailsViewModel;

            existingViewModel.ComeFromPreview = false;
            //Invalid after Sept 30th
            existingViewModel.Wage.Type           = WageType.Custom;
            existingViewModel.Wage.Classification = WageClassification.Custom;
            existingViewModel.Wage.CustomType     = CustomWageType.Fixed;
            existingViewModel.Wage.Amount         = 99;
            existingViewModel.Wage.Unit           = WageUnit.Weekly;
            existingViewModel.Wage.HoursPerWeek   = 30;

            VacancyPostingProvider.Setup(p => p.GetVacancySummaryViewModel(It.IsAny <int>())).Returns(existingViewModel);

            var mediator = GetMediator();

            var result = mediator.UpdateVacancyDates(viewModel, false);

            result.ViewModel.ComeFromPreview.Should().BeTrue();
            result.Code.Should().Be(VacancyPostingMediatorCodes.ManageDates.FailedCrossFieldValidation);
            result.Message.Level.Should().Be(UserMessageLevel.Warning);
            result.Message.Text.Should().Be(VacancyViewModelMessages.FailedCrossFieldValidation);
        }
        [TestCase(2652, WageUnit.Annually, 15, true)]    //3.40 pounds per hour
        public void ApprenticeMinimumWage_PerHour_AfterOctFirst2016(decimal wage, WageUnit wageUnit, decimal hoursPerWeek, bool expectValid)
        {
            //After 1st of october 2016 the National Minimum Wage for Apprentices increases to £3.40/hour
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                Wage = new WageViewModel()
                {
                    Classification = WageClassification.Custom, CustomType = CustomWageType.Fixed, Amount = wage, Unit = wageUnit, HoursPerWeek = hoursPerWeek
                },
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    PossibleStartDate = new DateViewModel(new DateTime(2016, 10, 1))
                }
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).Build();

            var response = _validator.Validate(viewModel, ruleSet: RuleSet);

            _aggregateValidator.Validate(vacancyViewModel);
            var aggregateResponse = _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSet);

            if (expectValid)
            {
                _validator.ShouldNotHaveValidationErrorFor(vm => vm.Wage, vm => vm.Wage.Amount, viewModel, RuleSet);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.Amount, vacancyViewModel);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.Amount, vacancyViewModel, RuleSet);
            }
            else
            {
                _validator.ShouldHaveValidationErrorFor(vm => vm.Wage, vm => vm.Wage.Amount, viewModel, RuleSet);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.Amount, vacancyViewModel);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.FurtherVacancyDetailsViewModel, vm => vm.FurtherVacancyDetailsViewModel.Wage, vm => vm.FurtherVacancyDetailsViewModel.Wage.Amount, vacancyViewModel, RuleSet);

                var error = response.Errors.SingleOrDefault(e => e.PropertyName == "Wage.Amount");
                error.Should().NotBeNull();
                error?.ErrorMessage.Should().Be("The wage should not be less then the new National Minimum Wage for apprentices effective from 1 Oct 2016");
                var aggregateError = aggregateResponse.Errors.SingleOrDefault(e => e.PropertyName == "FurtherVacancyDetailsViewModel.Wage.Amount");
                aggregateError.Should().NotBeNull();
                aggregateError?.ErrorMessage.Should().Be("The wage should not be less then the new National Minimum Wage for apprentices effective from 1 Oct 2016");
            }
        }