Exemplo n.º 1
0
        public void Validate_Errors()
        {
            var learner = new MessageLearner()
            {
                LearningDelivery = new MessageLearnerLearningDelivery[]
                {
                    new MessageLearnerLearningDelivery()
                    {
                        LearnStartDate = new DateTime(2005, 1, 1),
                    }
                }
            };

            var validationDataMock = new Mock <IValidationData>();

            validationDataMock.SetupGet(vd => vd.AcademicYearStart).Returns(new DateTime(2017, 8, 1));

            var validationErrorHandlerMock = new Mock <IValidationErrorHandler <MessageLearner> >();

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

            validationErrorHandlerMock.Setup(handle);

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

            rule.Validate(learner);

            validationErrorHandlerMock.Verify(handle, Times.Once);
        }
        [InlineData("2006-07-31", "2016-08-15", "2016-08-01")] // 2016-08-01 => 2006-08-01
        public void InvalidItemRaisesValidationMessage(string startDate, string operationDate, string commencementDate)
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var testdate     = DateTime.Parse(startDate);
            var opDate       = DateTime.Parse(operationDate);
            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(x => x.LearnStartDate)
            .Returns(testdate);

            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);

            handler
            .Setup(x => x.Handle(LearnStartDate_02Rule.Name, LearnRefNumber, 0, Moq.It.IsAny <IEnumerable <IErrorMessageParameter> >()));
            handler
            .Setup(x => x.BuildErrorMessageParameter("LearnStartDate", testdate.ToString("d", AbstractRule.RequiredCulture)))
            .Returns(new Mock <IErrorMessageParameter>().Object);

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

            service
            .SetupGet(x => x.Today)
            .Returns(opDate);
            service
            .Setup(x => x.GetAcademicYearOfLearningDate(opDate, AcademicYearDates.Commencement))
            .Returns(DateTime.Parse(commencementDate));

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

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

            // assert
            handler.VerifyAll();
            service.VerifyAll();
        }
        [InlineData("2006-08-01", "2016-08-15", "2016-08-01")] // 2016-08-01 => 2006-08-01
        public void ValidItemDoesNotRaiseAValidationMessage(string startDate, string operationDate, string commencementDate)
        {
            // arrange
            const string LearnRefNumber = "123456789X";

            var testdate     = DateTime.Parse(startDate);
            var opDate       = DateTime.Parse(operationDate);
            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(x => x.LearnStartDate)
            .Returns(testdate);

            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
            .SetupGet(x => x.Today)
            .Returns(opDate);
            service
            .Setup(x => x.GetAcademicYearOfLearningDate(opDate, AcademicYearDates.Commencement))
            .Returns(DateTime.Parse(commencementDate));

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

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

            // assert
            handler.VerifyAll();
            service.VerifyAll();
        }
Exemplo n.º 4
0
        public void Validate_NoErrors()
        {
            var learner = new MessageLearner()
            {
                LearningDelivery = new MessageLearnerLearningDelivery[]
                {
                    new MessageLearnerLearningDelivery()
                    {
                        LearnStartDate = new DateTime(2015, 1, 1),
                    }
                }
            };

            var validationDataMock = new Mock <IValidationData>();

            validationDataMock.SetupGet(vd => vd.AcademicYearStart).Returns(new DateTime(2017, 8, 1));

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

            rule.Validate(learner);
        }