public async Task VerifyResults(IEnumerable <FileUploadJob> results, DateTimeOffset testStartDateTime, DateTimeOffset testEndDateTime, Action <decimal?, decimal, decimal?> verificationAction) { var resultsList = results.ToList(); var ukprnList = resultsList.Select(r => r.Ukprn).ToList(); byte collectionPeriod = (byte)resultsList.FirstOrDefault().PeriodNumber; var groupedResults = resultsList.GroupBy(g => g.CollectionYear); foreach (var groupedResult in groupedResults) { short academicYear = (short)groupedResult.Key; var paymentCsv = await ExtractPaymentsData(testStartDateTime, testEndDateTime, academicYear, collectionPeriod); var dataStoreCsv = await ExtractDataStoreData(academicYear, collectionPeriod, ukprnList); var paymentTotals = await verificationService.GetPaymentTotals( academicYear, collectionPeriod, true, testStartDateTime, testEndDateTime); decimal?totalEarningYtd = await verificationService.GetTotalEarningsYtd(academicYear, collectionPeriod, ukprnList); var settings = await submissionService.ReadSettingsFile(); decimal tolerance = settings.Tolerance; decimal?actualPercentage = null; if (totalEarningYtd != 0) { actualPercentage = paymentTotals?.missingPayments / totalEarningYtd * 100; } var summaryCsv = CreateSummaryCsv(actualPercentage, tolerance, totalEarningYtd, paymentTotals); var queryTimeWindowCsv = CreateQueryTimeWindowCsv(testStartDateTime, testEndDateTime); await SaveCsv(paymentCsv, dataStoreCsv, summaryCsv, queryTimeWindowCsv, academicYear, collectionPeriod); var earningsDifference = totalEarningYtd - paymentTotals?.earningsYtd; verificationAction.Invoke(actualPercentage, tolerance, earningsDifference); } }