Exemple #1
0
        public void HasLearningDeliveryMatch_False(string learnAimRef, int yearStart, int fundModel, int?progType, int?fworkCode, int?pwayCode, int?stdCode)
        {
            var learningDelivery = new TestLearningDelivery
            {
                LearnAimRef       = learnAimRef,
                LearnStartDate    = new DateTime(yearStart, 8, 1),
                FundModel         = fundModel,
                ProgTypeNullable  = progType,
                FworkCodeNullable = fworkCode,
                PwayCodeNullable  = pwayCode,
                StdCodeNullable   = stdCode
            };

            var previousLearnerData = new LearnerReferenceData
            {
                LearnAimRef       = "LearnAimRef",
                LearnStartDate    = new DateTime(2020, 8, 1),
                FundModel         = 35,
                ProgTypeNullable  = 1,
                FworkCodeNullable = 1,
                PwayCodeNullable  = 1,
                StdCodeNullable   = 1
            };

            NewDD().HasLearningDeliveryMatch(learningDelivery, previousLearnerData).Should().BeFalse();
        }
Exemple #2
0
        public virtual IReadOnlyDictionary <string, IEnumerable <ILearnerReferenceData> > BuildDictionary(LearnerReferenceDataJson learnerReferenceData)
        {
            var referenceData = new LearnerReferenceData();

            if (learnerReferenceData == null)
            {
                return(new Dictionary <string, IEnumerable <ILearnerReferenceData> >());
            }

            var dictionary = learnerReferenceData?
                             .Learners?
                             .GroupBy(x => x.LearnRefNumber)
                             .ToDictionary(
                k => k.Key,
                v => v.Select(l => (ILearnerReferenceData) new LearnerReferenceData
            {
                LearnRefNumber     = l.LearnRefNumber,
                UKPRN              = l.UKPRN,
                PMUKPRN            = l.PMUKPRN,
                PrevUKPRN          = l.PrevUKPRN,
                ULN                = l.ULN,
                PrevLearnRefNumber = l.PrevLearnRefNumber,
                LearnAimRef        = l.LearnAimRef,
                ProgTypeNullable   = l.ProgTypeNullable,
                StdCodeNullable    = l.StdCodeNullable,
                FworkCodeNullable  = l.FworkCodeNullable,
                PwayCodeNullable   = l.PwayCodeNullable,
                LearnStartDate     = l.LearnStartDate,
                LearnActEndDate    = l.LearnActEndDate,
                FundModel          = l.FundModel,
            }), StringComparer.OrdinalIgnoreCase);

            return(dictionary);
        }
        public void ValidateNo_NoError()
        {
            var learnerReferenceData = new LearnerReferenceData
            {
                LearnAimRef       = "LearnAimRef",
                LearnStartDate    = new DateTime(2020, 8, 1),
                LearnActEndDate   = new DateTime(2020, 7, 1),
                FundModel         = 35,
                ProgTypeNullable  = 1,
                FworkCodeNullable = 1,
                PwayCodeNullable  = 1,
                StdCodeNullable   = 1
            };

            var learningDeliveryFams = new List <ILearningDeliveryFAM>
            {
                new TestLearningDeliveryFAM
                {
                    LearnDelFAMCode = "1",
                    LearnDelFAMType = "ADL"
                }
            };

            var learningDelivery = new TestLearningDelivery
            {
                FundModel = 35,
                LearnActEndDateNullable = new DateTime(2020, 7, 1),
                LearningDeliveryFAMs    = learningDeliveryFams
            };

            var learningDeliveries = new List <ILearningDelivery>
            {
                learningDelivery
            };

            var learner = new TestLearner
            {
                LearnRefNumber     = "LearnRefNUmber",
                LearningDeliveries = learningDeliveries
            };

            var dd39 = new Mock <IDerivedData_39Rule>();

            dd39.Setup(x => x.GetMatchingLearningAimFromPreviousYear(learner, learningDelivery)).Returns(learnerReferenceData);

            var learningDeliveryFamQSMock = new Mock <ILearningDeliveryFAMQueryService>();

            learningDeliveryFamQSMock.Setup(x => x.HasLearningDeliveryFAMCodeForType(learningDeliveryFams, "ADL", "1")).Returns(false);

            using (var validationErrorHandlerMock = BuildValidationErrorHandlerMockForNoError())
            {
                NewRule(validationErrorHandlerMock.Object, learningDeliveryFamQSMock.Object, dd39.Object).Validate(learner);
                validationErrorHandlerMock.Verify(h => h.BuildErrorMessageParameter(It.IsAny <string>(), It.IsAny <object>()), Times.Exactly(0));
            }
        }
        public void ConditionMet_False_FundedAim()
        {
            var learnerReferenceData = new LearnerReferenceData
            {
                LearnAimRef       = "LearnAimRef",
                LearnStartDate    = new DateTime(2020, 8, 1),
                LearnActEndDate   = new DateTime(2020, 7, 1),
                FundModel         = 35,
                ProgTypeNullable  = 1,
                FworkCodeNullable = 1,
                PwayCodeNullable  = 1,
                StdCodeNullable   = 1
            };

            var learningDeliveryFams = new List <ILearningDeliveryFAM>
            {
                new TestLearningDeliveryFAM
                {
                    LearnDelFAMCode = "1",
                    LearnDelFAMType = "ADL"
                }
            };

            var learningDelivery = new TestLearningDelivery
            {
                FundModel = 10,
                LearnActEndDateNullable = new DateTime(2020, 8, 1),
                LearningDeliveryFAMs    = learningDeliveryFams
            };

            var learningDeliveries = new List <ILearningDelivery>
            {
                learningDelivery
            };

            var learner = new TestLearner
            {
                LearnRefNumber     = "LearnRefNUmber",
                LearningDeliveries = learningDeliveries
            };

            var learningDeliveryFamQSMock = new Mock <ILearningDeliveryFAMQueryService>();

            learningDeliveryFamQSMock.Setup(x => x.HasLearningDeliveryFAMCodeForType(learningDeliveryFams, "ADL", "1")).Returns(false);

            NewRule(learningDeliveryFamQueryService: learningDeliveryFamQSMock.Object).ConditionMet(learningDelivery, learnerReferenceData).Should().BeFalse();
        }
Exemple #5
0
        public void GetLearnerDataForPreviousYear_Multiple()
        {
            var learner1 = new LearnerReferenceData
            {
                LearnRefNumber = "Learner1"
            };

            var learner2 = new LearnerReferenceData
            {
                LearnRefNumber = "Learner2"
            };

            var learnerCache = new Dictionary <string, IEnumerable <ILearnerReferenceData> >
            {
                {
                    "Learner1", new List <ILearnerReferenceData>
                    {
                        learner1
                    }
                },
                {
                    "Learner2", new List <ILearnerReferenceData>
                    {
                        learner2
                    }
                },
            };

            var cache = new Mock <ILearnerReferenceDataCache>();

            cache.Setup(x => x.Learners).Returns(learnerCache);

            var result = NewService(cache.Object).GetLearnerDataForPreviousYear(new List <string> {
                "Learner1", "Learner2"
            });

            result.Should().BeEquivalentTo(new List <ILearnerReferenceData> {
                learner1, learner2
            });
        }
Exemple #6
0
        public void HasMatch_True(int ukprn)
        {
            var learner = new TestLearner
            {
                LearnRefNumber     = "LearnRefNumber1",
                PrevLearnRefNumber = "LearnRefNumber2",
                PMUKPRNNullable    = ukprn,
                PrevUKPRNNullable  = ukprn,
                ULN = 1,
            };
            var learningDelivery = new TestLearningDelivery
            {
                LearnAimRef      = "LearnAimRef",
                LearnStartDate   = new DateTime(2020, 8, 1),
                FundModel        = 35,
                ProgTypeNullable = 1,
            };

            var previousLearnerData = new LearnerReferenceData
            {
                LearnRefNumber   = "LearnRefNumber1",
                UKPRN            = 1,
                PrevUKPRN        = 2,
                PMUKPRN          = 2222,
                ULN              = 1,
                LearnAimRef      = "LearnAimRef",
                LearnStartDate   = new DateTime(2020, 8, 1),
                FundModel        = 35,
                ProgTypeNullable = 1,
            };

            var ukprnList = new List <long> {
                1, 2, 3
            };

            NewDD().HasMatch(ukprnList, 1, learningDelivery, previousLearnerData).Should().BeTrue();
        }
Exemple #7
0
        public async Task ExecuteAsync()
        {
            var fileName                = "Filename.xml";
            var container               = "Container";
            var ilrReferenceDataKey     = "IlrReferenceDataKey";
            var learnerReferenceDataKey = "LearnerReferenceDataKey";
            var message        = new Message();
            var ilrRefData     = new ReferenceDataRoot();
            var learnerRefData = new LearnerReferenceData();

            var cancellationToken = CancellationToken.None;
            var context           = new Mock <IValidationContext>();

            context.Setup(x => x.Filename).Returns(fileName);
            context.Setup(x => x.Container).Returns(container);
            context.Setup(x => x.IlrReferenceDataKey).Returns(ilrReferenceDataKey);
            context.Setup(x => x.LearnerReferenceDataKey).Returns(learnerReferenceDataKey);

            var messageProvider = new Mock <IFileProvider <Message> >();

            messageProvider.Setup(x => x.ProvideAsync(fileName, container, cancellationToken)).ReturnsAsync(message);
            var referenceDataRootProvider = new Mock <IFileProvider <ReferenceDataRoot> >();

            referenceDataRootProvider.Setup(x => x.ProvideAsync(ilrReferenceDataKey, container, cancellationToken)).ReturnsAsync(ilrRefData);
            var learnerReferenceDataProvider = new Mock <IFileProvider <LearnerReferenceData> >();

            learnerReferenceDataProvider.Setup(x => x.ProvideAsync(learnerReferenceDataKey, container, cancellationToken)).ReturnsAsync(learnerRefData);

            var preValidationPopulationService = new Mock <IPopulationService>();

            var validationErrorCache = new Mock <IValidationErrorCache>();

            validationErrorCache.Setup(x => x.ValidationErrors).Returns(new List <IValidationError>());

            var validationOutputService = new Mock <IValidationOutputService>();

            validationOutputService.Setup(x => x.ProcessAsync(context.Object, message, validationErrorCache.Object.ValidationErrors, cancellationToken)).Returns(Task.CompletedTask);

            var validIlrFileOutputService = new Mock <IValidIlrFileOutputService>();

            validIlrFileOutputService.Setup(x => x.ProcessAsync(context.Object, message, cancellationToken)).Returns(Task.CompletedTask);

            var messageRuleSetOrchestratonService = new Mock <IRuleSetOrchestrationService <IRule <IMessage>, IMessage> >();

            messageRuleSetOrchestratonService.Setup(x => x.ExecuteAsync(message, cancellationToken)).ReturnsAsync(new List <IValidationError>());

            var crossYearRuleSetOrchestrationService = new Mock <IRuleSetOrchestrationService <ICrossYearRule <ILearner>, ILearner> >();

            crossYearRuleSetOrchestrationService.Setup(x => x.ExecuteAsync(message.Learners, cancellationToken)).ReturnsAsync(new List <IValidationError>());

            var validationExecutionProvider = new Mock <IValidationExecutionProvider>();

            validationExecutionProvider.Setup(x => x.ExecuteAsync(context.Object, message, cancellationToken)).Returns(Task.CompletedTask);

            await NewService(
                preValidationPopulationService.Object,
                messageProvider.Object,
                referenceDataRootProvider.Object,
                learnerReferenceDataProvider.Object,
                validationErrorCache.Object,
                validationOutputService.Object,
                validIlrFileOutputService.Object,
                messageRuleSetOrchestratonService.Object,
                crossYearRuleSetOrchestrationService.Object,
                validationExecutionProvider.Object
                ).ExecuteAsync(context.Object, cancellationToken);

            preValidationPopulationService.VerifyAll();
            messageProvider.VerifyAll();
            referenceDataRootProvider.VerifyAll();
            learnerReferenceDataProvider.VerifyAll();
            validationErrorCache.VerifyAll();
            validationOutputService.VerifyAll();
            validIlrFileOutputService.VerifyAll();
            messageRuleSetOrchestratonService.VerifyAll();
            crossYearRuleSetOrchestrationService.VerifyAll();
            validationExecutionProvider.VerifyAll();
        }
 public void Populate(IValidationContext validationContext, IMessage message, ReferenceDataRoot referenceDataRoot, LearnerReferenceData learnerReferenceData)
 {
     _messageCachePopulationService.Populate(message);
     _internalDataCachePopulationService.Populate(referenceDataRoot);
     _fileDataCachePopulationService.Populate(validationContext, message);
     _externalDataCachePopulationService.Populate(referenceDataRoot, validationContext);
     _learnerReferenceDataCachePopulationService.Populate(learnerReferenceData);
 }
Exemple #9
0
        public void GetMatchingLearningAimFromPreviousYear_NoMatchFound()
        {
            var learner = new TestLearner
            {
                LearnRefNumber     = "LearnRefNumber1",
                PrevLearnRefNumber = "LearnRefNumber2",
                PrevUKPRNNullable  = 5555,
                ULN = 1,
            };

            var learningDelivery = new TestLearningDelivery
            {
                LearnAimRef      = "LearnAimRef",
                LearnStartDate   = new DateTime(2020, 8, 1),
                FundModel        = 35,
                ProgTypeNullable = 1,
            };

            var previousLearnerData1 = new LearnerReferenceData
            {
                LearnRefNumber   = "LearnRefNumber1",
                PrevUKPRN        = 5555,
                PMUKPRN          = 5555,
                ULN              = 1,
                LearnAimRef      = "LearnAimRef",
                LearnStartDate   = new DateTime(2020, 8, 1),
                FundModel        = 35,
                ProgTypeNullable = 1,
            };

            var previousLearnerData2 = new LearnerReferenceData
            {
                LearnRefNumber   = "LearnRefNumber2",
                PrevUKPRN        = 5555,
                PMUKPRN          = 5555,
                ULN              = 1,
                LearnAimRef      = "LearnAimRef2",
                LearnStartDate   = new DateTime(2020, 8, 1),
                FundModel        = 35,
                ProgTypeNullable = 1,
            };

            var previousLearnerData = new List <LearnerReferenceData>
            {
                previousLearnerData1,
                previousLearnerData2
            };

            var refDataServiceMock = new Mock <ILearnerReferenceDataService>();

            refDataServiceMock.Setup(x => x.GetLearnerDataForPreviousYear(new List <string> {
                learner.LearnRefNumber, learner.PrevLearnRefNumber
            }))
            .Returns(previousLearnerData);

            var fileDataServiceMock = new Mock <IFileDataService>();

            fileDataServiceMock.Setup(x => x.UKPRN()).Returns(12345);

            NewDD(refDataServiceMock.Object, fileDataServiceMock.Object).GetMatchingLearningAimFromPreviousYear(learner, learningDelivery).Should().BeEquivalentTo(previousLearnerData1);
        }