diff --git a/docs/Architecting and Developing Modern Web Applications with ASP.NET Core and Azure.pdf b/docs/Architecting and Developing Modern Web Applications with ASP.NET Core and Azure.pdf index 4f4b4be2d..1582bb5d8 100644 Binary files a/docs/Architecting and Developing Modern Web Applications with ASP.NET Core and Azure.pdf and b/docs/Architecting and Developing Modern Web Applications with ASP.NET Core and Azure.pdf differ diff --git a/tests/IntegrationTests/Infrastructure/File/LocalFileImageServiceGetImageBytesById.cs b/tests/IntegrationTests/Infrastructure/File/LocalFileImageServiceGetImageBytesById.cs new file mode 100644 index 000000000..77bc8eeda --- /dev/null +++ b/tests/IntegrationTests/Infrastructure/File/LocalFileImageServiceGetImageBytesById.cs @@ -0,0 +1,47 @@ +using Infrastructure.FileSystem; +using Microsoft.AspNetCore.Hosting; +using System.IO; +using Xunit; +using Moq; + +namespace IntegrationTests.Infrastructure.File +{ +public class LocalFileImageServiceGetImageBytesById +{ + private byte[] _testBytes = new byte[] { 0x01, 0x02, 0x03 }; + private readonly Mock _mockEnvironment = new Mock(); + private int _testImageId = 123; + private string _testFileName = "123.png"; + + public LocalFileImageServiceGetImageBytesById() + { + // create folder if necessary + Directory.CreateDirectory(Path.Combine(GetFileDirectory(), "Pics")); + + string filePath = GetFilePath(_testFileName); + System.IO.File.WriteAllBytes(filePath, _testBytes); + _mockEnvironment.SetupGet(m => m.ContentRootPath).Returns(GetFileDirectory()); + } + + private string GetFilePath(string fileName) + { + return Path.Combine(GetFileDirectory(), "Pics", fileName); + } + + private string GetFileDirectory() + { + var location = System.Reflection.Assembly.GetEntryAssembly().Location; + return Path.GetDirectoryName(location); + } + + [Fact] + public void ReturnsFileContentResultGivenValidId() + { + var fileService = new LocalFileImageService(_mockEnvironment.Object); + + var result = fileService.GetImageBytesById(_testImageId); + + Assert.Equal(_testBytes, result); + } +} +} diff --git a/tests/IntegrationTests/IntegrationTests.csproj b/tests/IntegrationTests/IntegrationTests.csproj index c3a488162..ba2269bd3 100644 --- a/tests/IntegrationTests/IntegrationTests.csproj +++ b/tests/IntegrationTests/IntegrationTests.csproj @@ -8,6 +8,8 @@ + +