public async Task UploadAsync_UploadToFileStorageFailed_DocumentUploadExceptionIsThrown()
        {
            //Arrange
            await using var fileContentStream = new MemoryStream();
            var fileUploadDto = _fixture.Build <FileUploadInfoDto>()
                                .With(dto => dto.FileContent, fileContentStream)
                                .Create();

            _fileStorageHandlerMock
            .Setup(handler => handler.UploadFileToStorageAsync(fileUploadDto.FileName, fileUploadDto.FileContent))
            .ReturnsAsync(false);

            //Act
            await Should.ThrowAsync <DocumentUploadException>(_sut.UploadAsync(fileUploadDto));
        }
        public async Task <IActionResult> Upload(IFormFile fileToUpload)
        {
            if (fileToUpload == null)
            {
                _logger.LogWarning("Invalid file request");
                return(BadRequest("File request is invalid"));
            }

            if (fileToUpload.ContentType != MediaTypeNames.Application.Pdf)
            {
                _logger.LogWarning($"Uploaded content type '{fileToUpload.ContentType}' requested which is not pdf.");
                return(BadRequest($"File '{fileToUpload.Name}' type is not pdf"));
            }

            var pdfSizeLimit = _configuration.GetValue <long>(PdfDocumentAllowedSizeLimitKey);

            if (fileToUpload.Length > pdfSizeLimit)
            {
                _logger.LogWarning($"Uploaded file size '{fileToUpload.Length} KB' is exceeding threshold of allowed size limit {pdfSizeLimit} KB'");
                return(BadRequest($"File '{fileToUpload.FileName}' size is more than {pdfSizeLimit} KB"));
            }

            var downloadFilePath = Url.ActionLink(action: "Download", values: new { fileName = fileToUpload.FileName });

            await using var fileContentStream = fileToUpload.OpenReadStream();
            var uploadedData = await _pdfDocumentHandler
                               .UploadAsync(new FileUploadInfoDto
            {
                FileContent      = fileContentStream,
                FileName         = Path.GetFileName(fileToUpload.FileName),
                FileSizeInBytes  = fileToUpload.Length,
                DownloadFilePath = downloadFilePath
            });

            return(Created(downloadFilePath, uploadedData));
        }