public void ShouldFailValidationIfStartDateIsLaterThanOneYearAfterTheEndOfCurrentAcademicYear() { MockAcademicYearDateProvider.Setup(x => x.CurrentAcademicYearEndDate).Returns(new DateTime(2020, 1, 1)); ValidModel.ApprenticeshipViewModel.StartDate = new DateTimeViewModel(new DateTime(2021, 7, 20)); var result = Validator.Validate(ValidModel); result.IsValid.Should().BeFalse(); result.Errors[0].ErrorMessage.Should().Be("The start date must be no later than one year after the end of the current teaching year"); }
public void ThenItValidatesDataofChangeAccordingToAcademicYearRule( DateTime academicYearStart, DateTime academicYearEnd, DateTime academicYearR14Cutoff, DateTime startDate, DateTime pausedDate, DateTime resumeDate, DateTime timeNow, bool expectToPassValidation, bool validatesOnStartDate, string scenario) { MockAcademicYearDateProvider.Setup(y => y.CurrentAcademicYearStartDate).Returns(academicYearStart); MockAcademicYearDateProvider.Setup(y => y.CurrentAcademicYearEndDate).Returns(academicYearEnd); MockAcademicYearDateProvider.Setup(y => y.LastAcademicYearFundingPeriod).Returns(academicYearR14Cutoff); if (timeNow > academicYearR14Cutoff) { MockAcademicYearValidator.Setup(v => v.Validate(It.IsAny <DateTime>())) .Returns(AcademicYearValidationResult.NotWithinFundingPeriod); } else { MockAcademicYearValidator.Setup(v => v.Validate(It.IsAny <DateTime>())) .Returns(AcademicYearValidationResult.Success); } MockCurrentDateTime.Setup(d => d.Now).Returns(timeNow); TestApprenticeship.PauseDate = pausedDate.Date; ExampleValidRequest.DateOfChange = resumeDate.Date; Func <Task> act = async() => await Handler.Handle(ExampleValidRequest); if (expectToPassValidation) { act.ShouldNotThrow <ValidationException>(); } else { act.ShouldThrow <ValidationException>() .Which.Message.Should().Be(validatesOnStartDate ? "Invalid Date of Change. Date should be the academic year start date." : "Invalid Date of Change. Date should be the pause date."); } }