public void HasQualifyingStartDateMeetsExpectation(string startDate, string yearEndDate, bool expectation)
        {
            // arrange
            var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict);
            var service = new Mock <IAcademicYearDataService>(MockBehavior.Strict);

            service
            .Setup(x => x.End())
            .Returns(DateTime.Parse(yearEndDate));

            var rule07 = new Mock <IDerivedData_07Rule>(MockBehavior.Strict);

            var sut = new LearnStartDate_12Rule(handler.Object, service.Object, rule07.Object);

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearnStartDate)
            .Returns(DateTime.Parse(startDate));

            // act
            var result = sut.HasQualifyingStartDate(mockDelivery.Object);

            // assert
            Assert.Equal(expectation, result);
        }
Exemplo n.º 2
0
        public void Validate_NoErrors()
        {
            var learningDelivery = new MessageLearnerLearningDelivery()
            {
                LearnStartDate = new DateTime(2017, 1, 1),
            };

            var learner = new MessageLearner()
            {
                LearningDelivery = new MessageLearnerLearningDelivery[]
                {
                    learningDelivery
                }
            };

            var validationDataMock = new Mock <IValidationData>();
            var dd07Mock           = new Mock <IDD07Rule>();

            validationDataMock.SetupGet(vd => vd.AcademicYearEnd).Returns(new DateTime(2017, 8, 1));
            dd07Mock.Setup(dd => dd.Evaluate(learningDelivery)).Returns("Y");

            var rule = new LearnStartDate_12Rule(dd07Mock.Object, validationDataMock.Object, null);

            rule.Validate(learner);
        }
Exemplo n.º 3
0
        public void Validate_Errors()
        {
            var learningDelivery = new MessageLearnerLearningDelivery()
            {
                LearnStartDate = new DateTime(2020, 1, 1),
                ProgType       = 1
            };

            var learner = new MessageLearner()
            {
                LearningDelivery = new MessageLearnerLearningDelivery[]
                {
                    learningDelivery,
                }
            };

            var validationDataMock         = new Mock <IValidationData>();
            var validationErrorHandlerMock = new Mock <IValidationErrorHandler <MessageLearner> >();
            var dd07Mock = new Mock <IDD07Rule>();

            validationDataMock.SetupGet(vd => vd.AcademicYearEnd).Returns(new DateTime(2018, 7, 31));
            dd07Mock.Setup(dd => dd.Evaluate(learningDelivery)).Returns("Y");

            Expression <Action <IValidationErrorHandler <MessageLearner> > > handle = veh => veh.Handle(learner, "LearnStartDate_12");

            validationErrorHandlerMock.Setup(handle);

            var rule = new LearnStartDate_12Rule(dd07Mock.Object, validationDataMock.Object, validationErrorHandlerMock.Object);

            rule.Validate(learner);

            validationErrorHandlerMock.Verify(handle, Times.Once);
        }
        public void InvalidItemRaisesValidationMessage()
        {
            const string LearnRefNumber = "123456789X";
            var          referenceDate  = DateTime.Parse("2019-04-19");

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearnStartDate)
            .Returns(referenceDate);
            mockDelivery
            .SetupGet(y => y.ProgTypeNullable)
            .Returns(ProgTypes.ApprenticeshipStandard);

            var deliveries = new List <ILearningDelivery>();

            deliveries.Add(mockDelivery.Object);

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockLearner
            .SetupGet(x => x.LearningDeliveries)
            .Returns(deliveries);

            var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict);

            handler
            .Setup(x => x.Handle(
                       Moq.It.Is <string>(y => y == LearnStartDate_12Rule.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 == LearnStartDate_12Rule.MessagePropertyName),
                       referenceDate))
            .Returns(new Mock <IErrorMessageParameter>().Object);

            var service = new Mock <IAcademicYearDataService>(MockBehavior.Strict);

            service
            .Setup(x => x.End())
            .Returns(referenceDate.AddYears(-1));
            var rule07 = new Mock <IDerivedData_07Rule>(MockBehavior.Strict);

            rule07
            .Setup(x => x.IsApprenticeship(ProgTypes.ApprenticeshipStandard))
            .Returns(true);

            var sut = new LearnStartDate_12Rule(handler.Object, service.Object, rule07.Object);

            sut.Validate(mockLearner.Object);

            handler.VerifyAll();
            service.VerifyAll();
            rule07.VerifyAll();
        }
        public void Validate_Errors()
        {
            var learningDelivery = new TestLearningDelivery()
            {
                LearnStartDateNullable = new DateTime(2020, 1, 1),
                ProgTypeNullable       = 1
            };

            var learner = new TestLearner()
            {
                LearningDeliveries = new TestLearningDelivery[]
                {
                    learningDelivery,
                }
            };

            var validationDataServiceMock  = new Mock <IValidationDataService>();
            var validationErrorHandlerMock = new Mock <IValidationErrorHandler>();
            var dd07Mock = new Mock <IDD07>();

            validationDataServiceMock.SetupGet(vd => vd.AcademicYearEnd).Returns(new DateTime(2018, 7, 31));
            dd07Mock.Setup(dd => dd.Derive(1)).Returns("Y");

            Expression <Action <IValidationErrorHandler> > handle = veh => veh.Handle("LearnStartDate_12", null, null, null);

            validationErrorHandlerMock.Setup(handle);

            var rule = new LearnStartDate_12Rule(dd07Mock.Object, validationDataServiceMock.Object, validationErrorHandlerMock.Object);

            rule.Validate(learner);

            validationErrorHandlerMock.Verify(handle, Times.Once);
        }
        public void Validate_NoErrors()
        {
            var learningDelivery = new TestLearningDelivery()
            {
                LearnStartDateNullable = new DateTime(2017, 1, 1),
                ProgTypeNullable       = 1,
            };

            var learner = new TestLearner()
            {
                LearningDeliveries = new TestLearningDelivery[]
                {
                    learningDelivery
                }
            };

            var validationDataServiceMock = new Mock <IValidationDataService>();
            var dd07Mock = new Mock <IDD07>();

            validationDataServiceMock.SetupGet(vd => vd.AcademicYearEnd).Returns(new DateTime(2017, 8, 1));
            dd07Mock.Setup(dd => dd.Derive(1)).Returns("Y");

            var rule = new LearnStartDate_12Rule(dd07Mock.Object, validationDataServiceMock.Object, null);

            rule.Validate(learner);
        }
        public void ValidItemDoesNotRaiseValidationMessage()
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var referenceDate = DateTime.Parse("2019-04-19");

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearnStartDate)
            .Returns(referenceDate);
            mockDelivery
            .SetupGet(y => y.ProgTypeNullable)
            .Returns(TypeOfLearningProgramme.ApprenticeshipStandard);

            var deliveries = Collection.Empty <ILearningDelivery>();

            deliveries.Add(mockDelivery.Object);

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockLearner
            .SetupGet(x => x.LearningDeliveries)
            .Returns(deliveries.AsSafeReadOnlyList());

            var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict);
            var service = new Mock <IAcademicYearDataService>(MockBehavior.Strict);

            service
            .Setup(x => x.End())
            .Returns(referenceDate.AddYears(-1).AddDays(1));
            var rule07 = new Mock <IDerivedData_07Rule>(MockBehavior.Strict);

            rule07
            .Setup(x => x.IsApprenticeship(TypeOfLearningProgramme.ApprenticeshipStandard))
            .Returns(true);

            var sut = new LearnStartDate_12Rule(handler.Object, service.Object, rule07.Object);

            // act
            sut.Validate(mockLearner.Object);

            // assert
            handler.VerifyAll();
            service.VerifyAll();
            rule07.VerifyAll();
        }
        public void IsApprenticeshipMeetsExpectation(bool expectation)
        {
            var mockItem = new Mock <ILearningDelivery>();

            var handler = new Mock <IValidationErrorHandler>(MockBehavior.Strict);
            var service = new Mock <IAcademicYearDataService>(MockBehavior.Strict);
            var rule07  = new Mock <IDerivedData_07Rule>(MockBehavior.Strict);

            rule07
            .Setup(x => x.IsApprenticeship(null))
            .Returns(expectation);

            var sut = new LearnStartDate_12Rule(handler.Object, service.Object, rule07.Object);

            var result = sut.IsApprenticeship(mockItem.Object);

            Assert.Equal(expectation, result);
            handler.VerifyAll();
            service.VerifyAll();
            rule07.VerifyAll();
        }
Exemplo n.º 9
0
        public void ConditionMet_False_DD07()
        {
            var rule = new LearnStartDate_12Rule(null, null, null);

            rule.ConditionMet(new DateTime(2018, 8, 1), new DateTime(2016, 7, 31), "N").Should().BeFalse();
        }
Exemplo n.º 10
0
        public void ConditionMet_False_LearnStartDate_BeforeAcademicYearEnd()
        {
            var rule = new LearnStartDate_12Rule(null, null, null);

            rule.ConditionMet(new DateTime(2017, 1, 1), new DateTime(2018, 7, 31), "Y").Should().BeFalse();
        }
Exemplo n.º 11
0
        public void ConditionMet_False_LearnStartDate_WithinYear()
        {
            var rule = new LearnStartDate_12Rule(null, null, null);

            rule.ConditionMet(new DateTime(2019, 1, 1), new DateTime(2018, 7, 31), "Y").Should().BeFalse();
        }