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

            var testDate = DateTime.Parse("2016-08-01");

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearnAimRef)
            .Returns(learnAimRef);
            mockDelivery
            .SetupGet(y => y.LearnStartDate)
            .Returns(testDate);
            mockDelivery
            .SetupGet(y => y.FundModel)
            .Returns(TypeOfFunding.AdultSkills);

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

            // it's this value that triggers the rule
            var mockCategory = new Mock <ILARSLearningCategory>();

            mockCategory
            .SetupGet(x => x.CategoryRef)
            .Returns(TypeOfLARSCategory.OnlyForLegalEntitlementAtLevel3);

            var larsCategories = Collection.Empty <ILARSLearningCategory>();

            larsCategories.Add(mockCategory.Object);

            var mockLars = new Mock <ILARSLearningDelivery>();

            mockLars
            .SetupGet(x => x.NotionalNVQLevelv2)
            .Returns(LARSNotionalNVQLevelV2.Level3);

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

            service
            .Setup(x => x.GetDeliveryFor(learnAimRef))
            .Returns(mockLars.Object);
            service
            .Setup(x => x.GetCategoriesFor(learnAimRef))
            .Returns(larsCategories.AsSafeReadOnlyList());

            var commonChecks = new Mock <IProvideRuleCommonOperations>(MockBehavior.Strict);

            commonChecks
            .Setup(x => x.IsRestart(mockDelivery.Object))
            .Returns(false);
            commonChecks
            .Setup(x => x.IsLearnerInCustody(mockDelivery.Object))
            .Returns(false);
            commonChecks
            .Setup(x => x.IsSteelWorkerRedundancyTraining(mockDelivery.Object))
            .Returns(false);
            commonChecks
            .Setup(x => x.InApprenticeship(mockDelivery.Object))
            .Returns(false);
            commonChecks
            .Setup(x => x.HasQualifyingFunding(mockDelivery.Object, TypeOfFunding.AdultSkills))
            .Returns(true);
            commonChecks
            .Setup(x => x.HasQualifyingStart(mockDelivery.Object, LearnAimRef_84Rule.FirstViableDate, null))
            .Returns(true);

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

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

            // assert
            handler.VerifyAll();
            service.VerifyAll();
            commonChecks.VerifyAll();
        }
        public void ValidItemDoesNotRaiseValidationMessage()
        {
            const string learnRefNumber = "123456789X";
            const string learnAimRef    = "salddfkjeifdnase";

            var testDate = DateTime.Parse("2016-08-01");

            var mockDelivery = new Mock <ILearningDelivery>();

            mockDelivery
            .SetupGet(y => y.LearnAimRef)
            .Returns(learnAimRef);
            mockDelivery
            .SetupGet(y => y.LearnStartDate)
            .Returns(testDate);
            mockDelivery
            .SetupGet(y => y.FundModel)
            .Returns(FundModels.AdultSkills);

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

            var mockCategory = new Mock <ILARSLearningCategory>();

            mockCategory
            .SetupGet(x => x.CategoryRef)
            .Returns(LARSConstants.Categories.OnlyForLegalEntitlementAtLevel3);

            var larsCategories = new List <ILARSLearningCategory>();

            larsCategories.Add(mockCategory.Object);

            var mockLars = new Mock <ILARSLearningDelivery>();

            mockLars
            .SetupGet(x => x.NotionalNVQLevelv2)
            .Returns(LARSConstants.NotionalNVQLevelV2Strings.Level3);

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

            service
            .Setup(x => x.GetDeliveryFor(learnAimRef))
            .Returns(mockLars.Object);
            service
            .Setup(x => x.GetCategoriesFor(learnAimRef))
            .Returns(larsCategories);

            var learningDeliveryFAMQS = new Mock <ILearningDeliveryFAMQueryService>(MockBehavior.Strict);

            learningDeliveryFAMQS
            .Setup(x => x.HasLearningDeliveryFAMCodeForType(
                       mockDelivery.Object.LearningDeliveryFAMs,
                       "LDM",
                       "347"))
            .Returns(false);
            learningDeliveryFAMQS
            .Setup(x => x.HasLearningDeliveryFAMCodeForType(
                       mockDelivery.Object.LearningDeliveryFAMs,
                       "LDM",
                       "376"))
            .Returns(false);
            learningDeliveryFAMQS
            .Setup(x => x.HasLearningDeliveryFAMCodeForType(
                       mockDelivery.Object.LearningDeliveryFAMs,
                       "LDM",
                       "034"))
            .Returns(false);
            learningDeliveryFAMQS
            .Setup(x => x.HasLearningDeliveryFAMCodeForType(
                       mockDelivery.Object.LearningDeliveryFAMs,
                       "DAM",
                       "023"))
            .Returns(false);
            learningDeliveryFAMQS
            .Setup(x => x.HasLearningDeliveryFAMType(
                       mockDelivery.Object.LearningDeliveryFAMs,
                       "RES"))
            .Returns(false);

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

            dd07
            .Setup(dd => dd.IsApprenticeship(mockDelivery.Object.ProgTypeNullable)).Returns(false);

            var dateTimeQS = new Mock <IDateTimeQueryService>(MockBehavior.Strict);

            dateTimeQS
            .Setup(x => x.IsDateBetween(mockDelivery.Object.LearnStartDate, LearnAimRef_84Rule.FirstViableDate, DateTime.MaxValue, true))
            .Returns(true);

            var sut = new LearnAimRef_84Rule(handler.Object, service.Object, learningDeliveryFAMQS.Object, dd07.Object, dateTimeQS.Object);

            sut.Validate(mockLearner.Object);

            handler.VerifyAll();
            service.VerifyAll();
            learningDeliveryFAMQS.VerifyAll();
            dd07.VerifyAll();
        }