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));
        }
Example #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));
        }
        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));
        }
Example #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 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));
        }
        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, 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);
            IStringUtilitiesService     stringUtilitiesService     = new StringUtilitiesService();
            IValueProvider              valueProvider              = new ValueProvider();
            ITopicAndTaskSectionOptions topicAndTaskSectionOptions = TestConfigurationHelper.GetTopicsAndTasks();
            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,
                topicAndTaskSectionOptions,
                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 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));
        }
        public async Task TestEntryPointZipGeneration()
        {
            string csv = $"A,B,C,D{Environment.NewLine}1,2,3,4";

            byte[] zipBytes = null;

            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();

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

            streamableKeyValuePersistenceService.Setup(x =>
                                                       x.SaveAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Callback <string, Stream, CancellationToken>((s, m, c) =>
            {
                zipBytes = new byte[m.Length];
                m.Seek(0, SeekOrigin.Begin);
                m.Read(zipBytes, 0, (int)m.Length);
            })
            .Returns(Task.CompletedTask);
            Mock <IReport> report = new Mock <IReport>();

            report.SetupGet(x => x.ReportTaskName).Returns(topicsAndTasks.TopicReports_TaskGenerateAllbOccupancyReport);
            report.Setup(x =>
                         x.GenerateReport(It.IsAny <IReportServiceContext>(), It.IsAny <ZipArchive>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()))
            .Callback <IReportServiceContext, ZipArchive, bool, CancellationToken>((j, z, b, c) =>
            {
                ZipArchiveEntry archivedFile = z.CreateEntry("ExampleReport.csv", CompressionLevel.Optimal);
                using (var sw = new StreamWriter(archivedFile.Open()))
                {
                    sw.Write(csv);
                }
            })
            .Returns(Task.CompletedTask);
            report.Setup(x => x.IsMatch(It.IsAny <string>())).Returns(true);

            JobContextMessage jobContextMessage =
                new JobContextMessage(
                    1,
                    new ITopicItem[] { new TopicItem("SubscriptionName", new List <ITaskItem> {
                    new TaskItem(new List <string> {
                        topicsAndTasks.TopicReports_TaskGenerateAllbOccupancyReport
                    }, false)
                }) },
                    0,
                    DateTime.UtcNow);

            jobContextMessage.KeyValuePairs.Add(JobContextMessageKey.UkPrn, 1234);

            EntryPoint entryPoint = new EntryPoint(
                logger.Object,
                streamableKeyValuePersistenceService.Object,
                new[] { report.Object });

            await entryPoint.Callback(new ReportServiceJobContextMessageContext(jobContextMessage), CancellationToken.None);

            string zipContents;

            using (MemoryStream ms = new MemoryStream(zipBytes))
            {
                using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Read))
                {
                    ZipArchiveEntry entry = archive.GetEntry("ExampleReport.csv");
                    entry.Should().NotBeNull();
                    using (StreamReader reader = new StreamReader(entry.Open()))
                    {
                        zipContents = reader.ReadToEnd();
                    }
                }
            }

            zipContents.Should().NotBeNullOrEmpty();
            zipContents.Should().Be(csv);
        }
Example #9
0
        public async Task TestMainOccupancyReportGeneration(string ilrFilename, string fm35Filename, string validLearner)
        {
            string        csv           = string.Empty;
            DateTime      dateTime      = DateTime.UtcNow;
            string        filename      = $"10033670_1_Main Occupancy Report {dateTime:yyyyMMdd-HHmmss}";
            List <string> validLearners = new List <string> {
                validLearner
            };

            Mock <ILogger>           logger = new Mock <ILogger>();
            Mock <IDateTimeProvider> dateTimeProviderMock         = new Mock <IDateTimeProvider>();
            Mock <IStreamableKeyValuePersistenceService> storage  = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IKeyValuePersistenceService>           redis    = new Mock <IKeyValuePersistenceService>();
            Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>();
            IIntUtilitiesService         intUtilitiesService      = new IntUtilitiesService();
            IJsonSerializationService    jsonSerializationService = new JsonSerializationService();
            IXmlSerializationService     xmlSerializationService  = new XmlSerializationService();
            IFM35ProviderService         fm35ProviderService      = new FM35ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, null, null);
            IFM25ProviderService         fm25ProviderService      = new FM25ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, null);
            IIlrProviderService          ilrProviderService       = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, null, null);
            LarsConfiguration            larsConfiguration        = new LarsConfiguration
            {
                LarsConnectionString = ConfigurationManager.AppSettings["LarsConnectionString"]
            };
            ILarsProviderService             larsProviderService    = new LarsProviderService(logger.Object, larsConfiguration);
            IStringUtilitiesService          stringUtilitiesService = new StringUtilitiesService();
            ITopicAndTaskSectionOptions      topicsAndTasks         = TestConfigurationHelper.GetTopicsAndTasks();
            IMainOccupancyReportModelBuilder reportModelBuilder     = new MainOccupancyReportModelBuilder();
            IValueProvider valueProvider = new ValueProvider();

            storage.Setup(x => x.GetAsync(ilrFilename, 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);
            storage.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);
            redis.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(jsonSerializationService.Serialize(validLearners));

            dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime);
            dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <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(ilrFilename);
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.FundingFM35OutputKey).Returns("FundingFm35Output");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

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

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

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

            csv.Should().NotBeNullOrEmpty();

            File.WriteAllText($"{filename}.csv", csv);
        }
        public async Task TestAdultFundingClaimReportGeneration()
        {
            string csv = string.Empty;

            byte[]   xlsx     = null;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10007924_1_Adult Funding Claim Report {dateTime:yyyyMMdd-HHmmss}";

            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 <IOrgProviderService>           orgProviderService           = new Mock <IOrgProviderService>();
            Mock <ILarsProviderService>          larsProviderService          = new Mock <ILarsProviderService>();
            Mock <IPostcodeProviderService>      postcodeProverServiceMock    = new Mock <IPostcodeProviderService>();
            Mock <ILargeEmployerProviderService> largeEmployerProviderService = new Mock <ILargeEmployerProviderService>();
            Mock <IDateTimeProvider>             dateTimeProviderMock         = new Mock <IDateTimeProvider>();
            IIntUtilitiesService intUtilitiesService = new IntUtilitiesService();

            EasConfiguration easConfiguration = new EasConfiguration()
            {
                EasConnectionString = new TestConfigurationHelper().GetSectionValues <EasConfiguration>("EasSection").EasConnectionString
            };
            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));
            }

            IEasProviderService  easProviderService  = new EasProviderService(logger.Object, easConfiguration);
            IIlrProviderService  ilrProviderService  = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);
            IAllbProviderService allbProviderService = new AllbProviderService(logger.Object, redis.Object, jsonSerializationService, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);
            IFM35ProviderService fm35ProviderService = new FM35ProviderService(logger.Object, redis.Object, jsonSerializationService, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);
            IVersionInfo         versionInfo         = new VersionInfo {
                ServiceReleaseVersion = "1.2.3.4.5"
            };

            redis.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("FundingFM35OutputKey", It.IsAny <Stream>(), It.IsAny <CancellationToken>())).Callback <string, Stream, CancellationToken>((st, sr, ct) => File.OpenRead("Fm35.json").CopyTo(sr)).Returns(Task.CompletedTask);
            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);
            storage.Setup(x => x.GetAsync("ILR-10007924-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);
            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");

            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();
            IValueProvider valueProvider = new ValueProvider();

            AdultFundingClaimReport adultFundingClaimReport = new AdultFundingClaimReport(
                logger.Object,
                storage.Object,
                ilrProviderService,
                orgProviderService.Object,
                allbProviderService,
                fm35ProviderService,
                dateTimeProviderMock.Object,
                intUtilitiesService,
                valueProvider,
                larsProviderService.Object,
                easProviderService,
                postcodeProverServiceMock.Object,
                largeEmployerProviderService.Object,
                versionInfo,
                topicsAndTasks,
                new AdultFundingClaimBuilder());

            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(10007924);
            reportServiceContextMock.SetupGet(x => x.Filename).Returns("ILR-10007924-1819-20180704-120055-03");
            reportServiceContextMock.SetupGet(x => x.FundingFM35OutputKey).Returns("FundingFM35OutputKey");
            reportServiceContextMock.SetupGet(x => x.FundingALBOutputKey).Returns("FundingALBOutputKey");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

            MemoryStream memoryStream = new MemoryStream();

            using (memoryStream)
            {
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Update, true))
                {
                    await adultFundingClaimReport.GenerateReport(reportServiceContextMock.Object, archive, false, CancellationToken.None);

                    //await adultFundingClaimReport.GenerateReport(jobContextMessage, archive, false, CancellationToken.None);
                }

                using (var fileStream = new FileStream($"{filename}.zip", FileMode.Create))
                {
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    memoryStream.CopyTo(fileStream);
                }
            }

            xlsx.Should().NotBeNullOrEmpty();

            File.WriteAllBytes($"{filename}.xlsx", xlsx);
        }
        public async Task TestFundingSummaryReportGeneration()
        {
            string csv = string.Empty;

            byte[]   xlsx     = null;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10033670_1_Funding Summary Report {dateTime:yyyyMMdd-HHmmss}";
            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();
            IIlrProviderService       ilrProviderService         = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);

            IOrgProviderService orgProviderService = new OrgProviderService(logger.Object, new OrgConfiguration()
            {
                OrgConnectionString = ConfigurationManager.AppSettings["OrgConnectionString"]
            });

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

            IEasProviderService easProviderService = new EasProviderService(logger.Object, new EasConfiguration()
            {
                EasConnectionString = new TestConfigurationHelper().GetSectionValues <EasConfiguration>("EasSection").EasConnectionString
            });
            Mock <IPostcodeProviderService>      postcodeProverServiceMock    = new Mock <IPostcodeProviderService>();
            Mock <ILargeEmployerProviderService> largeEmployerProviderService = new Mock <ILargeEmployerProviderService>();
            IAllbProviderService            allbProviderService            = new AllbProviderService(logger.Object, redis.Object, jsonSerializationService, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);
            IFM35ProviderService            fm35ProviderService            = new FM35ProviderService(logger.Object, redis.Object, jsonSerializationService, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);
            IFM25ProviderService            fm25ProviderService            = new FM25ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, IlrRulebaseContextFactory);
            IFM36ProviderService            fm36ProviderService            = new FM36ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, IlrRulebaseContextFactory);
            IFM81TrailBlazerProviderService fm81TrailBlazerProviderService = new FM81TrailBlazerProviderService(logger.Object, storage.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.FundingFM35OutputKey).Returns("FundingFm35Output");
            reportServiceContextMock.SetupGet(x => x.FundingFM25OutputKey).Returns("FundingFm25Output");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");
            reportServiceContextMock.SetupGet(x => x.ReturnPeriod).Returns(12);

            IValidLearnersService   validLearnersService   = new ValidLearnersService(logger.Object, redis.Object, jsonSerializationService, dataStoreConfiguration);
            IStringUtilitiesService stringUtilitiesService = new StringUtilitiesService();
            IVersionInfo            versionInfo            = new VersionInfo {
                ServiceReleaseVersion = "1.2.3.4.5"
            };
            ITotalBuilder       totalBuilder       = new TotalBuilder();
            IFm25Builder        fm25Builder        = new Fm25Builder();
            IFm35Builder        fm35Builder        = new Fm35Builder(totalBuilder, new CacheProviderService <LearningDelivery[]>());
            IFm36Builder        fm36Builder        = new Fm36Builder(totalBuilder, new CacheProviderService <ILR.FundingService.FM36.FundingOutput.Model.Output.LearningDelivery[]>());
            IFm81Builder        fm81Builder        = new Fm81Builder(totalBuilder, new CacheProviderService <ILR.FundingService.FM81.FundingOutput.Model.Output.LearningDelivery[]>());
            IAllbBuilder        allbBuilder        = new AllbBuilder(ilrProviderService, validLearnersService, allbProviderService, stringUtilitiesService, logger.Object);
            IExcelStyleProvider excelStyleProvider = new ExcelStyleProvider();

            IEasBuilder easBuilder = new EasBuilder(easProviderService);

            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);
            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"
            }));
            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);
            redis.Setup(x => x.GetAsync("FundingFm25Output", It.IsAny <CancellationToken>())).ReturnsAsync(File.ReadAllText("Fm25.json"));
            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");

            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();
            IValueProvider valueProvider = new ValueProvider();

            FundingSummaryReport fundingSummaryReport = new FundingSummaryReport(
                storage.Object,
                ilrProviderService,
                orgProviderService,
                allbProviderService,
                fm25ProviderService,
                fm35ProviderService,
                fm36ProviderService,
                fm81TrailBlazerProviderService,
                validLearnersService,
                dateTimeProviderMock.Object,
                valueProvider,
                larsProviderService,
                easProviderService,
                postcodeProverServiceMock.Object,
                largeEmployerProviderService.Object,
                allbBuilder,
                fm25Builder,
                fm35Builder,
                fm36Builder,
                fm81Builder,
                totalBuilder,
                versionInfo,
                excelStyleProvider,
                topicsAndTasks,
                easBuilder,
                logger.Object);

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

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

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

            //var fundingSummaryHeaderMapper = new FundingSummaryHeaderMapper();
            //var fundingSummaryMapper = new FundingSummaryMapper();
            //var fundingSummaryFooterMapper = new FundingSummaryFooterMapper();
            //TestCsvHelper.CheckCsv(
            //    csv,
            //    new CsvEntry(fundingSummaryHeaderMapper, 1),
            //    new CsvEntry(fundingSummaryMapper, 0, "16-18 Traineeships Budget", 1),
            //    new CsvEntry(fundingSummaryMapper, 3, "16-18 Traineeships"),
            //    new CsvEntry(fundingSummaryMapper, 1, "16-18 Trailblazer Apprenticeships for starts before 1 May 2017", 1),
            //    new CsvEntry(fundingSummaryMapper, 0, "Advanced Loans Bursary Budget", 1),
            //    new CsvEntry(fundingSummaryMapper, 3, "Advanced Loans Bursary"),
            //    new CsvEntry(fundingSummaryMapper, 0, Constants.ALBInfoText),
            //    new CsvEntry(fundingSummaryFooterMapper, 1, blankRowsBefore: 1));

            //var fundingSummaryHeaderMapper = new FundingSummaryHeaderMapper();
            //var fundingSummaryMapper = new FundingSummaryMapper();
            //TestXlsxHelper.CheckXlsxWithTitles(
            //    xlsx,
            //    new XlsxEntry(fundingSummaryHeaderMapper, fundingSummaryHeaderMapper.GetMaxIndex(), true),
            //    new XlsxEntry(fundingSummaryMapper, 0, "16-18 Traineeships Budget", 1),
            //    new XlsxEntry(fundingSummaryMapper, 13, "16-18 Traineeships", 0),
            //    new XlsxEntry(fundingSummaryMapper, 0, "Carry-in Apprenticeships Budget (for starts before 1 May 2017 and non-procured delivery)", 1),
            //    new XlsxEntry(fundingSummaryMapper, 9, "16-18 Apprenticeship Frameworks for starts before 1 May 2017", 1),
            //    new XlsxEntry(fundingSummaryMapper, 9, "16-18 Trailblazer Apprenticeships for starts before 1 May 2017", 1),
            //    new XlsxEntry(fundingSummaryMapper, 18, "16-18 Non-Levy Contracted Apprenticeships - Non-procured delivery", 1),
            //    new XlsxEntry(fundingSummaryMapper, 9, "19-23 Apprenticeship Frameworks for starts before 1 May 2017", 1),
            //    new XlsxEntry(fundingSummaryMapper, 9, "19-23 Trailblazer Apprenticeships for starts before 1 May 2017", 0),
            //    new XlsxEntry(fundingSummaryMapper, 9, "24+ Apprenticeship Frameworks for starts before 1 May 2017", 1));
        }
        public async Task TestTrailblazerEmployerIncentiveReportGeneration(string ilrFilename, string validLearnRefNumbersFilename, string fm81FileName)
        {
            string   csv      = string.Empty;
            DateTime dateTime = DateTime.UtcNow;
            string   filename = $"10033670_1_Trailblazer Apprenticeships Employer Incentives Report {dateTime:yyyyMMdd-HHmmss}";

            Mock <ILogger> logger = new Mock <ILogger>();
            Mock <IStreamableKeyValuePersistenceService> storage              = new Mock <IStreamableKeyValuePersistenceService>();
            IIntUtilitiesService intUtilitiesService                          = new IntUtilitiesService();
            Mock <IKeyValuePersistenceService> redis                          = new Mock <IKeyValuePersistenceService>();
            IJsonSerializationService          jsonSerializationService       = new JsonSerializationService();
            IXmlSerializationService           xmlSerializationService        = new XmlSerializationService();
            IFM81TrailBlazerProviderService    fm81TrailBlazerProviderService = new FM81TrailBlazerProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, null, null);
            IIlrProviderService ilrProviderService = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, null, intUtilitiesService, null, null);

            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.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.FundingFM81OutputKey).Returns("FundingFm81Output");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

            IValidLearnersService       validLearnersService = new ValidLearnersService(logger.Object, redis.Object, jsonSerializationService, null);
            Mock <IDateTimeProvider>    dateTimeProviderMock = new Mock <IDateTimeProvider>();
            ITopicAndTaskSectionOptions topicsAndTasks       = TestConfigurationHelper.GetTopicsAndTasks();
            ITrailblazerEmployerIncentivesModelBuilder reportModelBuilder = new TrailblazerEmployerIncentivesModelBuilder();
            IValueProvider valueProvider = new ValueProvider();

            var validLearnersStr = File.ReadAllText(validLearnRefNumbersFilename);

            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            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.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);

            redis.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.GetAsync("FundingFm81Output", It.IsAny <CancellationToken>())).ReturnsAsync(File.ReadAllText(fm81FileName));
            redis.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(validLearnersStr);

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

            var trailblazerEmployerIncentivesReport = new TrailblazerEmployerIncentivesReport(
                logger.Object,
                storage.Object,
                fm81TrailBlazerProviderService,
                ilrProviderService,
                validLearnersService,
                reportModelBuilder,
                topicsAndTasks,
                valueProvider,
                dateTimeProviderMock.Object);

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

            csv.Should().NotBeNullOrEmpty();
            File.WriteAllBytes($"{filename}.csv", Encoding.ASCII.GetBytes(csv));

            //TestCsvHelper.CheckCsv(csv, new CsvEntry(new MainOccupancyFM25Mapper(), 14), new CsvEntry(new MainOccupancyFM35Mapper(), 14));
        }
Example #13
0
        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>();
            Mock <IKeyValuePersistenceService>           redis     = new Mock <IKeyValuePersistenceService>();
            IJsonSerializationService     jsonSerializationService = new JsonSerializationService();
            IIntUtilitiesService          intUtilitiesService      = new IntUtilitiesService();
            IFM36ProviderService          fm36ProviderService      = new FM36ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, IlrRulebaseContextFactory);
            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);
            redis.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);

            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();
            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,
                topicsAndTasks,
                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 TestFundingClaim1619ReportGeneration()
        {
            byte[] xlsx     = null;
            string filename = $"10033670_1_16-19 Funding Claim Report {DateTime.UtcNow:yyyyMMdd-HHmmss}";
            string csv      = string.Empty;
            var    dateTime = System.DateTime.UtcNow;

            Mock <ILogger> logger = new Mock <ILogger>();
            Mock <IStreamableKeyValuePersistenceService> storage              = new Mock <IStreamableKeyValuePersistenceService>();
            Mock <IKeyValuePersistenceService>           redis                = new Mock <IKeyValuePersistenceService>();
            IJsonSerializationService            jsonSerializationService     = new JsonSerializationService();
            IXmlSerializationService             xmlSerializationService      = new XmlSerializationService();
            Mock <IOrgProviderService>           orgProviderService           = new Mock <IOrgProviderService>();
            Mock <ILarsProviderService>          larsProviderService          = new Mock <ILarsProviderService>();
            Mock <IPostcodeProviderService>      postcodeProverServiceMock    = new Mock <IPostcodeProviderService>();
            Mock <ILargeEmployerProviderService> largeEmployerProviderService = new Mock <ILargeEmployerProviderService>();
            Mock <IDateTimeProvider>             dateTimeProviderMock         = new Mock <IDateTimeProvider>();
            IIntUtilitiesService intUtilitiesService = new IntUtilitiesService();

            EasConfiguration easConfiguration = new EasConfiguration()
            {
                EasConnectionString = new TestConfigurationHelper().GetSectionValues <EasConfiguration>("EasSection").EasConnectionString
            };
            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);
            IVersionInfo        versionInfo        = new VersionInfo {
                ServiceReleaseVersion = "1.2.3.4.5"
            };

            storage.Setup(x => x.ContainsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(true);
            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-20181213-230923-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);

            redis.Setup(x => x.GetAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(jsonSerializationService.Serialize(
                                                                                                                  new List <string>
            {
                "0fm2501",
                "0fm2502",
                "0fm2503",
                "0fm2504"
            }));

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

            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();
            IValueProvider valueProvider = new ValueProvider();

            Mock <IFM25ProviderService> fm25ProviderServiceMock = new Mock <IFM25ProviderService>();
            var fm25DataModelMock = TestFm25GlobalBuilder.BuildTestModel();

            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-20181213-230923-03");
            reportServiceContextMock.SetupGet(x => x.ValidLearnRefNumbersKey).Returns("ValidLearnRefNumbers");
            reportServiceContextMock.SetupGet(x => x.FundingFM25OutputKey).Returns("FundingFm25Output");
            reportServiceContextMock.SetupGet(x => x.CollectionName).Returns("ILR1819");

            fm25ProviderServiceMock.Setup(x => x.GetFM25Data(reportServiceContextMock.Object, CancellationToken.None)).Returns(Task.FromResult(fm25DataModelMock));
            decimal?cofTestValue = 100.50m;

            orgProviderService
            .Setup(x => x.GetCofRemoval(It.IsAny <IReportServiceContext>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(cofTestValue));

            FundingClaim1619Report fundingClaim1619Report = new FundingClaim1619Report(
                storage.Object,
                dateTimeProviderMock.Object,
                valueProvider,
                ilrProviderService,
                orgProviderService.Object,
                fm25ProviderServiceMock.Object,
                postcodeProverServiceMock.Object,
                largeEmployerProviderService.Object,
                larsProviderService.Object,
                versionInfo,
                topicsAndTasks);

            MemoryStream memoryStream = new MemoryStream();

            using (memoryStream)
            {
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Update, true))
                {
                    await fundingClaim1619Report.GenerateReport(reportServiceContextMock.Object, archive, false, CancellationToken.None);
                }

                using (var fileStream = new FileStream($"{filename}.zip", FileMode.Create))
                {
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    memoryStream.CopyTo(fileStream);
                }
            }

            xlsx.Should().NotBeNullOrEmpty();

            File.WriteAllBytes($"{filename}.xlsx", xlsx);

            //using (var stream = File.Open($"{filename}.xlsx", FileMode.Open, FileAccess.Read))
            //{
            //    using (var reader = ExcelReaderFactory.CreateReader(stream))
            //    {
            //        var result = reader.AsDataSet();
            //        var a = 1;
            //    }
            //}
        }
Example #15
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 IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, null, null);

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

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

            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,
                allbProviderService,
                validLearnersService,
                stringUtilitiesService,
                dateTimeProviderMock.Object,
                valueProvider,
                topicsAndTasks);

            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 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>();
            Mock <IKeyValuePersistenceService>           redis   = new Mock <IKeyValuePersistenceService>();
            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 IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory);
            Mock <ILarsProviderService> larsProviderService    = new Mock <ILarsProviderService>();
            IValidLearnersService       validLearnersService   = new ValidLearnersService(logger.Object, redis.Object, jsonSerializationService, dataStoreConfiguration);
            IFM36ProviderService        fm36ProviderService    = new FM36ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, IlrRulebaseContextFactory);
            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);
            redis.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"
            }));
            redis.Setup(x => x.ContainsAsync("ValidLearners", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.ContainsAsync("ValidLearnRefNumbers", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.Setup(x => x.ContainsAsync("FundingFm36Output", It.IsAny <CancellationToken>())).ReturnsAsync(true);
            redis.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 redis.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");

            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();
            IValueProvider valueProvider = new ValueProvider();

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

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