public async Task <bool> CreateSerialEncFile(string batchId, string exchangeSetPath, string correlationId) { bool checkSerialEncFileCreated = false; if (!string.IsNullOrWhiteSpace(exchangeSetPath)) { string serialFilePath = Path.Combine(exchangeSetPath, fileShareServiceConfig.Value.SerialFileName); fileSystemHelper.CheckAndCreateFolder(exchangeSetPath); int weekNumber = CommonHelper.GetCurrentWeekNumber(DateTime.UtcNow); var serialFileContent = String.Format("GBWK{0:D2}-{1} {2:D4}{3:D2}{4:D2}UPDATE {5:D2}.00{6}\x0b\x0d\x0a", weekNumber, DateTime.UtcNow.Year.ToString("D4").Substring(2), DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 2, "U01X01"); fileSystemHelper.CreateFileContent(serialFilePath, serialFileContent); await Task.CompletedTask; if (fileSystemHelper.CheckFileExists(serialFilePath)) { checkSerialEncFileCreated = true; } else { logger.LogError(EventIds.SerialFileIsNotCreated.ToEventId(), "Error in creating serial.enc file for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} - Invalid Exchange Set Path", batchId, correlationId); throw new FulfilmentException(EventIds.SerialFileIsNotCreated.ToEventId()); } } return(checkSerialEncFileCreated); }
public void WhenInvalidCreateSerialEncFileRequest_ThenReturnFulfilmentException() { fakeExchangeSetPath = @"C:\\HOME"; A.CallTo(() => fakeFileSystemHelper.CheckAndCreateFolder(A <string> .Ignored)); A.CallTo(() => fakeFileSystemHelper.CreateFileContent(A <string> .Ignored, A <string> .Ignored)).Returns(true); A.CallTo(() => fakeFileSystemHelper.CheckFileExists(A <string> .Ignored)).Returns(false); Assert.ThrowsAsync(Is.TypeOf <FulfilmentException>().And.Message.EqualTo(fulfilmentExceptionMessage), async delegate { await fulfilmentAncillaryFiles.CreateSerialEncFile(fakeBatchId, fakeExchangeSetInfoPath, null); }); }
public async Task CreateAndUploadErrorFileToFileShareService(SalesCatalogueServiceResponseQueueMessage fulfilmentServiceQueueMessage, EventId eventId, string errorMessage, string batchFolderPath) { fileSystemHelper.CheckAndCreateFolder(batchFolderPath); var errorFileFullPath = Path.Combine(batchFolderPath, fileShareServiceConfig.Value.ErrorFileName); fileSystemHelper.CreateFileContent(errorFileFullPath, errorMessage); if (fileSystemHelper.CheckFileExists(errorFileFullPath)) { var isUploaded = await fileShareService.UploadFileToFileShareService(fulfilmentServiceQueueMessage.BatchId, batchFolderPath, fulfilmentServiceQueueMessage.CorrelationId, fileShareServiceConfig.Value.ErrorFileName); if (isUploaded) { logger.LogError(EventIds.ErrorTxtIsUploaded.ToEventId(), "Error while processing Exchange Set creation and error.txt file is created and uploaded in file share service with ErrorCode-EventId:{EventId} and EventName:{EventName} for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", eventId.Id, eventId.Name, fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); logger.LogError(EventIds.ExchangeSetCreatedWithError.ToEventId(), "Exchange set is created with error for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); } else { logger.LogError(EventIds.ErrorTxtNotUploaded.ToEventId(), "Error while uploading error.txt file to file share service for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); } } else { logger.LogError(EventIds.ErrorTxtNotCreated.ToEventId(), "Error while creating error.txt for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", fulfilmentServiceQueueMessage.BatchId, fulfilmentServiceQueueMessage.CorrelationId); } await SendErrorCallBackResponse(fulfilmentServiceQueueMessage); }