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 async Task InsertOrReplacePdfDocumentAsync_DocumentUpserted()
        {
            //Arrange
            var documentEntity = _fixture.Create <DocumentEntity>();

            var documentClientMock = new Mock <IDocumentClient>();

            _documentClientFactoryMock
            .Setup(factory => factory.GetClient())
            .Returns(documentClientMock.Object);

            //Act
            await _sut.InsertOrReplacePdfDocumentAsync(documentEntity);

            //Assert
            documentClientMock.Verify(
                client => client.UpsertDocumentAsync(
                    It.IsAny <Uri>(),
                    It.IsAny <object>(),
                    It.IsAny <RequestOptions>(),
                    It.IsAny <bool>(),
                    It.IsAny <CancellationToken>()),
                Times.Once);
        }