public async Task <IActionResult> GetAppealFile([FromRoute] GetAppealFileRequest request) { var query = new GetAppealFileQuery { ApplicationId = request.ApplicationId, FileName = request.FileName }; var appealFile = await _mediator.Send(query); if (appealFile is null) { _logger.LogError($"Unable to find appeal file for application: {request.ApplicationId} || fileName {request.FileName}"); return(NotFound()); } var file = await _fileStorageService.DownloadApplicationFile(appealFile.ApplicationId, appealFile.FileName, ContainerType.Appeals, new CancellationToken()); if (file is null) { _logger.LogError($"Unable to download appeal file for application: {request.ApplicationId} || fileName {request.FileName}"); return(NotFound()); } return(File(file.Stream, file.ContentType, file.FileName)); }
public async Task GetAppealFile_gets_AppealFile_for_Application_Appeal() { var applicationId = AutoFixture.Create <Guid>(); var fileName = AutoFixture.Create <string>(); var contentType = "application/pdf"; var request = new GetAppealFileRequest { ApplicationId = applicationId, FileName = fileName }; var appealFile = new Domain.QueryResults.AppealFile { ApplicationId = applicationId, FileName = fileName, ContentType = contentType }; _mediator.Setup(x => x.Send(It.IsAny <GetAppealFileQuery>(), It.IsAny <CancellationToken>())).ReturnsAsync(appealFile); var storageFile = new DownloadFile { Stream = new MemoryStream(), ContentType = contentType, FileName = fileName }; _fileStorageService.Setup(x => x.DownloadApplicationFile(applicationId, storageFile.FileName, It.IsAny <ContainerType>(), It.IsAny <CancellationToken>())).ReturnsAsync(storageFile); var result = await _controller.GetAppealFile(request); result.Should().BeOfType <FileStreamResult>(); var fileResult = result as FileStreamResult; Assert.AreEqual(storageFile.FileName, fileResult.FileDownloadName); Assert.AreEqual(storageFile.ContentType, fileResult.ContentType); }