public async Task <FileDownloadInfo> DownloadFileAsync(string fileName) { var client = _blobClientFactory.GetContainerClient(AzureBlobConstants.BlobDocumentsContainerName); var lowerFileName = fileName.ToLower(); var blobClient = client.GetBlobClient(lowerFileName); var isBlobClientExists = await blobClient.ExistsAsync(); if (!isBlobClientExists) { _serviceLogger.LogWarning($"File '{fileName}' is not found in blob storage"); return(new FileDownloadInfo { Status = HttpStatusCode.NotFound.ToString("G"), Content = null, ContentType = string.Empty }); } var downloadResult = await blobClient.DownloadAsync(); using var downloadInfo = downloadResult.Value; using var rawResponse = downloadResult.GetRawResponse(); _serviceLogger.LogInfo($"File '{fileName}' download responded with status '{rawResponse.Status}-{rawResponse.ReasonPhrase}'"); return(new FileDownloadInfo { Status = rawResponse.ReasonPhrase, ContentType = downloadInfo.ContentType, Content = downloadInfo.Content }); }
public void LogWarning_LogMessageSentWithWarningLogLevel() { //Arrange var message = _fixture.Create <string>(); var serilogLoggerMock = new Mock <ISerilogLogger>(); _serviceLoggerFactoryMock .Setup(factory => factory.GetLogger()) .Returns(serilogLoggerMock.Object); //Act _sut.LogWarning(message); //Assert serilogLoggerMock .Verify(logger => logger.Write(LogEventLevel.Warning, message), Times.Once); }
public async Task <IActionResult> Download([FromRoute] string fileName) { if (string.IsNullOrEmpty(fileName)) { _logger.LogWarning("Attempt to download a file with empty name."); return(BadRequest("File name should not be empty")); } var downloadInfo = await _pdfDocumentHandler.DownloadAsync(fileName); if (downloadInfo.Status == HttpStatusCode.NotFound.ToString("G")) { _logger.LogWarning("Attempt to download not existing file."); return(NotFound($"File with name '{fileName}' does not exist")); } return(File(downloadInfo.Content, downloadInfo.ContentType)); }