public async Task <DocumentDto> UploadAsync(FileUploadInfoDto fileUploadInfo)
        {
            var isUploaded = await _fileStorageHandler.UploadFileToStorageAsync(fileUploadInfo.FileName, fileUploadInfo.FileContent);

            if (!isUploaded)
            {
                _logger.LogError($"File storage failed to upload '{fileUploadInfo.FileName}' document");
                throw new DocumentUploadException("Provided pdf document failed to upload");
            }

            var insertEntity = new DocumentEntity
            {
                Id                  = fileUploadInfo.FileName,
                ContentType         = MediaTypeNames.Application.Pdf,
                FileSizeInKilobytes = fileUploadInfo.FileSizeInBytes,
                Path                = fileUploadInfo.DownloadFilePath
            };
            await _pdfDocumentRepository.InsertOrReplacePdfDocumentAsync(insertEntity);

            return(new DocumentDto
            {
                Name = fileUploadInfo.FileName,
                FileSize = $"{fileUploadInfo.FileSizeInBytes / 1000} MB",
                Path = fileUploadInfo.DownloadFilePath
            });
        }
Ejemplo n.º 2
0
        public void LogError_LogMessageSentWithErrorLogLevel()
        {
            //Arrange
            var message           = _fixture.Create <string>();
            var serilogLoggerMock = new Mock <ISerilogLogger>();

            _serviceLoggerFactoryMock
            .Setup(factory => factory.GetLogger())
            .Returns(serilogLoggerMock.Object);

            //Act
            _sut.LogError(message);

            //Assert
            serilogLoggerMock
            .Verify(logger => logger.Write(LogEventLevel.Error, message), Times.Once);
        }