public void ValidItemDoesNotRaiseValidationMessage()
        {
            // arrange
            const string LearnRefNumber = "123456789X";
            const string learnAimRef    = "salddfkjeifdnase";

            var mockFAM = new Mock <ILearningDeliveryFAM>();

            mockFAM
            .SetupGet(x => x.LearnDelFAMType)
            .Returns(Monitoring.Delivery.Types.FullOrCoFunding);
            mockFAM
            .SetupGet(x => x.LearnDelFAMCode)
            .Returns("2");

            var fams = new ILearningDeliveryFAM[] { mockFAM.Object };

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearnAimRef)
            .Returns(learnAimRef);
            mockDelivery
            .SetupGet(y => y.LearnStartDate)
            .Returns(DateTime.Parse("2017-08-01"));
            mockDelivery
            .SetupGet(y => y.FundModel)
            .Returns(TypeOfFunding.AdultSkills);
            mockDelivery
            .SetupGet(y => y.LearningDeliveryFAMs)
            .Returns(fams);

            var deliveries = new ILearningDelivery[] { mockDelivery.Object };

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.PriorAttainNullable)
            .Returns(TypeOfPriorAttainment.FullLevel2);
            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockLearner
            .SetupGet(x => x.DateOfBirthNullable)
            .Returns(DateTime.Parse("1996-07-01"));
            mockLearner
            .SetupGet(x => x.LearningDeliveries)
            .Returns(deliveries);

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

            var mockCat = new Mock <ILARSLearningCategory>();

            mockCat
            .SetupGet(x => x.CategoryRef)
            .Returns(TypeOfLARSCategory.LegalEntitlementLevel2);

            var larsCats = new ILARSLearningCategory[] { mockCat.Object };

            var mockLARSDel = new Mock <ILARSLearningDelivery>();

            mockLARSDel
            .SetupGet(x => x.NotionalNVQLevelv2)
            .Returns(LARSNotionalNVQLevelV2.Level2);
            mockLARSDel
            .SetupGet(x => x.Categories)
            .Returns(larsCats);

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

            service
            .Setup(x => x.GetDeliveryFor(learnAimRef))
            .Returns(mockLARSDel.Object);

            var mockDDRule07 = new Mock <IDerivedData_07Rule>(MockBehavior.Strict);
            var mockDDRule21 = new Mock <IDerivedData_21Rule>(MockBehavior.Strict);

            mockDDRule21
            .Setup(x => x.IsAdultFundedUnemployedWithOtherStateBenefits(mockDelivery.Object, mockLearner.Object))
            .Returns(false);

            var mockDDRule28 = new Mock <IDerivedData_28Rule>(MockBehavior.Strict);

            mockDDRule28
            .Setup(x => x.IsAdultFundedUnemployedWithBenefits(mockDelivery.Object, mockLearner.Object))
            .Returns(false);

            var mockDDRule29 = new Mock <IDerivedData_29Rule>(MockBehavior.Strict);

            var sut = new LearnDelFAMType_62Rule(handler.Object, service.Object, mockDDRule07.Object, mockDDRule21.Object, mockDDRule28.Object, mockDDRule29.Object);

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

            // assert
            handler.VerifyAll();
            service.VerifyAll();
            mockDDRule07.VerifyAll();
            mockDDRule21.VerifyAll();
            mockDDRule28.VerifyAll();
            mockDDRule29.VerifyAll();
        }
        public void InvalidItemRaisesValidationMessage()
        {
            // arrange
            const string LearnRefNumber = "123456789X";
            const string learnAimRef    = "salddfkjeifdnase";
            const int    fundModel      = TypeOfFunding.AdultSkills;
            const string famType        = Monitoring.Delivery.Types.FullOrCoFunding;
            const string famCode        = "2";
            DateTime?    dateOfBirth    = new DateTime(1996, 8, 1);
            DateTime     learnStartDate = new DateTime(2017, 8, 1);

            var mockFAM = new Mock <ILearningDeliveryFAM>();

            mockFAM
            .SetupGet(x => x.LearnDelFAMType)
            .Returns(famType);
            mockFAM
            .SetupGet(x => x.LearnDelFAMCode)
            .Returns(famCode);

            var fams = new ILearningDeliveryFAM[] { mockFAM.Object };

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearnAimRef)
            .Returns(learnAimRef);
            mockDelivery
            .SetupGet(y => y.LearnStartDate)
            .Returns(learnStartDate);
            mockDelivery
            .SetupGet(y => y.FundModel)
            .Returns(fundModel);
            mockDelivery
            .SetupGet(y => y.LearningDeliveryFAMs)
            .Returns(fams);

            var deliveries = new ILearningDelivery[] { mockDelivery.Object };

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.PriorAttainNullable)
            .Returns(TypeOfPriorAttainment.FullLevel2);
            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockLearner
            .SetupGet(x => x.DateOfBirthNullable)
            .Returns(dateOfBirth);
            mockLearner
            .SetupGet(x => x.LearningDeliveries)
            .Returns(deliveries);

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

            handler
            .Setup(x => x.Handle(RuleNameConstants.LearnDelFAMType_62, LearnRefNumber, 0, It.IsAny <IEnumerable <IErrorMessageParameter> >()));
            handler
            .Setup(x => x.BuildErrorMessageParameter("FundModel", fundModel))
            .Returns(new Mock <IErrorMessageParameter>().Object);
            handler
            .Setup(x => x.BuildErrorMessageParameter("LearnDelFAMType", famType))
            .Returns(new Mock <IErrorMessageParameter>().Object);
            handler
            .Setup(x => x.BuildErrorMessageParameter("LearnDelFAMCode", famCode))
            .Returns(new Mock <IErrorMessageParameter>().Object);
            handler
            .Setup(x => x.BuildErrorMessageParameter("LearnStartDate", AbstractRule.AsRequiredCultureDate(learnStartDate)))
            .Returns(new Mock <IErrorMessageParameter>().Object);
            handler
            .Setup(x => x.BuildErrorMessageParameter("DateOfBirth", AbstractRule.AsRequiredCultureDate(dateOfBirth)))
            .Returns(new Mock <IErrorMessageParameter>().Object);

            var mock = new Mock <ILARSLearningDelivery>();

            mock
            .SetupGet(x => x.NotionalNVQLevelv2)
            .Returns(LARSNotionalNVQLevelV2.Level2);

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

            service
            .Setup(x => x.GetDeliveryFor(learnAimRef))
            .Returns(mock.Object);

            var mockDDRule07 = new Mock <IDerivedData_07Rule>(MockBehavior.Strict);
            var mockDDRule21 = new Mock <IDerivedData_21Rule>(MockBehavior.Strict);

            mockDDRule21
            .Setup(x => x.IsAdultFundedUnemployedWithOtherStateBenefits(mockDelivery.Object, mockLearner.Object))
            .Returns(false);

            var mockDDRule28 = new Mock <IDerivedData_28Rule>(MockBehavior.Strict);

            mockDDRule28
            .Setup(x => x.IsAdultFundedUnemployedWithBenefits(mockDelivery.Object, mockLearner.Object))
            .Returns(false);

            var mockDDRule29 = new Mock <IDerivedData_29Rule>(MockBehavior.Strict);

            var sut = new LearnDelFAMType_62Rule(handler.Object, service.Object, mockDDRule07.Object, mockDDRule21.Object, mockDDRule28.Object, mockDDRule29.Object);

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

            // assert
            handler.VerifyAll();
            service.VerifyAll();
            mockDDRule07.VerifyAll();
            mockDDRule21.VerifyAll();
            mockDDRule28.VerifyAll();
            mockDDRule29.VerifyAll();
        }
        public void InvalidItemRaisesValidationMessage()
        {
            // arrange
            const string LearnRefNumber = "123456789X";
            const string learnAimRef    = "salddfkjeifdnase";

            var mockFAM = new Mock <ILearningDeliveryFAM>();

            mockFAM
            .SetupGet(x => x.LearnDelFAMType)
            .Returns(Monitoring.Delivery.Types.FullOrCoFunding);
            mockFAM
            .SetupGet(x => x.LearnDelFAMCode)
            .Returns("2");

            var fams = Collection.Empty <ILearningDeliveryFAM>();

            fams.Add(mockFAM.Object);

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearnAimRef)
            .Returns(learnAimRef);
            mockDelivery
            .SetupGet(y => y.LearnStartDate)
            .Returns(DateTime.Parse("2017-08-01"));
            mockDelivery
            .SetupGet(y => y.FundModel)
            .Returns(TypeOfFunding.AdultSkills);
            mockDelivery
            .SetupGet(y => y.LearningDeliveryFAMs)
            .Returns(fams.AsSafeReadOnlyList());

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

            deliveries.Add(mockDelivery.Object);

            var mockLearner = new Mock <ILearner>();

            mockLearner
            .SetupGet(x => x.PriorAttainNullable)
            .Returns(TypeOfPriorAttainment.FullLevel2);
            mockLearner
            .SetupGet(x => x.LearnRefNumber)
            .Returns(LearnRefNumber);
            mockLearner
            .SetupGet(x => x.DateOfBirthNullable)
            .Returns(DateTime.Parse("1996-07-01"));
            mockLearner
            .SetupGet(x => x.LearningDeliveries)
            .Returns(deliveries.AsSafeReadOnlyList());

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

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

            var mock = new Mock <ILARSLearningDelivery>();

            mock
            .SetupGet(x => x.NotionalNVQLevelv2)
            .Returns(LARSNotionalNVQLevelV2.Level2);

            var larsDeliveries = Collection.Empty <ILARSLearningDelivery>();

            larsDeliveries.Add(mock.Object);

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

            service
            .Setup(x => x.GetDeliveriesFor(learnAimRef))
            .Returns(larsDeliveries.AsSafeReadOnlyList());

            var mockDDRule07 = new Mock <IDD07>(MockBehavior.Strict);
            var mockDDRule21 = new Mock <IDerivedData_21Rule>(MockBehavior.Strict);
            var mockDDRule28 = new Mock <IDerivedData_28Rule>(MockBehavior.Strict);
            var mockDDRule29 = new Mock <IDerivedData_29Rule>(MockBehavior.Strict);

            var sut = new LearnDelFAMType_62Rule(handler.Object, service.Object, mockDDRule07.Object, mockDDRule21.Object, mockDDRule28.Object, mockDDRule29.Object);

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

            // assert
            handler.VerifyAll();
            service.VerifyAll();
            mockDDRule07.VerifyAll();
            mockDDRule21.VerifyAll();
            mockDDRule28.VerifyAll();
            mockDDRule29.VerifyAll();
        }