public void UpdateCollectionPeriod(int year, int month, int day, int assertion) { var returnPeriods = ReturnPeriods(); var desktopContextMock = new Mock <IDesktopContext>(); desktopContextMock.Setup(dm => dm.KeyValuePairs) .Returns(new Dictionary <string, object> { { "ReturnPeriod", 0 } }); IReferenceDataContext referenceDataContext = new ReferenceDataJobContextMessageContext(desktopContextMock.Object); NewService().UpdateCollectionPeriod(referenceDataContext, new DateTime(year, month, day), returnPeriods); referenceDataContext.ReturnPeriod.Should().Be(assertion); }
public async Task <IDesktopContext> ExecuteAsync(IDesktopContext desktopContext, CancellationToken cancellationToken) { // Create context IReferenceDataContext referenceDataContext = new ReferenceDataJobContextMessageContext(desktopContext); // Retrieving ILR File _logger.LogInfo("Starting ILR File Retrieval"); var message = await _messageProvider.ProvideAsync(referenceDataContext, cancellationToken); _logger.LogInfo("Finished ILR File Retrieval"); // get reference data and build model. _logger.LogInfo("Starting Reference Data Population"); var referenceData = await _referenceDataPopulationService.PopulateAsync(referenceDataContext, message, cancellationToken); _logger.LogInfo("Finished Reference Data Population"); // output model. _logger.LogInfo("Starting Reference Data Output"); await _filePersister.StoreAsync(referenceDataContext.OutputIlrReferenceDataFileKey, referenceDataContext.Container, referenceData, compressOutput, cancellationToken); _logger.LogInfo("Finished Reference Data Output"); // set return period _logger.LogInfo("Adding Return Period and Ukprn to Context"); _desktopContextReturnPeriodUpdateService.UpdateCollectionPeriod( referenceDataContext, message.HeaderEntity.CollectionDetailsEntity.FilePreparationDate, referenceData.MetaDatas.CollectionDates.ReturnPeriods); var ukprn = message?.HeaderEntity?.SourceEntity?.UKPRN; if (ukprn != null) { referenceDataContext.Ukprn = ukprn.Value; } _logger.LogInfo($"Finished adding Return Period : {referenceDataContext.ReturnPeriod} and Ukprn : {referenceDataContext.Ukprn} to Context"); return(desktopContext); }
public async Task ExecuteAsync() { var cancellationToken = CancellationToken.None; IReadOnlyCollection <ReturnPeriod> returnPeriods = new List <ReturnPeriod> { new ReturnPeriod { Name = "R01", Period = 1, Start = new DateTime(2019, 08, 23), End = new DateTime(2019, 09, 06, 23, 59, 59) }, new ReturnPeriod { Name = "R02", Period = 2, Start = new DateTime(2019, 09, 07), End = new DateTime(2019, 10, 04, 23, 59, 59) }, new ReturnPeriod { Name = "R03", Period = 3, Start = new DateTime(2019, 10, 05), End = new DateTime(2019, 11, 06, 23, 59, 59) }, new ReturnPeriod { Name = "R04", Period = 4, Start = new DateTime(2019, 11, 07), End = new DateTime(2019, 12, 06, 23, 59, 59) }, new ReturnPeriod { Name = "R05", Period = 5, Start = new DateTime(2019, 12, 07), End = new DateTime(2020, 01, 07, 23, 59, 59) }, new ReturnPeriod { Name = "R06", Period = 6, Start = new DateTime(2020, 01, 08), End = new DateTime(2020, 02, 06, 23, 59, 59) }, new ReturnPeriod { Name = "R07", Period = 7, Start = new DateTime(2020, 02, 07), End = new DateTime(2020, 03, 06, 23, 59, 59) }, new ReturnPeriod { Name = "R08", Period = 8, Start = new DateTime(2020, 03, 07), End = new DateTime(2020, 04, 04, 23, 59, 59) }, new ReturnPeriod { Name = "R09", Period = 9, Start = new DateTime(2020, 04, 05), End = new DateTime(2020, 05, 07, 23, 59, 59) }, new ReturnPeriod { Name = "R10", Period = 10, Start = new DateTime(2020, 05, 08), End = new DateTime(2020, 06, 06, 23, 59, 59) }, new ReturnPeriod { Name = "R11", Period = 11, Start = new DateTime(2020, 06, 07), End = new DateTime(2020, 07, 04, 23, 59, 59) }, new ReturnPeriod { Name = "R12", Period = 12, Start = new DateTime(2020, 07, 05), End = new DateTime(2020, 08, 06, 23, 59, 59) }, new ReturnPeriod { Name = "R13", Period = 13, Start = new DateTime(2020, 08, 07), End = new DateTime(2020, 09, 13, 23, 59, 59) }, new ReturnPeriod { Name = "R14", Period = 14, Start = new DateTime(2020, 09, 14), End = new DateTime(2020, 10, 17, 23, 59, 59) }, }; var desktopContextMock = new Mock <IDesktopContext>(); desktopContextMock.Setup(dm => dm.KeyValuePairs) .Returns(new Dictionary <string, object> { { "IlrReferenceData", "IlrReferenceData" }, { "OriginalFilename", "OriginalFilename" }, { "Filename", "Filename" }, { "Container", "Container" }, { "ReturnPeriod", 0 }, { "UkPrn", 12345678 } }); IReferenceDataContext referenceDataContext = new ReferenceDataJobContextMessageContext(desktopContextMock.Object); var messageProviderMock = new Mock <IMessageProvider>(); var referenceDataPopulationServiceMock = new Mock <IReferenceDataPopulationService>(); var filePersisterMock = new Mock <IFilePersister>(); var desktopContextReturnPeriodUpdateServiceMock = new Mock <IDesktopContextReturnPeriodUpdateService>(); var loggerMock = new Mock <ILogger>(); IMessage message = new TestMessage { HeaderEntity = new TestHeader { CollectionDetailsEntity = new TestCollectionDetails { FilePreparationDate = new DateTime(2019, 9, 1) } } }; var referenceDataRoot = new ReferenceDataRoot { MetaDatas = new Model.MetaData.MetaData { CollectionDates = new IlrCollectionDates { ReturnPeriods = returnPeriods } } }; messageProviderMock.Setup(p => p.ProvideAsync(It.IsAny <IReferenceDataContext>(), cancellationToken)).Returns(Task.FromResult(message)).Verifiable(); referenceDataPopulationServiceMock.Setup(s => s.PopulateAsync(It.IsAny <IReferenceDataContext>(), message, cancellationToken)).Returns(Task.FromResult(referenceDataRoot)).Verifiable(); filePersisterMock.Setup(s => s.StoreAsync(referenceDataContext.OutputIlrReferenceDataFileKey, referenceDataContext.Container, referenceDataRoot, false, cancellationToken)).Returns(Task.CompletedTask).Verifiable(); desktopContextReturnPeriodUpdateServiceMock.Setup(m => m.UpdateCollectionPeriod(It.IsAny <IReferenceDataContext>(), It.IsAny <DateTime>(), referenceDataRoot.MetaDatas.CollectionDates.ReturnPeriods)).Verifiable(); var task = NewTask( messageProviderMock.Object, referenceDataPopulationServiceMock.Object, filePersisterMock.Object, desktopContextReturnPeriodUpdateServiceMock.Object, loggerMock.Object); await task.ExecuteAsync(desktopContextMock.Object, cancellationToken); messageProviderMock.VerifyAll(); referenceDataPopulationServiceMock.VerifyAll(); filePersisterMock.VerifyAll(); desktopContextReturnPeriodUpdateServiceMock.VerifyAll(); }