public async Task TestFundingSummaryPeriodEndReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10036143_1_Funding Summary Report {dateTime:yyyyMMdd-HHmmss}";

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10036143);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            IValueProvider valueProvider = new ValueProvider();
            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);

            IIntUtilitiesService      intUtilitiesService      = new IntUtilitiesService();
            IJsonSerializationService jsonSerializationService = new JsonSerializationService();
            IXmlSerializationService  xmlSerializationService  = new XmlSerializationService();

            DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration()
            {
                ILRDataStoreConnectionString      = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString,
                ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString
            };

            IIlr1819ValidContext IlrValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options;

                return(new ILR1819_DataStoreEntitiesValid(options));
            }

            IIlr1819RulebaseContext IlrRulebaseValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options;

                return(new ILR1819_DataStoreEntities(options));
            }

            IIlrProviderService     ilrProviderService     = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseValidContextFactory);
            IFM36ProviderService    fm36ProviderService    = new FM36ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, IlrRulebaseValidContextFactory);
            IStringUtilitiesService stringUtilitiesService = new StringUtilitiesService();

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var fundingSummaryPeriodEndModelBuilder = new FundingSummaryPeriodEndModelBuilder();

            var report = new ReportService.Service.Reports.PeriodEnd.FundingSummaryPeriodEndReport(logger.Object, storage.Object, ilrProviderService, fm36ProviderService, stringUtilitiesService, dateTimeProviderMock.Object, valueProvider, topicsAndTasks, fundingSummaryPeriodEndModelBuilder);

            await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new FundingSummaryPeriodEndMapper(), 1));
        }
Exemple #2
0
        public async Task TestAppsAdditionalPaymentsReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10036143_1_Apps Additional Payments Report {dateTime:yyyyMMdd-HHmmss}";
            int      ukPrn    = 10036143;
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(ukPrn);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock              = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage       = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IIlrProviderService>         ilrProviderServiceMock  = new Mock <IIlrProviderService>();
            Mock <IDASPaymentsProviderService> dasPaymentProviderMock  = new Mock <IDASPaymentsProviderService>();
            Mock <IFM36ProviderService>        fm36ProviderServiceMock = new Mock <IFM36ProviderService>();
            IValueProvider valueProvider = new ValueProvider();
            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);

            var appsAdditionalPaymentIlrInfo         = BuildILRModel(ukPrn);
            var appsAdditionalPaymentRulebaseInfo    = BuildFm36Model(ukPrn);
            var appsAdditionalPaymentDasPaymentsInfo = BuildDasPaymentsModel(ukPrn);

            ilrProviderServiceMock.Setup(x => x.GetILRInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetFM36DataForAppsAdditionalPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentRulebaseInfo);
            dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentDasPaymentsInfo);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var appsAdditionalPaymentsModelBuilder = new AppsAdditionalPaymentsModelBuilder();

            var report = new ReportService.Service.Reports.PeriodEnd.AppsAdditionalPaymentsReport(logger.Object, storage.Object, ilrProviderServiceMock.Object, fm36ProviderServiceMock.Object, dateTimeProviderMock.Object, valueProvider, topicsAndTasks, dasPaymentProviderMock.Object, appsAdditionalPaymentsModelBuilder);

            await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsAdditionalPaymentsMapper(), 1));
        }
Exemple #3
0
        public async Task TestNonContractedAppsActivityReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10036143_1_Non-Contracted Apprenticeships Activity Report {dateTime:yyyyMMdd-HHmmss}";
            int      ukPrn    = 10036143;
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(ukPrn);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IIlrProviderService>   ilrProviderServiceMock  = new Mock <IIlrProviderService>();
            Mock <IFCSProviderService>   fcsProviderMock         = new Mock <IFCSProviderService>();
            Mock <IValidLearnersService> validLearnerServiceMock = new Mock <IValidLearnersService>();
            Mock <ILarsProviderService>  larsProviderServiceMock = new Mock <ILarsProviderService>();
            Mock <IFM36NonContractedActivityProviderService> fm36ProviderServiceMock = new Mock <IFM36NonContractedActivityProviderService>();
            IValueProvider valueProvider = new ValueProvider();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);

            var nonContractedAppsActivityIlrInfo  = BuildIlrModel(ukPrn);
            var nonContractedActivityRuleBaseInfo = BuildFm36Model(ukPrn);
            var contractAllocationInfo            = BuildFcsModel();
            var larsLearningDeliveries            = BuildLarsModel();

            ilrProviderServiceMock.Setup(x => x.GetILRInfoForNonContractedAppsActivityReportAsync(It.IsAny <List <string> >(), reportServiceContextMock.Object, It.IsAny <CancellationToken>())).ReturnsAsync(nonContractedAppsActivityIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetFM36InfoForNonContractedActivityReportAsync(It.IsAny <List <string> >(), reportServiceContextMock.Object, It.IsAny <CancellationToken>())).ReturnsAsync(nonContractedActivityRuleBaseInfo);
            fcsProviderMock
            .Setup(x => x.GetContractAllocationsForProviderAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(contractAllocationInfo);
            larsProviderServiceMock.Setup(x =>
                                          x.GetLearningDeliveriesAsync(It.IsAny <string[]>(), It.IsAny <CancellationToken>())).ReturnsAsync(larsLearningDeliveries);
            validLearnerServiceMock
            .Setup(x => x.GetLearnersAsync(reportServiceContextMock.Object, It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <string>()
            {
                "fm36 18 20"
            });

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var nonContractedAppsActivityModel = new NonContractedAppsActivityModelBuilder(new PeriodProviderService());

            var report = new ReportService.Service.Reports.NonContractedAppsActivityReport(
                logger.Object,
                storage.Object,
                ilrProviderServiceMock.Object,
                fcsProviderMock.Object,
                validLearnerServiceMock.Object,
                fm36ProviderServiceMock.Object,
                larsProviderServiceMock.Object,
                dateTimeProviderMock.Object,
                valueProvider,
                nonContractedAppsActivityModel);

            await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new NonContractedAppsActivityMapper(), 1));
            IEnumerable <NonContractedAppsActivityModel> result;

            using (var reader = new StreamReader($"{filename}.csv"))
            {
                using (var csvReader = new CsvReader(reader))
                {
                    csvReader.Configuration.RegisterClassMap <NonContractedAppsActivityMapper>();
                    result = csvReader.GetRecords <NonContractedAppsActivityModel>().ToList();
                }
            }

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(3);
            result.First().UniqueLearnerNumber.Should().Be(1000000205);
            result.First().AgeAtProgrammeStart.Should().Be(25);
            result.First().AimSeqNumber.Should().Be(1);
            result.First().AimType.Should().Be(1);
            result.First().AppAdjLearnStartDate.Should().Be("01/11/2018");
            result.First().ApprenticeshipPathway.Should().Be(2);
            result.First().CampusIdentifier.Should().Be("ZZ123456");
            result.First().DateOfBirth.Should().Be("15/05/1982");
            result.First().FrameworkCode.Should().Be(563);
            result.First().FundingLineType.Should().Be("19+ Apprenticeship Non-Levy Contract (procured)");
            result.First().LearnerReferenceNumber.Should().Be("fm36 18 20");
            result.First().LearningAimReference.Should().Be("ZPROG001");
            result.First().LearningAimTitle.Should().Be("LearnAimTitle");
            result.First().LearningDeliveryFAMTypeACTDateAppliesFrom.Should().Be("01/01/2019");
            result.First().LearningDeliveryFAMTypeACTDateAppliesTo.Should().Be(string.Empty);
            result.First().LearningDeliveryFAMTypeApprenticeshipContractType.Should().Be("2");
            result.First().LearningPlannedEndDate.Should().Be("31/03/2020");
            result.First().LearningStartDate.Should().Be("01/11/2018");
            result.First().OriginalLearningStartDate.Should().Be("01/11/2018");
            result.First().PriceEpisodeActualEndDate.Should().Be("31/07/2019");
            result.First().ProgrammeType.Should().Be(21);
            result.First().SoftwareSupplierAimIdentifier.Should().Be("83282eb2aa2230439a9964374c163b9c");
            result.First().AugustTotalEarnings.Should().Be(1);
            result.First().SeptemberTotalEarnings.Should().Be(2);
            result.First().OctoberTotalEarnings.Should().Be(3);
            result.First().NovemberTotalEarnings.Should().Be(4);
            result.First().DecemberTotalEarnings.Should().Be(5);
            result.First().JanuaryTotalEarnings.Should().Be(6);
            result.First().FebruaryTotalEarnings.Should().Be(7);
            result.First().MarchTotalEarnings.Should().Be(8);
            result.First().AprilTotalEarnings.Should().Be(9);
            result.First().MayTotalEarnings.Should().Be(10);
            result.First().JuneTotalEarnings.Should().Be(11);
            result.First().JulyTotalEarnings.Should().Be(12);
            result.First().TotalEarnings.Should().Be(78);

            result.ElementAt(1).ProgrammeType.Should().Be(25);
            result.ElementAt(1).StandardCode.Should().Be(23);
            result.ElementAt(1).ApprenticeshipPathway.Should().Be(2);
            result.ElementAt(1).LearningAimReference.Should().Be("50086832");
            result.ElementAt(1).FundingLineType.Should().Be("19+ Apprenticeship (From May 2017) Levy Contract");
            result.ElementAt(1).LearningDeliveryFAMTypeApprenticeshipContractType.Should().Be("1");
            result.ElementAt(1).LearningDeliveryFAMTypeACTDateAppliesFrom.Should().Be("01/11/2018");
            result.ElementAt(1).LearningDeliveryFAMTypeACTDateAppliesTo.Should().Be("31/12/2018");

            result.ElementAt(2).ProgrammeType.Should().Be(25);
            result.ElementAt(2).StandardCode.Should().Be(23);
            result.ElementAt(2).ApprenticeshipPathway.Should().Be(2);
            result.ElementAt(2).LearningAimReference.Should().Be("50086832");
            result.ElementAt(2).FundingLineType.Should().Be("19+ Apprenticeship Non-Levy Contract (procured)");
            result.ElementAt(2).LearningDeliveryFAMTypeApprenticeshipContractType.Should().Be("2");
            result.ElementAt(2).LearningDeliveryFAMTypeACTDateAppliesFrom.Should().Be("01/01/2019");
            result.ElementAt(2).LearningDeliveryFAMTypeACTDateAppliesTo.Should().Be(string.Empty);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new NonContractedAppsActivityMapper(), 1));
        }
Exemple #4
0
        public async Task TestSummaryOfFunding1619ReportGeneration()
        {
            string csv = string.Empty;

            System.DateTime dateTime = System.DateTime.UtcNow;
            string          filename = $"10033670_1_16-19 Summary of Funding by Student Report {dateTime:yyyyMMdd-HHmmss}";

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IKeyValuePersistenceService>           redis   = new Mock <IKeyValuePersistenceService>();
            IIntUtilitiesService      intUtilitiesService        = new IntUtilitiesService();
            IJsonSerializationService jsonSerializationService   = new JsonSerializationService();
            IXmlSerializationService  xmlSerializationService    = new XmlSerializationService();
            DataStoreConfiguration    dataStoreConfiguration     = new DataStoreConfiguration()
            {
                ILRDataStoreConnectionString      = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString,
                ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString
            };

            IIlr1819ValidContext IlrValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options;

                return(new ILR1819_DataStoreEntitiesValid(options));
            }

            IIlr1819RulebaseContext IlrRulebaseContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options;

                return(new ILR1819_DataStoreEntities(options));
            }

            IIlrProviderService ilrProviderService = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10033670);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns("ILR-10033670-1819-20180712-144437-03");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.FundingFM25OutputKey).Returns("FundingFm25Output");

            IValidLearnersService   validLearnersService   = new ValidLearnersService(logger.Object, redis.Object, jsonSerializationService, null);
            IFM25ProviderService    fm25ProviderService    = new FM25ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, IlrRulebaseContextFactory);
            IStringUtilitiesService stringUtilitiesService = new StringUtilitiesService();
            IValueProvider          valueProvider          = new ValueProvider();

            storage.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead("ILR-10033670-1819-20180712-144437-03.xml").CopyTo(sr)).Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);
            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(jsonSerializationService.Serialize(
                                                                                                                  new List <string>
            {
                "0fm2501",
                "3fm9901",
                "5fm9901"
            }));
            redis.Setup(x => x.GetAsync("FundingFm25Output", It.IsAny <CancellationToken>())).ReturnsAsync(File.ReadAllText("Fm25.json"));
            redis.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <System.DateTime>())).Returns(dateTime);

            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();

            SummaryOfFunding1619Report summaryOfFunding1619Report = new SummaryOfFunding1619Report(
                logger.Object,
                storage.Object,
                ilrProviderService,
                validLearnersService,
                fm25ProviderService,
                stringUtilitiesService,
                dateTimeProviderMock.Object,
                valueProvider,
                topicsAndTasks);

            await summaryOfFunding1619Report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new SummaryOfFunding1619Mapper(), 1));
        }
        public async Task TestDataMatchReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10033670_1_Apprenticeship Data Match Report {dateTime:yyyyMMdd-HHmmss}";
            long     ukPrn    = 10033670;
            string   ilr      = "ILR-10033670-1819-20180704-120055-03";
            DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration()
            {
                ILRDataStoreConnectionString      = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString,
                ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString
            };

            IIlr1819ValidContext IlrValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options;

                return(new ILR1819_DataStoreEntitiesValid(options));
            }

            IIlr1819RulebaseContext IlrRulebaseContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options;

                return(new ILR1819_DataStoreEntities(options));
            }

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10033670);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns(ilr);
            reportServiceContextMock.SetupGet(x => x.FundingFM36OutputKey).Returns("FundingFm36Output");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");

            Mock <ILogger> logger = new Mock <ILogger>();
            Mock <IStreamableKeyValuePersistenceService> storage   = new Mock <IStreamableKeyValuePersistenceService>();
            IJsonSerializationService     jsonSerializationService = new JsonSerializationService();
            IIntUtilitiesService          intUtilitiesService      = new IntUtilitiesService();
            IFM36ProviderService          fm36ProviderService      = new FM36FileServiceProvider(logger.Object, storage.Object, jsonSerializationService);
            Mock <IDasCommitmentsService> dasCommitmentsService    = new Mock <IDasCommitmentsService>();
            Mock <IPeriodProviderService> periodProviderService    = new Mock <IPeriodProviderService>();
            Mock <IDateTimeProvider>      dateTimeProviderMock     = new Mock <IDateTimeProvider>();

            List <DasCommitment> dasCommitments = new List <DasCommitment>
            {
                new DasCommitment(new DasCommitments
                {
                    Uln   = 9900001906,
                    Ukprn = ukPrn,
                    //StandardCode = 0,
                    FrameworkCode = 421,      // No match - 420
                    PathwayCode   = 2,        // No match - 1
                    ProgrammeType = 3,        // No match - 2
                    AgreedCost    = 1.80M,    // No match?
                    StartDate     = dateTime, // No match
                    PaymentStatus = (int)PaymentStatus.Active
                })
            };

            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);
            storage.Setup(x => x.GetAsync("FundingFm36Output", It.IsAny <CancellationToken>())).ReturnsAsync(File.ReadAllText("Fm36.json"));
            dasCommitmentsService
            .Setup(x => x.GetCommitments(It.IsAny <long>(), It.IsAny <List <long> >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(dasCommitments);
            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            periodProviderService.Setup(x => x.MonthFromPeriod(It.IsAny <int>())).Returns(1);

            IValueProvider valueProvider = new ValueProvider();
            IValidationStageOutputCache      validationStageOutputCache      = new ValidationStageOutputCache();
            IDatalockValidationResultBuilder datalockValidationResultBuilder = new DatalockValidationResultBuilder();
            ITotalBuilder totalBuilder = new TotalBuilder();

            var report = new DataMatchReport(
                logger.Object,
                fm36ProviderService,
                dasCommitmentsService.Object,
                periodProviderService.Object,
                storage.Object,
                dateTimeProviderMock.Object,
                valueProvider,
                validationStageOutputCache,
                datalockValidationResultBuilder,
                totalBuilder);

            await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new DataMatchReportMapper(), 1));
        }
        public async Task TestDataMatchReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10033670_1_Apprenticeship Data Match Report {dateTime:yyyyMMdd-HHmmss}.csv";
            int      ukPrn    = 10033670;

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10033670);
            reportServiceContextMock.SetupGet(x => x.IsIlrSubmission).Returns(true);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IDASPaymentsProviderService>           dasPaymentProviderMock = new Mock <IDASPaymentsProviderService>();
            Mock <IILRProviderService>     iIlrProviderService   = new Mock <IILRProviderService>();
            IExternalDataMatchModelBuilder dataMatchModelBuilder = new ExternalDataMatchMonthEndModelBuilder(new DataLockValidationMessageService(), logger.Object);

            storage.Setup(x => x.SaveAsync(filename, It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((key, value, ct) => csv = value)
            .Returns(Task.CompletedTask);

            var ilrModelForDataMatchReport = BuildILRModelForDataMatchReport(ukPrn);
            var dataMatchRulebaseInfo      = BuildFm36Model(ukPrn);

            var dasApprenticeshipInfoForDataMatchReport       = GetDasApprenticeshipInfoForDataMatchReport(ukPrn);
            var dataLockValidationErrorInfoForDataMatchReport = GetDataLockValidationErrorInfoForDataMatchReport(ukPrn);

            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            storage.Setup(x => x.SaveAsync(filename, It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((key, value, ct) => csv = value)
            .Returns(Task.CompletedTask);

            iIlrProviderService
            .Setup(x => x.GetFM36DataForDataMatchReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(dataMatchRulebaseInfo);
            iIlrProviderService
            .Setup(x => x.GetILRInfoForDataMatchReportAsync(It.IsAny <int>(), It.IsAny <List <long> >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(ilrModelForDataMatchReport);
            dasPaymentProviderMock.Setup(x =>
                                         x.GetDasApprenticeshipInfoForDataMatchReport(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(dasApprenticeshipInfoForDataMatchReport);

            dasPaymentProviderMock.Setup(x => x.GetDataLockValidationErrorInfoForUkprnAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(dataLockValidationErrorInfoForDataMatchReport);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);

            var report = new ExternalDataMatchReport(
                dasPaymentProviderMock.Object,
                iIlrProviderService.Object,
                storage.Object,
                dataMatchModelBuilder,
                dateTimeProviderMock.Object,
                new ExternalDataMatchModelComparer(),
                logger.Object);

            await report.GenerateReport(reportServiceContextMock.Object, null, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText(filename, csv);
            IEnumerable <DataMatchModel> result;

            TestCsvHelper.CheckCsv(csv, new CsvEntry(new ExternalDataMatchMapper(), 1));
            using (var reader = new StreamReader(filename))
            {
                using (var csvReader = new CsvReader(reader))
                {
                    csvReader.Configuration.RegisterClassMap <ExternalDataMatchMapper>();
                    result = csvReader.GetRecords <DataMatchModel>().ToList();
                }
            }

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(1);
        }
        public async Task TestAppsAdditionalPaymentsReportGeneration(
            string employerName,
            string employerNameExpected,
            string ilrLearnRefNumber,
            string ilrLearnAimRef,
            string dasLearnRefNumber,
            string dasLearnAimRef,
            string provSpecLearnMonOccurA,
            string provSpecLearnMonOccurB)
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"R01_10036143_10036143 Apps Additional Payments Report {dateTime:yyyyMMdd-HHmmss}";
            int      ukPrn    = 10036143;
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(ukPrn);
            reportServiceContextMock.SetupGet(x => x.ReturnPeriod).Returns(1);
            reportServiceContextMock.SetupGet(x => x.ReturnPeriodName).Returns("R01");

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IIlrPeriodEndProviderService>          ilrPeriodEndProviderServiceMock = new Mock <IIlrPeriodEndProviderService>();
            Mock <IDASPaymentsProviderService>           dasPaymentProviderMock          = new Mock <IDASPaymentsProviderService>();
            Mock <IFM36PeriodEndProviderService>         fm36ProviderServiceMock         = new Mock <IFM36PeriodEndProviderService>();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((key, value, ct) => csv = value)
            .Returns(Task.CompletedTask);

            var appsAdditionalPaymentIlrInfo         = BuildILRModel(ukPrn, ilrLearnRefNumber, ilrLearnAimRef, provSpecLearnMonOccurA, provSpecLearnMonOccurB);
            var rulebaseLearningDeliveries           = BuildRulebaseLearningDeliveries();
            var rulebasePriceEpisodes                = BuildRulebasePriceEpisodes(ukPrn);
            var appsAdditionalPaymentDasPaymentsInfo = BuildDasPaymentsModel(ukPrn, employerName, dasLearnRefNumber, dasLearnAimRef);
            var legalEntityNameDictionary            = BuildLegalEntityNameDictionary(employerName);

            ilrPeriodEndProviderServiceMock.Setup(x => x.GetILRInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(appsAdditionalPaymentIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetLearningDeliveriesForAppsAdditionalPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(rulebaseLearningDeliveries);
            fm36ProviderServiceMock.Setup(x => x.GetApprenticeshipPriceEpisodesForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(rulebasePriceEpisodes);
            dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(appsAdditionalPaymentDasPaymentsInfo);
            dasPaymentProviderMock
            .Setup(x => x.GetLegalEntityNameApprenticeshipIdDictionaryAsync(It.IsAny <IEnumerable <long?> >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(legalEntityNameDictionary);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var appsAdditionalPaymentsModelBuilder          = new AppsAdditionalPaymentsModelBuilder();
            Mock <IPersistReportData> persistReportDataMock = new Mock <IPersistReportData>();

            var report = new AppsAdditionalPaymentsReport(
                logger.Object,
                storage.Object,
                ilrPeriodEndProviderServiceMock.Object,
                fm36ProviderServiceMock.Object,
                dateTimeProviderMock.Object,
                dasPaymentProviderMock.Object,
                appsAdditionalPaymentsModelBuilder,
                persistReportDataMock.Object);

            await report.GenerateReport(reportServiceContextMock.Object, null, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsAdditionalPaymentsMapper(), 1));
            IEnumerable <AppsAdditionalPaymentsModel> result;

            using (var csvReader = new CsvReader(new StringReader(csv)))
            {
                csvReader.Configuration.TypeConverterOptionsCache.GetOptions <DateTime>().Formats  = new[] { "dd/MM/yyyy" };
                csvReader.Configuration.TypeConverterOptionsCache.GetOptions <DateTime?>().Formats = new[] { "dd/MM/yyyy" };

                csvReader.Configuration.RegisterClassMap <AppsAdditionalPaymentsMapper>();
                result = csvReader.GetRecords <AppsAdditionalPaymentsModel>().ToList();
            }

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(1);
            result.First().AugustEarnings.Should().Be(10);
            result.First().JulyEarnings.Should().Be(120);
            result.First().TotalEarnings.Should().Be(780);
            result.First().TotalPaymentsYearToDate.Should().Be(20);
            result.First().UniqueLearnerNumber.Should().Be(12345);
            result.First().EmployerNameFromApprenticeshipService.Should().Be(employerNameExpected);
        }
        public async Task TestAppsMonthlyPaymentReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            int      ukPrn    = 10036143;
            string   filename = $"10036143_1_Apps Monthly Payment Report {dateTime:yyyyMMdd-HHmmss}";

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10036143);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IIlrPeriodEndProviderService>          IlrPeriodEndProviderServiceMock = new Mock <IIlrPeriodEndProviderService>();
            Mock <IDASPaymentsProviderService>           dasPaymentProviderMock          = new Mock <IDASPaymentsProviderService>();
            Mock <IFM36PeriodEndProviderService>         fm36ProviderServiceMock         = new Mock <IFM36PeriodEndProviderService>();
            Mock <ILarsProviderService> larsProviderServiceMock = new Mock <ILarsProviderService>();
            IValueProvider valueProvider = new ValueProvider();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);

            var appsMonthlyPaymentIlrInfo      = BuildILRModel(ukPrn);
            var appsMonthlyPaymentRulebaseInfo = BuildFm36Model(ukPrn);
            var appsMonthlyPaymentDasInfo      = BuildDasPaymentsModel(ukPrn);
            var larsDeliveryInfoModel          = BuildLarsDeliveryInfoModel();

            IlrPeriodEndProviderServiceMock.Setup(x => x.GetILRInfoForAppsMonthlyPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsMonthlyPaymentIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetFM36DataForAppsMonthlyPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsMonthlyPaymentRulebaseInfo);
            dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsMonthlyPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsMonthlyPaymentDasInfo);
            larsProviderServiceMock.Setup(x => x.GetLarsLearningDeliveryInfoForAppsMonthlyPaymentReportAsync(It.IsAny <string[]>(), It.IsAny <CancellationToken>())).ReturnsAsync(larsDeliveryInfoModel);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var appsMonthlyPaymentModelBuilder = new AppsMonthlyPaymentModelBuilder();

            var report = new ReportService.Service.Reports.PeriodEnd.AppsMonthlyPaymentReport(
                logger.Object,
                storage.Object,
                IlrPeriodEndProviderServiceMock.Object,
                fm36ProviderServiceMock.Object,
                dasPaymentProviderMock.Object,
                larsProviderServiceMock.Object,
                dateTimeProviderMock.Object,
                valueProvider,
                appsMonthlyPaymentModelBuilder);

            await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            IEnumerable <AppsMonthlyPaymentModel> result;

            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsMonthlyPaymentMapper(), 1));
            using (var reader = new StreamReader($"{filename}.csv"))
            {
                using (var csvReader = new CsvReader(reader))
                {
                    csvReader.Configuration.RegisterClassMap <AppsMonthlyPaymentMapper>();
                    result = csvReader.GetRecords <AppsMonthlyPaymentModel>().ToList();
                }
            }

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(1);
            result.First().LearnerReferenceNumber.Should().Be("A12345");
            result.First().UniqueLearnerNumber.Should().Be(12345);
            result.First().CampusIdentifier.Should().Be("camp101");
            result.First().AimSeqNumber.Should().Be(1);
            result.First().LearningAimReference.Should().Be("50117889");
            result.First().LearningStartDate.Should().Be("28/06/2017");
            result.First().LearningAimProgrammeType.Should().Be(1);
            result.First().LearningAimStandardCode.Should().Be(1);
            result.First().LearningAimFrameworkCode.Should().Be(1);
            result.First().LearningAimPathwayCode.Should().Be(1);
            result.First().AimType.Should().Be(3);
            result.First().FundingLineType.Should().Be("16-18 Apprenticeship Non-Levy");
            result.First().LearningDeliveryFAMTypeApprenticeshipContractType.Should().Be(2);
            result.First().AugustLevyPayments.Should().Be(11);
            result.First().AugustCoInvestmentPayments.Should().Be(12);
            result.First().AugustTotalPayments.Should().Be(116);
            result.First().TotalLevyPayments.Should().Be(143);
            result.First().TotalCoInvestmentPayments.Should().Be(156);
            result.First().TotalCoInvestmentDueFromEmployerPayments.Should().Be(169);
            result.First().TotalEmployerAdditionalPayments.Should().Be(182);
            result.First().TotalProviderAdditionalPayments.Should().Be(195);
            result.First().TotalApprenticeAdditionalPayments.Should().Be(208);
            result.First().TotalEnglishAndMathsPayments.Should().Be(221);
            result.First().TotalPaymentsForLearningSupport.Should().Be(234);
            result.First().TotalPayments.Should().Be(1508);
            result.First().LearningAimTitle.Should().Be("Maths & English");
        }
Exemple #9
0
        public async Task TestAppsIndicativeEarningsReportGeneration(string ilrFile, string fm36Output)
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10033670_1_Apps Indicative Earnings Report {dateTime:yyyyMMdd-HHmmss}";
            string   ilr      = ilrFile;
            DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration()
            {
                ILRDataStoreConnectionString      = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString,
                ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString
            };

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10033670);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns(ilr);
            reportServiceContextMock.SetupGet(x => x.FundingFM36OutputKey).Returns("FundingFm36Output");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            IIntUtilitiesService      intUtilitiesService        = new IntUtilitiesService();
            IJsonSerializationService jsonSerializationService   = new JsonSerializationService();
            IXmlSerializationService  xmlSerializationService    = new XmlSerializationService();

            IIlr1819ValidContext IlrValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options;

                return(new ILR1819_DataStoreEntitiesValid(options));
            }

            IIlr1819RulebaseContext IlrRulebaseContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options;

                return(new ILR1819_DataStoreEntities(options));
            }

            IIlrProviderService     ilrProviderService = new IlrFileServiceProvider(logger.Object, storage.Object, xmlSerializationService); Mock <ILarsProviderService> larsProviderService = new Mock <ILarsProviderService>();
            IValidLearnersService   validLearnersService   = new ValidLearnersService(logger.Object, storage.Object, jsonSerializationService, dataStoreConfiguration);
            IFM36ProviderService    fm36ProviderService    = new FM36FileServiceProvider(logger.Object, storage.Object, jsonSerializationService);
            IStringUtilitiesService stringUtilitiesService = new StringUtilitiesService();
            ITotalBuilder           totalBuilder           = new TotalBuilder();

            List <IAppsIndicativeCommand> commands = new List <IAppsIndicativeCommand>()
            {
                new AppsIndicativeAugustCommand()
            };

            AppsIndicativeEarningsModelBuilder builder = new AppsIndicativeEarningsModelBuilder(commands, totalBuilder, stringUtilitiesService);

            storage.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead($"{ilr}.xml").CopyTo(sr)).Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);
            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            storage.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(jsonSerializationService.Serialize(
                                                                                                                    new List <string>
            {
                "3DOB01",
                "0fm3501",
                "1fm3501",
                "2fm3501",
                "3fm3501",
                "4fm3501",
                "5fm3501",
                "6fm3501",
                "7fm3501",
                "8fm3501",
                "9fm3501",
                "Afm3501",
                "Bfm3501",
                "Cfm3501",
                "Dfm3501",
                "Efm3501",
                "0fm3601",
                "0DOB52",
                "fm36 18 20"
            }));
            storage.Setup(x => x.ContainsAsync("ValidLearners", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            storage.Setup(x => x.ContainsAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            storage.Setup(x => x.ContainsAsync("FundingFm36Output", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            storage.Setup(x => x.GetAsync("FundingFm36Output", It.IsAny <CancellationToken>())).ReturnsAsync(File.ReadAllText(fm36Output));
            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);

            IMessage message = await ilrProviderService.GetIlrFile(reportServiceContextMock.Object, CancellationToken.None);

            string validLearners = await storage.Object.GetAsync("ValidLearnRefNumbers");

            Dictionary <string, LarsLearningDelivery> learningDeliveriesDict = new Dictionary <string, LarsLearningDelivery>();

            foreach (ILearner messageLearner in message.Learners)
            {
                if (!validLearners.Contains(messageLearner.LearnRefNumber))
                {
                    continue;
                }

                foreach (ILearningDelivery learningDelivery in messageLearner.LearningDeliveries)
                {
                    learningDeliveriesDict[learningDelivery.LearnAimRef] = new LarsLearningDelivery()
                    {
                        LearningAimTitle       = "A",
                        NotionalNvqLevel       = "B",
                        Tier2SectorSubjectArea = 3
                    };
                }
            }

            larsProviderService.Setup(x => x.GetLearningDeliveriesAsync(It.IsAny <string[]>(), It.IsAny <CancellationToken>())).ReturnsAsync(learningDeliveriesDict);
            larsProviderService.Setup(x => x.GetStandardAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync("NotionalEndLevel");

            IValueProvider valueProvider = new ValueProvider();

            var report = new AppsIndicativeEarningsReport(
                logger.Object,
                storage.Object,
                ilrProviderService,
                validLearnersService,
                fm36ProviderService,
                larsProviderService.Object,
                builder,
                dateTimeProviderMock.Object,
                valueProvider);

            await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsIndicativeEarningsMapper(), 1));
        }
        public async Task TestValidationReportGeneration()
        {
            string csv  = string.Empty;
            string json = string.Empty;

            byte[]   xlsx        = null;
            DateTime dateTime    = DateTime.UtcNow;
            string   filename    = $"10000020_1_Rule Violation Report {dateTime:yyyyMMdd-HHmmss}";
            string   ilrFilename = @"Reports\Validation\ILR-10000020-1819-20181005-120953-03.xml";

            Mock <ILogger> logger = new Mock <ILogger>();
            Mock <IStreamableKeyValuePersistenceService> storage        = new Mock <IStreamableKeyValuePersistenceService>();
            IXmlSerializationService        xmlSerializationService     = new XmlSerializationService();
            IJsonSerializationService       jsonSerializationService    = new JsonSerializationService();
            Mock <IDateTimeProvider>        dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            IValueProvider                  valueProvider               = new ValueProvider();
            IIntUtilitiesService            intUtilitiesService         = new IntUtilitiesService();
            Mock <IValidationErrorsService> validationErrorsServiceMock = new Mock <IValidationErrorsService>();

            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            storage.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(File.ReadAllText(ilrFilename));
            storage.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead(ilrFilename).CopyTo(sr)).Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv   = value).Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.json", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => json = value).Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.xlsx", It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>(
                (key, value, ct) =>
            {
                value.Seek(0, SeekOrigin.Begin);
                using (MemoryStream ms = new MemoryStream())
                {
                    value.CopyTo(ms);
                    xlsx = ms.ToArray();
                }
            })
            .Returns(Task.CompletedTask);
            storage.Setup(x => x.GetAsync("ValidationErrors", It.IsAny <CancellationToken>())).ReturnsAsync(File.ReadAllText(@"Reports\Validation\ValidationErrors.json"));
            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            validationErrorsServiceMock.Setup(x => x.PopulateValidationErrors(It.IsAny <string[]>(), It.IsAny <List <ValidationErrorDetails> >(), It.IsAny <CancellationToken>())).Callback <string[], List <ValidationErrorDetails>, CancellationToken>(
                (s, v, c) =>
            {
                List <ValidationErrorDetails> validationErrorDetails = jsonSerializationService.Deserialize <List <ValidationErrorDetails> >(File.ReadAllText(@"Reports\Validation\ValidationErrorsLookup.json"));
                foreach (ValidationErrorDetails veds in v)
                {
                    ValidationErrorDetails rule = validationErrorDetails.SingleOrDefault(x => string.Equals(x.RuleName, veds.RuleName, StringComparison.OrdinalIgnoreCase));
                    if (rule != null)
                    {
                        veds.Message  = rule.Message;
                        veds.Severity = rule.Severity;
                    }
                }
            }).Returns(Task.CompletedTask);

            IIlrProviderService ilrProviderService = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, null, null);

            ITopicAndTaskSectionOptions topicsAndTasks             = TestConfigurationHelper.GetTopicsAndTasks();
            IValidationStageOutputCache validationStageOutputCache = new ValidationStageOutputCache();

            IReport validationErrorsReport = new ValidationErrorsReport(
                logger.Object,
                storage.Object,
                jsonSerializationService,
                ilrProviderService,
                dateTimeProviderMock.Object,
                valueProvider,
                topicsAndTasks,
                validationErrorsServiceMock.Object,
                validationStageOutputCache);

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10000020);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns(@"Reports\Validation\" + Path.GetFileNameWithoutExtension(ilrFilename));
            reportServiceContextMock.SetupGet(x => x.ValidationErrorsKey).Returns("ValidationErrors");
            reportServiceContextMock.SetupGet(x => x.ValidationErrorsLookupsKey).Returns("ValidationErrorsLookup");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersCount).Returns(2);
            reportServiceContextMock.SetupGet(x => x.InvalidLearnRefNumbersCount).Returns(3);
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

            await validationErrorsReport.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            json.Should().NotBeNullOrEmpty();
            csv.Should().NotBeNullOrEmpty();
            xlsx.Should().NotBeNullOrEmpty();

#if DEBUG
            File.WriteAllBytes($"{filename}.xlsx", xlsx);
#endif

            ValidationErrorMapper helper = new ValidationErrorMapper();
            TestCsvHelper.CheckCsv(csv, new CsvEntry(helper, 1));
            TestXlsxHelper.CheckXlsx(xlsx, new XlsxEntry(helper, 5));
        }
Exemple #11
0
        public async Task TestSummaryOfFM35FundingReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10033670_1_Summary of Funding Model 35 Funding Report {dateTime:yyyyMMdd-HHmmss}";

            byte[] xlsx = null;

            Mock <ILogger> logger = new Mock <ILogger>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IStreamableKeyValuePersistenceService> redis   = new Mock <IStreamableKeyValuePersistenceService>();
            IJsonSerializationService jsonSerializationService   = new JsonSerializationService();
            IXmlSerializationService  xmlSerializationService    = new XmlSerializationService();
            Mock <IDateTimeProvider>  dateTimeProviderMock       = new Mock <IDateTimeProvider>();

            Mock <ILarsProviderService>          larsProviderService          = new Mock <ILarsProviderService>();
            Mock <IOrgProviderService>           orgProviderService           = new Mock <IOrgProviderService>();
            Mock <IPostcodeProviderService>      postcodeProverServiceMock    = new Mock <IPostcodeProviderService>();
            Mock <ILargeEmployerProviderService> largeEmployerProviderService = new Mock <ILargeEmployerProviderService>();

            ITotalBuilder  totalBuilder  = new TotalBuilder();
            IFm35Builder   fm35Builder   = new Fm35Builder(totalBuilder, new CacheProviderService <LearningDelivery[]>());
            IValueProvider valueProvider = new ValueProvider();
            IVersionInfo   versionInfo   = new VersionInfo {
                ServiceReleaseVersion = "1.2.3.4.5"
            };

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10033670);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns("ILR-10033670-1819-20180704-120055-03");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.FundingFM35OutputKey).Returns("FundingFm35Output");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

            redis.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(File.ReadAllText("ValidLearnRefNumbers.json"));
            redis.Setup(x => x.GetAsync("FundingFm35Output", It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead("Fm35.json").CopyTo(sr)).Returns(Task.CompletedTask);

            storage.Setup(x => x.GetAsync("ILR-10033670-1819-20180704-120055-03", It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead("ILR-10033670-1819-20180704-120055-03.xml").CopyTo(sr)).Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.xlsx", It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>(
                (key, value, ct) =>
            {
                value.Seek(0, SeekOrigin.Begin);
                using (MemoryStream ms = new MemoryStream())
                {
                    value.CopyTo(ms);
                    xlsx = ms.ToArray();
                }
            })
            .Returns(Task.CompletedTask);
            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            largeEmployerProviderService.Setup(x => x.GetVersionAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync("NA");
            postcodeProverServiceMock.Setup(x => x.GetVersionAsync(It.IsAny <CancellationToken>())).ReturnsAsync("NA");
            orgProviderService.Setup(x => x.GetProviderName(It.IsAny <IReportServiceContext>(), It.IsAny <CancellationToken>())).ReturnsAsync("Test Provider");
            larsProviderService.Setup(x => x.GetVersionAsync(It.IsAny <CancellationToken>())).ReturnsAsync("1.2.3.4.5");

            DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration()
            {
                ILRDataStoreConnectionString      = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString,
                ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString
            };

            IIlr1819ValidContext IlrValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options;

                return(new ILR1819_DataStoreEntitiesValid(options));
            }

            IIlr1819RulebaseContext IlrRulebaseContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options;

                return(new ILR1819_DataStoreEntities(options));
            }

            IIlrProviderService         ilrProviderService         = new IlrFileServiceProvider(logger.Object, storage.Object, xmlSerializationService);
            IIlrMetadataProviderService ilrMetadataProviderService = new IlrMetadataProviderService(dateTimeProviderMock.Object, IlrValidContextFactory, IlrRulebaseContextFactory);

            IFM35ProviderService fm35ProviderService = new FM35ProviderService(logger.Object, redis.Object, jsonSerializationService, null, null);

            var summaryOfFm35FundingReport = new SummaryOfFm35FundingReport(
                logger.Object,
                storage.Object,
                ilrProviderService,
                ilrMetadataProviderService,
                fm35ProviderService,
                dateTimeProviderMock.Object,
                valueProvider,
                versionInfo,
                larsProviderService.Object,
                postcodeProverServiceMock.Object,
                largeEmployerProviderService.Object,
                orgProviderService.Object,
                fm35Builder);

            await summaryOfFm35FundingReport.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            xlsx.Should().NotBeNullOrEmpty();
#if DEBUG
            File.WriteAllBytes($"{filename}.csv", Encoding.ASCII.GetBytes(csv));
            File.WriteAllBytes($"{filename}.xlsx", xlsx);
#endif

            TestCsvHelper.CheckCsv(csv, new CsvEntry(new SummaryOfFM35FundingMapper(), 1));
        }
        //[Theory]
        //[InlineData("EMPLOYER2", "EMPLOYER2", "A12345", "ZPROG001", "A12345", "ZPROG001")]
        public async Task TestCoInvestmentContributionsReportGeneration(
            string employerName,
            string employerNameExpected,
            string ilrLearnRefNumber,
            string ilrLearnAimRef,
            string dasLearnRefNumber,
            string dasLearnAimRef)
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10036143 Apps Co-Investment Contributions Report {dateTime:yyyyMMdd-HHmmss}";
            int      ukPrn    = 10036143;
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(ukPrn);
            reportServiceContextMock.SetupGet(x => x.ReturnPeriod).Returns(1);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IIlrPeriodEndProviderService>          ilrPeriodEndProviderServiceMock = new Mock <IIlrPeriodEndProviderService>();
            Mock <IDASPaymentsProviderService>           dasPaymentProviderMock          = new Mock <IDASPaymentsProviderService>();
            Mock <IFM36PeriodEndProviderService>         fm36ProviderServiceMock         = new Mock <IFM36PeriodEndProviderService>();
            Mock <IPersistReportData> persistReportDataMock = new Mock <IPersistReportData>();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((key, value, ct) => csv = value)
            .Returns(Task.CompletedTask);

            var appsCoInvestmentIlrInfo         = BuildILRModel(ukPrn, ilrLearnRefNumber, ilrLearnAimRef, 1);
            var appsCoInvestmentRulebaseInfo    = BuildFm36Model(ukPrn, ilrLearnRefNumber, 1, ilrLearnAimRef);
            var appsCoInvestmentDasPaymentsInfo = BuildDasPaymentsModel(ukPrn, employerName, dasLearnRefNumber, dasLearnAimRef);

            ilrPeriodEndProviderServiceMock.Setup(x => x.GetILRInfoForAppsCoInvestmentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(appsCoInvestmentIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetFM36DataForAppsCoInvestmentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(appsCoInvestmentRulebaseInfo);
            dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsCoInvestmentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(appsCoInvestmentDasPaymentsInfo);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var appsCoInvestmentContributionsModelBuilder = new AppsCoInvestmentContributionsModelBuilder(new AppsCoInvestmentRecordKeyEqualityComparer(), logger.Object);

            var report = new AppsCoInvestmentContributionsReport(
                logger.Object,
                storage.Object,
                dateTimeProviderMock.Object,
                ilrPeriodEndProviderServiceMock.Object,
                dasPaymentProviderMock.Object,
                fm36ProviderServiceMock.Object,
                appsCoInvestmentContributionsModelBuilder,
                persistReportDataMock.Object);

            await report.GenerateReport(reportServiceContextMock.Object, null, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsCoInvestmentContributionsMapper(), 1));
            IEnumerable <AppsCoInvestmentContributionsModel> result;

            using (var csvReader = new CsvReader(new StringReader(csv)))
            {
                csvReader.Configuration.RegisterClassMap <AppsCoInvestmentContributionsMapper>();
                result = csvReader.GetRecords <AppsCoInvestmentContributionsModel>().ToList();
            }

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(1);
            result.First().CoInvestmentDueFromEmployerForAugust.Should().Be(20);
            result.First().CompletionPaymentsThisFundingYear.Should().Be(20);

            result.First().UniqueLearnerNumber.Should().Be(12345);
            result.First().EmployerNameFromApprenticeshipService.Should().Be(employerNameExpected);
        }
Exemple #13
0
        public async Task TestAllbOccupancyReportGeneration(string ilr, string alb, string validLearners)
        {
            string csv = string.Empty;

            System.DateTime dateTime = System.DateTime.UtcNow;
            string          filename = $"10033670_1_ALLB Occupancy Report {dateTime:yyyyMMdd-HHmmss}";

            Mock <ILogger> logger = new Mock <ILogger>();

            Mock <IStreamableKeyValuePersistenceService> storage  = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IStreamableKeyValuePersistenceService> redis    = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IDateTimeProvider>     dateTimeProviderMock     = new Mock <IDateTimeProvider>();
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();
            IIntUtilitiesService         intUtilitiesService      = new IntUtilitiesService();
            IXmlSerializationService     xmlSerializationService  = new XmlSerializationService();
            IJsonSerializationService    jsonSerializationService = new JsonSerializationService();

            storage.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead($@"Reports\ALB\{ilr}").CopyTo(sr)).Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);
            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);

            redis.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("FundingALBOutputKey", It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead("ALBOutput1000.json").CopyTo(sr)).Returns(Task.CompletedTask);
            redis.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(File.ReadAllText($@"Reports\ALB\{validLearners}"));
            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <System.DateTime>())).Returns(dateTime);

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10033670);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns(ilr.Replace(".xml", string.Empty));
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.FundingALBOutputKey).Returns("FundingAlbOutput");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

            IIlrProviderService ilrProviderService = new IlrFileServiceProvider(logger.Object, storage.Object, xmlSerializationService);

            ILarsProviderService larsProviderService = new LarsProviderService(logger.Object, new LarsConfiguration
            {
                LarsConnectionString = ConfigurationManager.AppSettings["LarsConnectionString"]
            });

            IAllbProviderService allbProviderService = new AllbProviderService(logger.Object, redis.Object, jsonSerializationService, null, null);

            IValidLearnersService validLearnersService = new ValidLearnersService(logger.Object, redis.Object, jsonSerializationService, null);

            IStringUtilitiesService stringUtilitiesService = new StringUtilitiesService();

            IValueProvider valueProvider = new ValueProvider();

            IReport allbOccupancyReport = new AllbOccupancyReport(
                logger.Object,
                storage.Object,
                ilrProviderService,
                larsProviderService,
                allbProviderService,
                validLearnersService,
                stringUtilitiesService,
                dateTimeProviderMock.Object,
                valueProvider);

            await allbOccupancyReport.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
#if DEBUG
            File.WriteAllText($"{reportServiceContextMock.Object.Filename}.csv", csv);
#endif
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AllbOccupancyMapper(), 1));
        }
        public async Task TestAllbOccupancyReportGeneration()
        {
            string csv = string.Empty;

            System.DateTime dateTime = System.DateTime.UtcNow;
            string          filename = $"10033670_1_ALLB Occupancy Report {dateTime:yyyyMMdd-HHmmss}";

            Mock <ILogger> logger = new Mock <ILogger>();

            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IStreamableKeyValuePersistenceService> redis   = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IDateTimeProvider>  dateTimeProviderMock       = new Mock <IDateTimeProvider>();
            IXmlSerializationService  xmlSerializationService    = new XmlSerializationService();
            IJsonSerializationService jsonSerializationService   = new JsonSerializationService();
            IIntUtilitiesService      intUtilitiesService        = new IntUtilitiesService();

            storage.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead("ILR-10033670-1819-20180704-120055-03.xml").CopyTo(sr)).Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);
            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);

            redis.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("FundingALBOutputKey", It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead("ALBOutput1000.json").CopyTo(sr)).Returns(Task.CompletedTask);
            redis.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(jsonSerializationService.Serialize(
                                                                                                                  new List <string>
            {
                "3Addl103",
                "4Addl103"
            }));
            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration()
            {
                ILRDataStoreConnectionString      = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString,
                ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString
            };

            IIlr1819ValidContext IlrValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options;

                return(new ILR1819_DataStoreEntitiesValid(options));
            }

            IIlr1819RulebaseContext IlrRulebaseContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options;

                return(new ILR1819_DataStoreEntities(options));
            }

            IIlrProviderService         ilrProviderService  = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);
            Mock <ILarsProviderService> larsProviderService = new Mock <ILarsProviderService>();

            larsProviderService.Setup(x => x.GetLearningDeliveriesAsync(It.IsAny <string[]>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new Dictionary <string, LarsLearningDelivery>()
            {
                { "60133533", new LarsLearningDelivery {
                      LearningAimTitle = "A", NotionalNvqLevel = "B", Tier2SectorSubjectArea = 3
                  } }
            });

            IAllbProviderService allbProviderService = new AllbProviderService(logger.Object, redis.Object, jsonSerializationService, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10033670);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns("ILR-10033670-1819-20180704-120055-03");
            reportServiceContextMock.SetupGet(x => x.FundingALBOutputKey).Returns("FundingAlbOutput");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");

            IValidLearnersService validLearnersService = new ValidLearnersService(logger.Object, redis.Object, jsonSerializationService, null);

            IStringUtilitiesService stringUtilitiesService = new StringUtilitiesService();

            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();

            IValueProvider valueProvider = new ValueProvider();

            IReport allbOccupancyReport = new AllbOccupancyReport(
                logger.Object,
                storage.Object,
                ilrProviderService,
                larsProviderService.Object,
                allbProviderService,
                validLearnersService,
                stringUtilitiesService,
                dateTimeProviderMock.Object,
                valueProvider,
                topicsAndTasks);

            await allbOccupancyReport.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AllbOccupancyMapper(), 1));
        }
        public async Task TestMainOccupancyReportGeneration(string ilrFilename, string validLearnRefNumbersFilename, string albFilename, string fm25Filename, string fm35Filename)
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10033670_1_Main Occupancy Report {dateTime:yyyyMMdd-HHmmss}";

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10033670);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns(ilrFilename);
            reportServiceContextMock.SetupGet(x => x.FundingFM25OutputKey).Returns("FundingFm25Output");
            reportServiceContextMock.SetupGet(x => x.FundingFM35OutputKey).Returns("FundingFm35Output");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

            DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration()
            {
                ILRDataStoreConnectionString      = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString,
                ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString
            };

            IIlr1819ValidContext IlrValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options;

                return(new ILR1819_DataStoreEntitiesValid(options));
            }

            IIlr1819RulebaseContext IlrRulebaseContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options;

                return(new ILR1819_DataStoreEntities(options));
            }

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock             = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage      = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IStreamableKeyValuePersistenceService> redis        = new Mock <IStreamableKeyValuePersistenceService>();
            IIntUtilitiesService             intUtilitiesService      = new IntUtilitiesService();
            IJsonSerializationService        jsonSerializationService = new JsonSerializationService();
            IXmlSerializationService         xmlSerializationService  = new XmlSerializationService();
            IFM35ProviderService             fm35ProviderService      = new FM35ProviderService(logger.Object, redis.Object, jsonSerializationService, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);
            IFM25ProviderService             fm25ProviderService      = new FM25ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, IlrRulebaseContextFactory);
            IIlrProviderService              ilrProviderService       = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);
            IValidLearnersService            validLearnersService     = new ValidLearnersService(logger.Object, redis.Object, jsonSerializationService, dataStoreConfiguration);
            Mock <ILarsProviderService>      larsProviderService      = new Mock <ILarsProviderService>();
            IStringUtilitiesService          stringUtilitiesService   = new StringUtilitiesService();
            ITopicAndTaskSectionOptions      topicsAndTasks           = TestConfigurationHelper.GetTopicsAndTasks();
            IMainOccupancyReportModelBuilder reportModelBuilder       = new MainOccupancyReportModelBuilder();
            IValueProvider valueProvider = new ValueProvider();

            var validLearnersStr = File.ReadAllText(validLearnRefNumbersFilename);

            storage.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead(ilrFilename).CopyTo(sr))
            .Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((key, value, ct) => csv = value)
            .Returns(Task.CompletedTask);
            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);

            redis.Setup(x => x.ContainsAsync("FundingFm35Output", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("FundingFm35Output", It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead(fm35Filename).CopyTo(sr)).Returns(Task.CompletedTask);
            storage.Setup(x => x.ContainsAsync("FundingFm25Output", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("FundingFm25Output", It.IsAny <CancellationToken>()))
            .ReturnsAsync(File.ReadAllText(fm25Filename));
            storage.Setup(x => x.ContainsAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(validLearnersStr);

            IMessage message = await ilrProviderService.GetIlrFile(reportServiceContextMock.Object, CancellationToken.None);

            List <string> validLearners = jsonSerializationService.Deserialize <List <string> >(validLearnersStr);
            Dictionary <string, LarsLearningDelivery> learningDeliveriesDict =
                new Dictionary <string, LarsLearningDelivery>();
            List <LearnerAndDeliveries> learnerAndDeliveries = new List <LearnerAndDeliveries>();

            foreach (ILearner messageLearner in message.Learners)
            {
                if (validLearners.Contains(messageLearner.LearnRefNumber))
                {
                    List <LearningDelivery> learningDeliveries = new List <LearningDelivery>();
                    foreach (ILearningDelivery learningDelivery in messageLearner.LearningDeliveries)
                    {
                        var learningDeliveryRes = new LearningDelivery(
                            learningDelivery.LearnAimRef,
                            learningDelivery.AimSeqNumber,
                            learningDelivery.FworkCodeNullable,
                            learningDelivery.ProgTypeNullable,
                            learningDelivery.PwayCodeNullable,
                            learningDelivery.LearnStartDate);
                        learningDeliveryRes.FrameworkComponentType = 1;
                        learningDeliveries.Add(learningDeliveryRes);
                        learningDeliveriesDict[learningDelivery.LearnAimRef] = new LarsLearningDelivery()
                        {
                            LearningAimTitle       = "A",
                            NotionalNvqLevel       = "B",
                            Tier2SectorSubjectArea = 3
                        };
                    }

                    learnerAndDeliveries.Add(
                        new LearnerAndDeliveries(messageLearner.LearnRefNumber, learningDeliveries));
                }
            }

            larsProviderService
            .Setup(x => x.GetLearningDeliveriesAsync(It.IsAny <string[]>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(learningDeliveriesDict);
            larsProviderService
            .Setup(x => x.GetFrameworkAimsAsync(It.IsAny <string[]>(), It.IsAny <List <ILearner> >(), It.IsAny <CancellationToken>())).ReturnsAsync(learnerAndDeliveries);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);

            var mainOccupancyReport = new MainOccupancyReport(
                logger.Object,
                storage.Object,
                ilrProviderService,
                stringUtilitiesService,
                validLearnersService,
                fm25ProviderService,
                fm35ProviderService,
                larsProviderService.Object,
                dateTimeProviderMock.Object,
                valueProvider,
                topicsAndTasks,
                reportModelBuilder);

            await mainOccupancyReport.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();

#if DEBUG
            File.WriteAllText($"{filename}.csv", csv);
#endif

            TestCsvHelper.CheckCsv(csv, new CsvEntry(new MainOccupancyMapper(), 1));
        }
Exemple #16
0
        public async Task TestHNSReportGeneration(string ilrFilename, string fm25Filename)
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10033670_1_High Needs Students Detail Report {dateTime:yyyyMMdd-HHmmss}";

            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10033670);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns(ilrFilename);
            reportServiceContextMock.SetupGet(x => x.FundingFM25OutputKey).Returns("FundingFm25Output");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

            DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration()
            {
                ILRDataStoreConnectionString      = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString,
                ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString
            };

            IIlr1819ValidContext IlrValidContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options;

                return(new ILR1819_DataStoreEntitiesValid(options));
            }

            IIlr1819RulebaseContext IlrRulebaseContextFactory()
            {
                var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options;

                return(new ILR1819_DataStoreEntities(options));
            }

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IStreamableKeyValuePersistenceService> redis   = new Mock <IStreamableKeyValuePersistenceService>();
            IIntUtilitiesService      intUtilitiesService        = new IntUtilitiesService();
            IJsonSerializationService jsonSerializationService   = new JsonSerializationService();
            IXmlSerializationService  xmlSerializationService    = new XmlSerializationService();

            IFM25ProviderService   fm25ProviderService = new FM25ProviderService(logger.Object, storage.Object, jsonSerializationService, IlrRulebaseContextFactory);
            IIlrProviderService    ilrProviderService = new IlrFileServiceProvider(logger.Object, storage.Object, xmlSerializationService); IValidLearnersService validLearnersService = new ValidLearnersService(logger.Object, redis.Object, jsonSerializationService, dataStoreConfiguration);
            IValueProvider         valueProvider      = new ValueProvider();
            IHNSReportModelBuilder reportModelBuilder = new HNSReportModelBuilder();

            storage.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead(ilrFilename).CopyTo(sr))
            .Returns(Task.CompletedTask);
            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Callback <string, string, CancellationToken>((key, value, ct) => csv = value)
            .Returns(Task.CompletedTask);
            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(jsonSerializationService.Serialize(
                                                                                                                  new List <string>
            {
                "0Addl103",
                "0ContPr01",
                "1ContPr01",
                "2ContPr01"
            }));

            storage.Setup(x => x.ContainsAsync("FundingFm25Output", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("FundingFm25Output", It.IsAny <CancellationToken>()))
            .ReturnsAsync(File.ReadAllText(fm25Filename));
            storage.Setup(x => x.ContainsAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);

            var hnsReport = new HNSDetailReport(
                logger.Object,
                storage.Object,
                ilrProviderService,
                validLearnersService,
                fm25ProviderService,
                dateTimeProviderMock.Object,
                valueProvider,
                reportModelBuilder);

            await hnsReport.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();

#if DEBUG
            File.WriteAllText($"{filename}.csv", csv);
#endif

            TestCsvHelper.CheckCsv(csv, new CsvEntry(new HNSMapper(), 1));
        }
        public async Task TestAppsAdditionalPaymentsReportGeneration()
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10036143_1_Apps Additional Payments Report {dateTime:yyyyMMdd-HHmmss}";
            int      ukPrn    = 10036143;
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();

            reportServiceContextMock.SetupGet(x => x.JobId).Returns(1);
            reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow);
            reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(ukPrn);

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock        = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IIlrPeriodEndProviderService>          IlrPeriodEndProviderServiceMock = new Mock <IIlrPeriodEndProviderService>();
            Mock <IDASPaymentsProviderService>           dasPaymentProviderMock          = new Mock <IDASPaymentsProviderService>();
            Mock <IFM36PeriodEndProviderService>         fm36ProviderServiceMock         = new Mock <IFM36PeriodEndProviderService>();
            IValueProvider valueProvider = new ValueProvider();

            storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask);

            var appsAdditionalPaymentIlrInfo         = BuildILRModel(ukPrn);
            var appsAdditionalPaymentRulebaseInfo    = BuildFm36Model(ukPrn);
            var appsAdditionalPaymentDasPaymentsInfo = BuildDasPaymentsModel(ukPrn);

            IlrPeriodEndProviderServiceMock.Setup(x => x.GetILRInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentIlrInfo);
            fm36ProviderServiceMock.Setup(x => x.GetFM36DataForAppsAdditionalPaymentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentRulebaseInfo);
            dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsAdditionalPaymentsReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(appsAdditionalPaymentDasPaymentsInfo);

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime);
            var appsAdditionalPaymentsModelBuilder = new AppsAdditionalPaymentsModelBuilder();

            var report = new ReportService.Service.Reports.PeriodEnd.AppsAdditionalPaymentsReport(
                logger.Object,
                storage.Object,
                IlrPeriodEndProviderServiceMock.Object,
                fm36ProviderServiceMock.Object,
                dateTimeProviderMock.Object,
                valueProvider,
                dasPaymentProviderMock.Object,
                appsAdditionalPaymentsModelBuilder);

            await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None);

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllText($"{filename}.csv", csv);
            TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsAdditionalPaymentsMapper(), 1));
            IEnumerable <AppsAdditionalPaymentsModel> result;

            using (var reader = new StreamReader($"{filename}.csv"))
            {
                using (var csvReader = new CsvReader(reader))
                {
                    csvReader.Configuration.RegisterClassMap <AppsAdditionalPaymentsMapper>();
                    result = csvReader.GetRecords <AppsAdditionalPaymentsModel>().ToList();
                }
            }

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(1);
            result.First().AprilEarnings.Should().Be(180);
            result.First().JulyEarnings.Should().Be(240);
            result.First().DecemberEarnings.Should().Be(100);
            result.First().TotalEarnings.Should().Be(1560);
            result.First().TotalPaymentsYearToDate.Should().Be(20);
            result.First().UniqueLearnerNumber.Should().Be(12345);
        }