public void Json_DeserializeModel_Fail() { var json = "{INVALID\"TimeRange\":2,\"DayRange\":3,\"CustomDays\":1,\"Title\":\"Test Reminder\"," + "\"Notes\":\"Exercise full range of motion\",\"HowManyTimesADay\":4," + "\"StartDate\":\"2020-02-11T13:43:34.9119383-07:00\",\"EndDate\":\"2020-03-03T13:43:34.9119383-07:00\"," + "\"NextDue\":\"2020-02-18T13:43:34.9119383-07:00\"}"; var ser = new JsonSerializationService(); var result = ser.Deserialize <Reminder>(json); Assert.IsInstanceOfType(result, typeof(Reminder)); }
public async Task GenerateReport() { DateTime dateTime = DateTime.UtcNow; int ukPrn = 10036143; string filename = $"R01_10036143_10036143 Learner Level View Report {dateTime:yyyyMMdd-HHmmss}"; int academicYear = 2021; 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); reportServiceContextMock.SetupGet(x => x.ReturnPeriod).Returns(1); reportServiceContextMock.SetupGet(x => x.ReturnPeriodName).Returns("R01"); Mock <ILogger> loggerMock = new Mock <ILogger>(); Mock <ICsvFileService> csvFileServiceMock = new Mock <ICsvFileService>(); Mock <IFileNameService> fileNameServiceMock = new Mock <IFileNameService>(); Mock <IUYPSummaryViewDataProvider> uypSummaryViewDataProviderMock = new Mock <IUYPSummaryViewDataProvider>(); Mock <IUYPSummaryViewModelBuilder> uypSummaryViewModelBuilderMock = new Mock <IUYPSummaryViewModelBuilder>(); Mock <IJsonSerializationService> jsonSerializationServiceMock = new Mock <IJsonSerializationService>(); IJsonSerializationService jsonSerializationService = new JsonSerializationService(); Mock <IFileService> fileServiceMock = new Mock <IFileService>(); Mock <IReportDataPersistanceService <LearnerLevelViewReport> > reportDataPersistanceServiceMock = new Mock <IReportDataPersistanceService <LearnerLevelViewReport> >(); Mock <IUYPSummaryViewPersistenceMapper> uypSummaryViewPersistenceMapper = new Mock <IUYPSummaryViewPersistenceMapper>(); var summaryReportDataPersistanceServiceMock = new Mock <IReportDataPersistanceService <UYPSummaryViewReport> >(); var zipServiceMock = new Mock <IReportZipService>(); uypSummaryViewPersistenceMapper.Setup(x => x.Map( It.IsAny <IReportServiceContext>(), It.IsAny <IEnumerable <LearnerLevelViewModel> >(), It.IsAny <CancellationToken>())).Returns(new List <LearnerLevelViewReport>()); uypSummaryViewPersistenceMapper.Setup(x => x.Map( It.IsAny <IReportServiceContext>(), It.IsAny <IEnumerable <LearnerLevelViewSummaryModel> >())).Returns(new List <UYPSummaryViewReport>()); reportDataPersistanceServiceMock.Setup(x => x.PersistAsync( It.IsAny <IReportServiceContext>(), It.IsAny <IEnumerable <LearnerLevelViewReport> >(), It.IsAny <CancellationToken>())); summaryReportDataPersistanceServiceMock.Setup(x => x.PersistAsync( It.IsAny <IReportServiceContext>(), It.IsAny <IEnumerable <UYPSummaryViewReport> >(), It.IsAny <CancellationToken>())); jsonSerializationServiceMock.Setup(x => x.Serialize <IEnumerable <LearnerLevelViewSummaryModel> >( It.IsAny <IEnumerable <LearnerLevelViewSummaryModel> >())).Returns(string.Empty); // We need three streams FileStream[] fs = new FileStream[3] { new FileStream("1.json", FileMode.Create), new FileStream("2.csv", FileMode.Create), new FileStream("3.csv", FileMode.Create) }; var index = 0; fileServiceMock.Setup(x => x.OpenWriteStreamAsync( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync(() => fs[index++]); // Return filenames fileNameServiceMock.Setup(x => x.GetFilename(It.IsAny <IReportServiceContext>(), It.IsAny <string>(), It.IsAny <OutputTypes>(), It.IsAny <bool>(), It.IsAny <bool>())).Returns(filename); // Setup data return objects ICollection <CoInvestmentInfo> coInvestmentInfo = new CoInvestmentInfo[1] { BuildILRCoInvestModel(ukPrn) }; uypSummaryViewDataProviderMock.Setup(x => x.GetCoinvestmentsAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(coInvestmentInfo); ICollection <Payment> payments = BuildDasPaymentsModel(ukPrn, academicYear); uypSummaryViewDataProviderMock.Setup(x => x.GetDASPaymentsAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(payments); ICollection <DataLock> dataLocks = new DataLock[1] { new DataLock() { DataLockFailureId = 1, CollectionPeriod = 1, LearnerReferenceNumber = "A12345" } }; uypSummaryViewDataProviderMock.Setup(x => x.GetDASDataLockAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(dataLocks); ICollection <HBCPInfo> hbcpInfo = new HBCPInfo[1] { new HBCPInfo() { LearnerReferenceNumber = "A12345", CollectionPeriod = 1, NonPaymentReason = 1 } }; uypSummaryViewDataProviderMock.Setup(x => x.GetHBCPInfoAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(hbcpInfo); ICollection <Learner> learners = BuildILRModel(ukPrn); uypSummaryViewDataProviderMock.Setup(x => x.GetILRLearnerInfoAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(learners); ICollection <LearningDeliveryEarning> ldEarnings = BuildLDEarningsModel(ukPrn); uypSummaryViewDataProviderMock.Setup(x => x.GetLearnerDeliveryEarningsAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(ldEarnings); IDictionary <long, string> legalEntityNames = BuildLegalEntityNames(); uypSummaryViewDataProviderMock.Setup(x => x.GetLegalEntityNameAsync(It.IsAny <int>(), It.IsAny <IEnumerable <long> >(), It.IsAny <CancellationToken>())).ReturnsAsync(legalEntityNames); ICollection <PriceEpisodeEarning> peEarnings = BuildPEEarningsModel(ukPrn); uypSummaryViewDataProviderMock.Setup(x => x.GetPriceEpisodeEarningsAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(peEarnings); ICollection <LearnerLevelViewModel> results = new LearnerLevelViewModel[1] { new LearnerLevelViewModel() { Ukprn = ukPrn, PaymentLearnerReferenceNumber = "A12345", PaymentUniqueLearnerNumbers = "12345", FamilyName = "Banner", GivenNames = "Bruce", LearnerEmploymentStatusEmployerId = 1, EmployerName = "Employer Name", TotalEarningsToDate = 1m, PlannedPaymentsToYouToDate = 2m, TotalCoInvestmentCollectedToDate = 3m, CoInvestmentOutstandingFromEmplToDate = 4m, TotalEarningsForPeriod = 5m, ESFAPlannedPaymentsThisPeriod = 6m, CoInvestmentPaymentsToCollectThisPeriod = 7m, IssuesAmount = 8m, ReasonForIssues = "Borked", PaymentFundingLineType = "12345", RuleDescription = "Rule X" } }; uypSummaryViewModelBuilderMock.Setup(x => x.Build( It.IsAny <ICollection <Payment> >(), It.IsAny <ICollection <Learner> >(), It.IsAny <ICollection <LearningDeliveryEarning> >(), It.IsAny <ICollection <PriceEpisodeEarning> >(), It.IsAny <ICollection <CoInvestmentInfo> >(), It.IsAny <ICollection <DataLock> >(), It.IsAny <ICollection <HBCPInfo> >(), It.IsAny <IDictionary <long, string> >(), It.IsAny <int>(), It.IsAny <int>())).Returns(results); // Create and invoke the view Reports.UYPSummaryView.UYPSummaryView report = new Reports.UYPSummaryView.UYPSummaryView( csvFileServiceMock.Object, fileNameServiceMock.Object, uypSummaryViewDataProviderMock.Object, uypSummaryViewModelBuilderMock.Object, jsonSerializationService, fileServiceMock.Object, zipServiceMock.Object, reportDataPersistanceServiceMock.Object, summaryReportDataPersistanceServiceMock.Object, uypSummaryViewPersistenceMapper.Object, loggerMock.Object); await report.GenerateReport(reportServiceContextMock.Object, CancellationToken.None); List <LearnerLevelViewSummaryModel> result; using (var reader = new StreamReader(fs[0].Name)) { string fileData = reader.ReadToEnd(); result = jsonSerializationService.Deserialize <IEnumerable <LearnerLevelViewSummaryModel> >(fileData).ToList(); } result.Should().NotBeNullOrEmpty(); result.Count().Should().Be(1); result[0].CoInvestmentPaymentsToCollectForThisPeriod.Should().Be(7); result[0].ESFAPlannedPaymentsForThisPeriod.Should().Be(6); result[0].NumberofLearners.Should().Be(1); result[0].TotalCoInvestmentCollectedToDate.Should().Be(3); result[0].NumberofClawbacks.Should().Be(0); }
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 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)); }
private async Task <Tuple <Message, ALBGlobal, ValidationErrorDto[], IDataStoreContext> > ReadAndDeserialiseAsync( string ilrFilename, string albFilename, string valErrorsDtoFilename, List <string> validLearners, Mock <IKeyValuePersistenceService> storage, Mock <IKeyValuePersistenceService> persist, Mock <ISerializationService> serialise, Mock <IValidationErrorsService> validationErrorsService) { var xmlSerialiser = new XmlSerializationService(); var jsonSerialiser = new JsonSerializationService(); const string validLearnersKey = "ValidLearners"; const string validLearnersSerialised = "<Serialised String>"; const string keyAlbOutput = "ALB_Output"; const string keyValErrors = "ValErrors"; const string keyValErrorsLookup = "ValErrorsLookup"; string ilrContents, albContents, valErrorsContents; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); using (StreamReader sr = new StreamReader(ilrFilename)) { ilrContents = await sr.ReadToEndAsync(); } output.WriteLine($"Read ILR file: {stopwatch.ElapsedMilliseconds}"); stopwatch.Restart(); using (StreamReader sr = new StreamReader(albFilename)) { albContents = await sr.ReadToEndAsync(); } output.WriteLine($"Read ALB file: {stopwatch.ElapsedMilliseconds}"); stopwatch.Restart(); using (StreamReader sr = new StreamReader(valErrorsDtoFilename)) { valErrorsContents = await sr.ReadToEndAsync(); } output.WriteLine($"Read Val Errors file: {stopwatch.ElapsedMilliseconds}"); stopwatch.Restart(); Message message = xmlSerialiser.Deserialize <Message>(ilrContents); output.WriteLine($"Deserialise ILR: {stopwatch.ElapsedMilliseconds}"); stopwatch.Restart(); ALBGlobal fundingOutputs = jsonSerialiser.Deserialize <ALBGlobal>(albContents); output.WriteLine($"Deserialise ALB: {stopwatch.ElapsedMilliseconds}"); stopwatch.Restart(); ValidationErrorDto[] validationErrorDtos = jsonSerialiser.Deserialize <ValidationErrorDto[]>(valErrorsContents); output.WriteLine($"Deserialise Val: {stopwatch.ElapsedMilliseconds}"); stopwatch.Restart(); var dataStoreContextMock = new Mock <IDataStoreContext>(); dataStoreContextMock.SetupGet(c => c.Filename).Returns(Path.GetFileName(ilrFilename)); dataStoreContextMock.SetupGet(c => c.OriginalFilename).Returns(Path.GetFileName(ilrFilename)); dataStoreContextMock.SetupGet(c => c.ValidLearnRefNumbersKey).Returns(validLearnersKey); dataStoreContextMock.SetupGet(c => c.FileSizeInBytes).Returns(new FileInfo(ilrFilename).Length); dataStoreContextMock.SetupGet(c => c.Ukprn).Returns(message.HeaderEntity.SourceEntity.UKPRN); dataStoreContextMock.SetupGet(c => c.ValidLearnRefNumbersCount).Returns(validLearners.Count); dataStoreContextMock.SetupGet(c => c.InvalidLearnRefNumbersCount).Returns(message.Learner.Length - validLearners.Count); dataStoreContextMock.SetupGet(c => c.ValidationTotalErrorCount).Returns(10); dataStoreContextMock.SetupGet(c => c.ValidationTotalWarningCount).Returns(20); dataStoreContextMock.SetupGet(c => c.FundingALBOutputKey).Returns(keyAlbOutput); dataStoreContextMock.SetupGet(c => c.ValidationErrorsKey).Returns(keyValErrors); dataStoreContextMock.SetupGet(c => c.ValidationErrorsLookupsKey).Returns(keyValErrorsLookup); dataStoreContextMock.SetupGet(c => c.SubmissionDateTimeUtc).Returns(new DateTime(2018, 1, 1)); storage.Setup(x => x.GetAsync(Path.GetFileName(ilrFilename), It.IsAny <CancellationToken>())).ReturnsAsync(ilrContents); // storage.Setup(x => x.GetAsync(Path.GetFileName(albFilename))).ReturnsAsync(albContents); persist.Setup(x => x.GetAsync(validLearnersKey, It.IsAny <CancellationToken>())).ReturnsAsync(validLearnersSerialised); persist.Setup(x => x.GetAsync(keyAlbOutput, It.IsAny <CancellationToken>())).ReturnsAsync(albContents); serialise.Setup(x => x.Deserialize <List <string> >(validLearnersSerialised)).Returns(validLearners); serialise.Setup(x => x.Deserialize <Message>(ilrContents)).Returns(message); serialise.Setup(x => x.Deserialize <ALBGlobal>(albContents)).Returns(fundingOutputs); validationErrorsService.Setup(x => x.GetValidationErrorsAsync(keyValErrors, keyValErrorsLookup)) .ReturnsAsync(validationErrorDtos); output.WriteLine($"Moq: {stopwatch.ElapsedMilliseconds}"); return(new Tuple <Message, ALBGlobal, ValidationErrorDto[], IDataStoreContext>(message, fundingOutputs, validationErrorDtos, dataStoreContextMock.Object)); }