public void Validate_NoErrors_FundModel() { var learner = new TestLearner() { ULNNullable = 9999999999, LearningDeliveries = new TestLearningDelivery[] { new TestLearningDelivery() { FundModelNullable = 100, LearnStartDateNullable = new DateTime(2018, 1, 2), LearnPlanEndDateNullable = new DateTime(2017, 1, 7), LearnActEndDateNullable = new DateTime(2018, 1, 7), } } }; var fileDataMock = new Mock <IFileDataService>(); var validationDataMock = new Mock <IValidationDataService>(); var learningDeliveryFAMQueryServiceMock = new Mock <ILearningDeliveryFAMQueryService>(); fileDataMock.SetupGet(fd => fd.FilePreparationDate).Returns(new DateTime(2018, 1, 1)); validationDataMock.SetupGet(vd => vd.AcademicYearJanuaryFirst).Returns(new DateTime(2018, 1, 1)); learningDeliveryFAMQueryServiceMock.Setup(qs => qs.HasLearningDeliveryFAMCodeForType(It.IsAny <IEnumerable <ILearningDeliveryFAM> >(), "LDM", "034")).Returns(false); var rule = new ULN_11Rule(fileDataMock.Object, validationDataMock.Object, learningDeliveryFAMQueryServiceMock.Object, null); rule.Validate(learner); }
public void HasExceedRegistrationPeriodMeetsExpectation(string fileDate, string startDate, bool expectation) { // arrange var mockItem = new Mock <ILearningDelivery>(); mockItem .SetupGet(y => y.LearnStartDate) .Returns(DateTime.Parse(startDate)); var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var fileData = new Mock <IFileDataService>(MockBehavior.Strict); fileData .Setup(xc => xc.FilePreparationDate()) .Returns(DateTime.Parse(fileDate)); var yearService = new Mock <IAcademicYearDataService>(MockBehavior.Strict); var sut = new ULN_11Rule(handler.Object, fileData.Object, yearService.Object); // act var result = sut.HasExceedRegistrationPeriod(mockItem.Object); // assert Assert.Equal(expectation, result); }
public void IsInsideGeneralRegistrationThresholdMeetsExpectation(string fileDate, string yearDate, bool expectation) { var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var fileData = new Mock <IFileDataService>(MockBehavior.Strict); fileData .Setup(xc => xc.FilePreparationDate()) .Returns(DateTime.Parse(fileDate)); var yearService = new Mock <IAcademicYearDataService>(MockBehavior.Strict); yearService .Setup(xc => xc.JanuaryFirst()) .Returns(DateTime.Parse(yearDate)); var sut = new ULN_11Rule(handler.Object, fileData.Object, yearService.Object); var result = sut.IsInsideGeneralRegistrationThreshold(); Assert.Equal(expectation, result); }
public void ValidItemDoesNotRaiseValidationMessage() { const string LearnRefNumber = "123456789X"; var mockFam = new Mock <ILearningDeliveryFAM>(); mockFam .SetupGet(y => y.LearnDelFAMType) .Returns(Monitoring.Delivery.Types.SourceOfFunding); mockFam .SetupGet(y => y.LearnDelFAMCode) .Returns("1"); var fams = new List <ILearningDeliveryFAM>(); fams.Add(mockFam.Object); var mockDelivery = new Mock <ILearningDelivery>(); mockDelivery .SetupGet(y => y.FundModel) .Returns(FundModels.NotFundedByESFA); mockDelivery .SetupGet(y => y.LearningDeliveryFAMs) .Returns(fams); mockDelivery .SetupGet(x => x.LearnStartDate) .Returns(DateTime.Parse("2019-03-02")); mockDelivery .SetupGet(x => x.LearnPlanEndDate) .Returns(DateTime.Parse("2019-05-02")); var deliveries = new List <ILearningDelivery>(); deliveries.Add(mockDelivery.Object); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); mockLearner .SetupGet(y => y.ULN) .Returns(9999999999); mockLearner .SetupGet(y => y.LearningDeliveries) .Returns(deliveries); var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); var fileData = new Mock <IFileDataService>(MockBehavior.Strict); fileData .Setup(xc => xc.FilePreparationDate()) .Returns(DateTime.Parse("2019-01-02")); var yearService = new Mock <IAcademicYearDataService>(MockBehavior.Strict); yearService .Setup(xc => xc.JanuaryFirst()) .Returns(DateTime.Parse("2019-01-01")); var sut = new ULN_11Rule(handler.Object, fileData.Object, yearService.Object); sut.Validate(mockLearner.Object); handler.VerifyAll(); fileData.VerifyAll(); yearService.VerifyAll(); }
public void InvalidItemRaisesValidationMessage() { // arrange const string LearnRefNumber = "123456789X"; var mockFam = new Mock <ILearningDeliveryFAM>(); mockFam .SetupGet(y => y.LearnDelFAMType) .Returns(Monitoring.Delivery.Types.SourceOfFunding); mockFam .SetupGet(y => y.LearnDelFAMCode) .Returns("1"); var fams = Collection.Empty <ILearningDeliveryFAM>(); fams.Add(mockFam.Object); var mockDelivery = new Mock <ILearningDelivery>(); mockDelivery .SetupGet(y => y.FundModel) .Returns(TypeOfFunding.NotFundedByESFA); mockDelivery .SetupGet(y => y.LearningDeliveryFAMs) .Returns(fams.AsSafeReadOnlyList()); mockDelivery .SetupGet(x => x.LearnStartDate) .Returns(DateTime.Parse("2019-04-02")); mockDelivery .SetupGet(x => x.LearnPlanEndDate) .Returns(DateTime.Parse("2019-05-02")); var deliveries = Collection.Empty <ILearningDelivery>(); deliveries.Add(mockDelivery.Object); var mockLearner = new Mock <ILearner>(); mockLearner .SetupGet(x => x.LearnRefNumber) .Returns(LearnRefNumber); mockLearner .SetupGet(y => y.ULN) .Returns(9999999999); mockLearner .SetupGet(y => y.LearningDeliveries) .Returns(deliveries.AsSafeReadOnlyList()); var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict); handler .Setup(x => x.Handle( Moq.It.Is <string>(y => y == ULN_11Rule.Name), Moq.It.Is <string>(y => y == LearnRefNumber), 0, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >())); handler .Setup(x => x.BuildErrorMessageParameter( Moq.It.Is <string>(y => y == ULN_11Rule.MessagePropertyName), Moq.It.IsAny <ILearningDelivery>())) .Returns(new Mock <IErrorMessageParameter>().Object); var fileData = new Mock <IFileDataService>(MockBehavior.Strict); fileData .Setup(xc => xc.FilePreparationDate()) .Returns(DateTime.Parse("2019-01-02")); var yearService = new Mock <IAcademicYearDataService>(MockBehavior.Strict); yearService .Setup(xc => xc.JanuaryFirst()) .Returns(DateTime.Parse("2019-01-01")); var sut = new ULN_11Rule(handler.Object, fileData.Object, yearService.Object); // act sut.Validate(mockLearner.Object); // assert handler.VerifyAll(); fileData.VerifyAll(); yearService.VerifyAll(); }