Skip to content

Commit

Permalink
adding integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis committed Apr 30, 2017
1 parent 22cd5ed commit 235b946
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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<IHostingEnvironment> _mockEnvironment = new Mock<IHostingEnvironment>();
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<string>(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);
}
}
}
2 changes: 2 additions & 0 deletions tests/IntegrationTests/IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="Moq" Version="4.7.8" />

</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 235b946

Please sign in to comment.