//[Theory] //[InlineData("EMPLOYER2", "EMPLOYER2", "A12345", "ZPROG001", "A12345", "ZPROG001")] public async Task TestCoInvestmentContributionsReportGeneration( string employerName, string employerNameExpected, string ilrLearnRefNumber, string ilrLearnAimRef, string dasLearnRefNumber, string dasLearnAimRef) { string csv = string.Empty; DateTime dateTime = DateTime.UtcNow; string filename = $"10036143 Apps Co-Investment Contributions Report {dateTime:yyyyMMdd-HHmmss}"; int ukPrn = 10036143; Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>(); reportServiceContextMock.SetupGet(x => x.JobId).Returns(1); reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow); reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(ukPrn); reportServiceContextMock.SetupGet(x => x.ReturnPeriod).Returns(1); Mock <ILogger> logger = new Mock <ILogger>(); Mock <IDateTimeProvider> dateTimeProviderMock = new Mock <IDateTimeProvider>(); Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>(); Mock <IIlrPeriodEndProviderService> ilrPeriodEndProviderServiceMock = new Mock <IIlrPeriodEndProviderService>(); Mock <IDASPaymentsProviderService> dasPaymentProviderMock = new Mock <IDASPaymentsProviderService>(); Mock <IFM36PeriodEndProviderService> fm36ProviderServiceMock = new Mock <IFM36PeriodEndProviderService>(); Mock <IPersistReportData> persistReportDataMock = new Mock <IPersistReportData>(); storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())) .Callback <string, string, CancellationToken>((key, value, ct) => csv = value) .Returns(Task.CompletedTask); var appsCoInvestmentIlrInfo = BuildILRModel(ukPrn, ilrLearnRefNumber, ilrLearnAimRef, 1); var appsCoInvestmentRulebaseInfo = BuildFm36Model(ukPrn, ilrLearnRefNumber, 1, ilrLearnAimRef); var appsCoInvestmentDasPaymentsInfo = BuildDasPaymentsModel(ukPrn, employerName, dasLearnRefNumber, dasLearnAimRef); ilrPeriodEndProviderServiceMock.Setup(x => x.GetILRInfoForAppsCoInvestmentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())) .ReturnsAsync(appsCoInvestmentIlrInfo); fm36ProviderServiceMock.Setup(x => x.GetFM36DataForAppsCoInvestmentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())) .ReturnsAsync(appsCoInvestmentRulebaseInfo); dasPaymentProviderMock.Setup(x => x.GetPaymentsInfoForAppsCoInvestmentReportAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())) .ReturnsAsync(appsCoInvestmentDasPaymentsInfo); dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime); dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime); var appsCoInvestmentContributionsModelBuilder = new AppsCoInvestmentContributionsModelBuilder(new AppsCoInvestmentRecordKeyEqualityComparer(), logger.Object); var report = new AppsCoInvestmentContributionsReport( logger.Object, storage.Object, dateTimeProviderMock.Object, ilrPeriodEndProviderServiceMock.Object, dasPaymentProviderMock.Object, fm36ProviderServiceMock.Object, appsCoInvestmentContributionsModelBuilder, persistReportDataMock.Object); await report.GenerateReport(reportServiceContextMock.Object, null, CancellationToken.None); csv.Should().NotBeNullOrEmpty(); File.WriteAllText($"{filename}.csv", csv); TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsCoInvestmentContributionsMapper(), 1)); IEnumerable <AppsCoInvestmentContributionsModel> result; using (var csvReader = new CsvReader(new StringReader(csv))) { csvReader.Configuration.RegisterClassMap <AppsCoInvestmentContributionsMapper>(); result = csvReader.GetRecords <AppsCoInvestmentContributionsModel>().ToList(); } result.Should().NotBeNullOrEmpty(); result.Count().Should().Be(1); result.First().CoInvestmentDueFromEmployerForAugust.Should().Be(20); result.First().CompletionPaymentsThisFundingYear.Should().Be(20); result.First().UniqueLearnerNumber.Should().Be(12345); result.First().EmployerNameFromApprenticeshipService.Should().Be(employerNameExpected); }
public async Task TestAppsCoInvestmentContributionsReportGeneration() { string csv = string.Empty; DateTime dateTime = DateTime.UtcNow; string filename = $"10036143_1_Apps Co-Investment Contributions 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); dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime); dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime); 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 }; DASPaymentsConfiguration dasPaymentsConfiguration = new DASPaymentsConfiguration() { DASPaymentsConnectionString = new TestConfigurationHelper().GetSectionValues <DASPaymentsConfiguration>("DASPaymentsSection").DASPaymentsConnectionString, }; 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)); } IDASPaymentsContext DasPaymentsContextFactory() { var options = new DbContextOptionsBuilder <DASPaymentsContext>().UseSqlServer(dasPaymentsConfiguration.DASPaymentsConnectionString).Options; return(new DASPaymentsContext(options)); } IIlrProviderService ilrProviderService = new IlrProviderService( logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseContextFactory); var dasPaymentsProviderService = new DASPaymentsProviderService(logger.Object, DasPaymentsContextFactory); var report = new AppsCoInvestmentContributionsReport(logger.Object, storage.Object, dateTimeProviderMock.Object, valueProvider, topicsAndTasks, ilrProviderService, dasPaymentsProviderService); await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None); csv.Should().NotBeNullOrEmpty(); File.WriteAllText($"{filename}.csv", csv); TestCsvHelper.CheckCsv(csv, new CsvEntry(new AppsCoInvestmentContributionsMapper(), 1)); }