Example #1
0
 public ApprenticeshipUploadModelValidator(IApprenticeshipValidationErrorText validationText, ICurrentDateTime currentDateTime, IUlnValidator ulnValidator, IAcademicYearDateProvider academicYearDateProvider)
 {
     _validationText           = validationText;
     _currentDateTime          = currentDateTime;
     _ulnValidator             = ulnValidator;
     _academicYearDateProvider = academicYearDateProvider;
 }
Example #2
0
 public ApprenticeshipViewModelValidator(
     IApprenticeshipValidationErrorText validationText,
     ICurrentDateTime currentDateTime,
     IAcademicYearDateProvider academicYear,
     IUlnValidator ulnValidator, IMediator mediator) : base(validationText, currentDateTime, academicYear, ulnValidator, mediator)
 {
 }
Example #3
0
        public ApprenticeshipCoreValidator(IApprenticeshipValidationErrorText validationText,
                                           IAcademicYearDateProvider academicYear,
                                           ICurrentDateTime currentDateTime, IMediator mediator)
        {
            ValidationText  = validationText;
            CurrentDateTime = currentDateTime;
            Mediator        = mediator;
            _academicYear   = academicYear;

            ValidateFirstName();

            ValidateLastName();

            ValidateUln();

            ValidateTraining();

            ValidateDateOfBirth();

            ValidateStartDate();

            ValidateEndDate();

            ValidateCost();

            ValidateEmployerReference();
        }
Example #4
0
        public AcademicYearEndExpiryProcessor(
            ILog logger,
            IAcademicYearDateProvider academicYearProvider,
            IDataLockRepository dataLockRepository,
            IApprenticeshipUpdateRepository apprenticeshipUpdateRepository,
            ICurrentDateTime currentDateTime)
        {
            if (logger == null)
            {
                throw new ArgumentException(nameof(logger));
            }
            if (dataLockRepository == null)
            {
                throw new ArgumentException(nameof(dataLockRepository));
            }
            if (currentDateTime == null)
            {
                throw new ArgumentException(nameof(currentDateTime));
            }
            if (academicYearProvider == null)
            {
                throw new ArgumentException(nameof(academicYearProvider));
            }
            if (apprenticeshipUpdateRepository == null)
            {
                throw new ArgumentException(nameof(apprenticeshipUpdateRepository));
            }


            _logger                         = logger;
            _dataLockRepository             = dataLockRepository;
            _apprenticeshipUpdateRepository = apprenticeshipUpdateRepository;
            _currentDateTime                = currentDateTime;
            _academicYearProvider           = academicYearProvider;
        }
Example #5
0
        public CreateChangeOfPartyRequestValidator(IAcademicYearDateProvider academicYearDateProvider)
        {
            _academicYearDateProvider = academicYearDateProvider;

            RuleFor(model => model.UserInfo).NotNull().WithMessage("The UserInfo cannot be empty");
            RuleFor(model => model.NewPartyId).Must(id => id > 0).WithMessage("The NewPartyId must be positive");
            RuleFor(model => model.ApprenticeshipId).Must(id => id > 0).WithMessage("The ApprenticeshipId must be positive");

            When(model => model.NewPrice.HasValue || model.NewStartDate.HasValue || model.NewEndDate.HasValue, () =>
            {
                RuleFor(model => model.NewPrice).NotNull().WithMessage("The NewPrice cannot be null if the NewStartDate or NewEndDate have values");
                RuleFor(model => model.NewStartDate).NotNull().WithMessage("The NewStartDate cannot be null if the NewPrice or NewEndDate have values");
                RuleFor(model => model.NewEndDate).NotNull().WithMessage("The NewEndDate cannot be null if the NewStartDate or NewPrice have values");
            });

            When(model => model.NewPrice.HasValue, () =>
            {
                RuleFor(model => model.NewPrice).GreaterThan(0).WithMessage("The NewPrice must be greater than 0");
                RuleFor(model => model.NewPrice).LessThanOrEqualTo(100000).WithMessage("The NewPrice must be 100000 or less");
            });

            When(model => model.NewStartDate.HasValue && model.NewEndDate.HasValue, () =>
            {
                RuleFor(model => model.NewStartDate).Must((args, value) => value.Value < args.NewEndDate)
                .WithMessage("The NewStartDate must be before the NewEndDate");

                RuleFor(model => model.NewStartDate).Must(newStartDate => newStartDate.Value <= _academicYearDateProvider.CurrentAcademicYearEndDate.AddYears(1))
                .WithMessage("The start date must be no later than one year after the end of the current teaching year");
            });
        }
Example #6
0
        public UpdateDraftApprenticeshipValidationTestsFixture WithCurrentDate(DateTime currentDate)
        {
            var utcCurrentDate = DateTime.SpecifyKind(currentDate, DateTimeKind.Utc);

            CurrentDateTime          = new CurrentDateTime(utcCurrentDate);
            AcademicYearDateProvider = new AcademicYearDateProvider(CurrentDateTime);
            return(this);
        }
Example #7
0
 public ApprovedApprenticeshipViewModelValidator(
     IApprenticeshipValidationErrorText validationText,
     IAcademicYearDateProvider academicYear,
     IAcademicYearValidator academicYearValidator,
     ICurrentDateTime currentDateTime,
     IMediator mediator)
     : base(validationText, academicYear, currentDateTime, mediator)
 {
     _academicYearValidator = academicYearValidator;
 }
Example #8
0
 public Job(
     IAcademicYearEndExpiryProcessor academicYearProcessor,
     ICurrentDateTime currentDateTime,
     IAcademicYearDateProvider academicYearProvider,
     ILog logger)
 {
     _academicYearProcessor = academicYearProcessor;
     _currentDateTime       = currentDateTime;
     _academicYearProvider  = academicYearProvider;
     _logger = logger;
     _jobId  = $"AcademicYearEnd.WebJob.{DateTime.UtcNow.Ticks}";
 }
 public EditApprenitceshipValidationService(IProviderCommitmentsDbContext context,
                                            IMediator mediator,
                                            IOverlapCheckService overlapCheckService,
                                            IReservationValidationService reservationValidationService,
                                            IAcademicYearDateProvider academicYearDateProvider,
                                            ICurrentDateTime currentDateTime)
 {
     _context                      = context;
     _overlapCheckService          = overlapCheckService;
     _reservationValidationService = reservationValidationService;
     _academicYearDateProvider     = academicYearDateProvider;
     _mediator                     = mediator;
     _currentDateTime              = currentDateTime;
 }
        public void ThenAcademicYearRunsAugustToJuly(DateTime currentDate, DateTime expectedYearStart, DateTime expectedYearEnd, DateTime expectedLastAcademicYearFundingPeriod)
        {
            //Arrange
            _currentDateTime.Setup(x => x.Now).Returns(currentDate);
            _academicYear = new Infrastructure.Services.AcademicYearDateProvider(_currentDateTime.Object);

            //Act
            var actualStart = _academicYear.CurrentAcademicYearStartDate;
            var actualEnd   = _academicYear.CurrentAcademicYearEndDate;
            var actualLastAcademicYearFundingPeriod = _academicYear.LastAcademicYearFundingPeriod;

            //Assert
            Assert.AreEqual(expectedYearStart, actualStart);
            Assert.AreEqual(expectedYearEnd, actualEnd);
            Assert.AreEqual(expectedLastAcademicYearFundingPeriod, actualLastAcademicYearFundingPeriod);
        }
 public AcademicYearEndExpiryProcessor(ILog logger,
                                       IAcademicYearDateProvider academicYearProvider,
                                       IDataLockRepository dataLockRepository,
                                       IApprenticeshipUpdateRepository apprenticeshipUpdateRepository,
                                       ICurrentDateTime currentDateTime,
                                       IMessagePublisher messagePublisher,
                                       IApprenticeshipRepository apprenticeshipRepository)
 {
     _logger                         = logger;
     _dataLockRepository             = dataLockRepository;
     _apprenticeshipUpdateRepository = apprenticeshipUpdateRepository;
     _currentDateTime                = currentDateTime;
     _messagePublisher               = messagePublisher;
     _apprenticeshipRepository       = apprenticeshipRepository;
     _academicYearProvider           = academicYearProvider;
 }
        public void ThenAcademicYearValidationShouldReturnExpectedResult(DateTime currentDate, DateTime startDate, AcademicYearValidationResult expectedResult)
        {
            //Arrange
            var yearStartDate     = new DateTime(2016, 8, 1);
            var fundingPeriodDate = new DateTime(2017, 10, 19);

            _mockCurrentDateTime.Setup(x => x.Now).Returns(currentDate);
            _academicYear = new Infrastructure.Services.AcademicYearDateProvider(_mockCurrentDateTime.Object);

            _academicYearValidator = new AcademicYearValidator(_mockCurrentDateTime.Object, _academicYear);
            //Act
            var result = _academicYearValidator.Validate(startDate);

            //Assert
            Assert.AreEqual(expectedResult, result);
        }
Example #13
0
        public UpdateDraftApprenticeshipValidationTestsFixture()
        {
            var autoFixture = new Fixture();

            UnitOfWorkContext          = new UnitOfWorkContext();
            DraftApprenticeshipDetails = new DraftApprenticeshipDetails
            {
                TrainingProgramme = new SFA.DAS.CommitmentsV2.Domain.Entities.TrainingProgramme("TEST", "TEST", ProgrammeType.Framework, DateTime.MinValue, DateTime.MaxValue)
            };
            SetupMinimumNameProperties();
            Cohort = new CommitmentsV2.Models.Cohort {
                EditStatus = EditStatus.ProviderOnly, ProviderId = 1
            };
            CurrentDateTime          = new CurrentDateTime(new DateTime(2019, 04, 01, 0, 0, 0, DateTimeKind.Utc));
            AcademicYearDateProvider = new AcademicYearDateProvider(CurrentDateTime);
            UserInfo = autoFixture.Create <UserInfo>();
        }
 public ApprenticeshipMapper(
     IHashingService hashingService,
     ICurrentDateTime currentDateTime,
     IMediator mediator,
     ILog logger,
     IAcademicYearValidator academicYearValidator,
     IAcademicYearDateProvider academicYearDateProvider,
     ILinkGenerator linkGenerator,
     IFeatureToggleService featureToggleService)
 {
     _hashingService           = hashingService;
     _currentDateTime          = currentDateTime;
     _mediator                 = mediator;
     _logger                   = logger;
     _academicYearValidator    = academicYearValidator;
     _academicYearDateProvider = academicYearDateProvider;
     _linkGenerator            = linkGenerator;
     _featureToggleService     = featureToggleService;
 }
 public ResumeApprenticeshipCommandHandler(
     ICommitmentRepository commitmentRepository,
     IApprenticeshipRepository apprenticeshipRepository,
     ApprenticeshipStatusChangeCommandValidator validator,
     ICurrentDateTime currentDate,
     IApprenticeshipEvents eventsApi,
     ICommitmentsLogger logger,
     IHistoryRepository historyRepository,
     IAcademicYearDateProvider academicYearDateProvider,
     IAcademicYearValidator academicYearValidator)
 {
     _commitmentRepository     = commitmentRepository;
     _apprenticeshipRepository = apprenticeshipRepository;
     _validator                = validator;
     _currentDate              = currentDate;
     _eventsApi                = eventsApi;
     _logger                   = logger;
     _historyRepository        = historyRepository;
     _academicYearDateProvider = academicYearDateProvider;
     _academicYearValidator    = academicYearValidator;
 }
 public EmployerManageApprenticeshipsOrchestrator(
     IMediator mediator,
     IHashingService hashingService,
     IApprenticeshipMapper apprenticeshipMapper,
     IValidateApprovedApprenticeship approvedApprenticeshipValidator,
     ICurrentDateTime currentDateTime,
     ILog logger,
     ICookieStorageService <UpdateApprenticeshipViewModel> apprenticeshipsViewModelCookieStorageService,
     IAcademicYearDateProvider academicYearDateProvider,
     IAcademicYearValidator academicYearValidator,
     ILinkGenerator linkGenerator)
     : base(mediator, hashingService, logger)
 {
     _apprenticeshipMapper            = apprenticeshipMapper;
     _currentDateTime                 = currentDateTime;
     _approvedApprenticeshipValidator = approvedApprenticeshipValidator;
     _apprenticeshipsViewModelCookieStorageService = apprenticeshipsViewModelCookieStorageService;
     _academicYearDateProvider = academicYearDateProvider;
     _academicYearValidator    = academicYearValidator;
     _linkGenerator            = linkGenerator;
 }
Example #17
0
        public WhatIsTheNewStartDateViewModelValidator(IAcademicYearDateProvider academicYearDateProvider)
        {
            _academicYearDateProvider = academicYearDateProvider;

            RuleFor(r => r.NewStartDate).Must((r, newStartDate) => r.NewStartMonth.HasValue && r.NewStartYear.HasValue)
            .WithMessage("Enter the start date with the new training provider")
            .Unless(r => r.NewStartYear.HasValue || r.NewStartMonth.HasValue);

            RuleFor(r => r.NewStartDate).Must(y => y.Year.HasValue)
            .WithMessage("The start date must include a year")
            .When(r => r.NewStartMonth.HasValue);

            RuleFor(r => r.NewStartDate).Must(y => y.Month.HasValue).WithMessage("The start date must include a month")
            .When(r => r.NewStartYear.HasValue);

            RuleFor(x => x.NewStartDate)
            .Must(y => y.IsValid).WithMessage($"The start date must be a real date")
            .When(z => z.NewStartMonth.HasValue && z.NewStartYear.HasValue);

            RuleFor(r => r.NewStartDate)
            .Must((r, newStartDate) => newStartDate.IsEqualToOrAfterMonthYearOfDateTime(r.StopDate))
            .WithMessage(r => $"The start date must be on or after {r.StopDate:MMMM yyyy}")
            .When(r => r.NewStartDate.IsValid);

            When(r => r.NewStartMonth.HasValue && r.NewStartYear.HasValue && r.NewStartDate.IsValid, () =>
            {
                RuleFor(r => r.NewStartDate)
                .Must((r, newStartDate) => newStartDate.IsBeforeMonthYearOfDateTime(r.NewEndDate.Value))
                .WithMessage(r => $"The start date must be before {r.NewEndDate:MMMM yyyy}")
                .When(r => r.NewEndDate.HasValue);

                RuleFor(r => r.NewStartDate)
                .Must((r, newStartDate) => newStartDate.IsEqualToOrBeforeMonthYearOfDateTime(_academicYearDateProvider.CurrentAcademicYearEndDate.AddYears(1)))
                .WithMessage(r => "The start date must be no later than one year after the end of the current teaching year")
                .Unless(StartDateAfterStopDate);
            });
        }
 public CohortDomainService(Lazy <ProviderCommitmentsDbContext> dbContext,
                            ILogger <CohortDomainService> logger,
                            IAcademicYearDateProvider academicYearDateProvider,
                            IUlnValidator ulnValidator,
                            IReservationValidationService reservationValidationService,
                            IOverlapCheckService overlapCheckService,
                            IAuthenticationService authenticationService,
                            ICurrentDateTime currentDateTime,
                            IEmployerAgreementService employerAgreementService,
                            IEncodingService encodingService,
                            IAccountApiClient accountApiClient)
 {
     _dbContext = dbContext;
     _logger    = logger;
     _academicYearDateProvider     = academicYearDateProvider;
     _ulnValidator                 = ulnValidator;
     _reservationValidationService = reservationValidationService;
     _overlapCheckService          = overlapCheckService;
     _authenticationService        = authenticationService;
     _currentDateTime              = currentDateTime;
     _employerAgreementService     = employerAgreementService;
     _encodingService              = encodingService;
     _accountApiClient             = accountApiClient;
 }
        public StartDateViewModelValidator(IAcademicYearDateProvider academicYearDateProvider)
        {
            _academicYearDateProvider = academicYearDateProvider;

            RuleFor(x => x.ApprenticeshipHashedId)
            .NotEmpty();
            RuleFor(x => x.EmployerAccountLegalEntityPublicHashedId)
            .NotEmpty();
            RuleFor(x => x.ProviderId)
            .GreaterThan(0);
            RuleFor(x => x.AccountLegalEntityId)
            .GreaterThan(0);
            RuleFor(x => x.StopDate)
            .NotEmpty();
            RuleFor(x => x.StartDate)
            .Must(y => y.HasValue)
            .WithMessage("Enter the new training start date for this apprenticeship")
            .When(z => !z.StartDate.HasValue);
            RuleFor(x => x.StartDate)
            .Must(y => y.IsValid)
            .WithMessage("The start date is not valid")
            .When(z => z.StartDate.HasValue);
            RuleFor(x => x.StartDate)
            .Must((y, _) => y.StartDate.Date >= y.StopDate)
            .WithMessage("The new training start date cannot be before the stop date")
            .When(a => a.StartDate.HasValue && a.StartDate.IsValid);
            RuleFor(x => x.StartDate)
            .Must((y, _) => y.StartDate.Date < (new MonthYearModel(y.EndDate).Date))
            .WithMessage("Enter a start date prior to the new training end date")
            .When(a => a.EndDate != null && a.StartDate.HasValue && a.StartDate.IsValid);
            RuleFor(x => x.StartDate)
            .Must((y, _) => y.StartDate.Date <= (new MonthYearModel(_academicYearDateProvider.CurrentAcademicYearEndDate.AddYears(1).ToString("MMyyyy")).Date))
            .WithMessage("The start date must be no later than one year after the end of the current teaching year")
            .When(a => a.StartDate.HasValue && a.StartDate.IsValid)
            .Unless(a => a.EndDate != null && a.StartDate.Date > new MonthYearModel(a.EndDate).Date);
        }
        public EditApprenticeshipStopDateViewModelValidator(ICurrentDateTime currentDateTime, IAcademicYearDateProvider academicYearDateProvider, IValidationApi validationApi, IHashingService hashingService)
        {
            _currentDateTime = currentDateTime;
            _validationApi   = validationApi;
            _hashingService  = hashingService;

            RuleFor(r => r.NewStopDate)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .NotNull().WithMessage("Enter the stop date for this apprenticeship")
            .Must(d => d.DateTime.HasValue).WithMessage("Enter the stop date for this apprenticeship")
            .Must(d => d.DateTime <= new DateTime(_currentDateTime.Now.Year, _currentDateTime.Now.Month, 1)).WithMessage("The stop date cannot be in the future")
            .Must((model, newStopDate) => newStopDate.DateTime >= new DateTime(model.ApprenticeshipStartDate.Year, model.ApprenticeshipStartDate.Month, 1)).WithMessage("The stop month cannot be before the apprenticeship started")
            .Must((model, newStopDate) => newStopDate.DateTime != model.CurrentStopDate).WithMessage("Enter a date that is different to the current stopped date")
            .MustAsync(NotOverlap).WithMessage("The date overlaps with existing dates for the same apprentice.");
        }
Example #21
0
        public InstrumentedBulkUploadValidator(ILog logger, IBulkUploadValidator validator, IUlnValidator ulnValidator, IAcademicYearDateProvider academicYear)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (validator == null)
            {
                throw new ArgumentNullException(nameof(validator));
            }

            _logger    = logger;
            _validator = validator;
        }
        public BulkUploadValidator(ProviderApprenticeshipsServiceConfiguration config, IUlnValidator ulnValidator, IAcademicYearDateProvider academicYear)
        {
            _validationText     = new BulkUploadApprenticeshipValidationText(academicYear);
            _viewModelValidator = new ApprenticeshipUploadModelValidator(_validationText, new CurrentDateTime(), ulnValidator, academicYear);

            _config = config;
        }
Example #23
0
 public WebApprenticeshipValidationText(IAcademicYearDateProvider academicYear)
 {
     _academicYear = academicYear;
 }
Example #24
0
 public AcademicYearValidator(ICurrentDateTime currentDateTime, IAcademicYearDateProvider academicYear)
 {
     _currentDateTime = currentDateTime;
     _academicYear    = academicYear;
 }
 public EditApprenticeshipRequestToViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IAcademicYearDateProvider academicYearDateProvider, ICurrentDateTime currentDateTime)
 {
     _commitmentsApiClient     = commitmentsApiClient;
     _academicYearDateProvider = academicYearDateProvider;
     _currentDateTime          = currentDateTime;
 }