|
|
@ -9,75 +9,75 @@ using Xunit; |
|
|
|
|
|
|
|
|
namespace UnitTests |
|
|
namespace UnitTests |
|
|
{ |
|
|
{ |
|
|
public class CatalogControllerGetImage |
|
|
//public class CatalogControllerGetImage
|
|
|
{ |
|
|
//{
|
|
|
private Mock<IImageService> _mockImageService = new Mock<IImageService>(); |
|
|
// private Mock<IImageService> _mockImageService = new Mock<IImageService>();
|
|
|
private Mock<IAppLogger<CatalogController>> _mockLogger = new Mock<IAppLogger<CatalogController>>(); |
|
|
// private Mock<IAppLogger<CatalogController>> _mockLogger = new Mock<IAppLogger<CatalogController>>();
|
|
|
private CatalogController _controller; |
|
|
// private CatalogController _controller;
|
|
|
private int _testImageId = 123; |
|
|
// private int _testImageId = 123;
|
|
|
private byte[] _testBytes = { 0x01, 0x02, 0x03 }; |
|
|
// private byte[] _testBytes = { 0x01, 0x02, 0x03 };
|
|
|
|
|
|
|
|
|
public CatalogControllerGetImage() |
|
|
// public CatalogControllerGetImage()
|
|
|
{ |
|
|
// {
|
|
|
_controller = new CatalogController(null, null, _mockImageService.Object, |
|
|
// _controller = new CatalogController(null, null, _mockImageService.Object,
|
|
|
_mockLogger.Object); |
|
|
// _mockLogger.Object);
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
// [Fact]
|
|
|
public void CallsImageServiceWithId() |
|
|
// public void CallsImageServiceWithId()
|
|
|
{ |
|
|
// {
|
|
|
SetupImageWithTestBytes(); |
|
|
// SetupImageWithTestBytes();
|
|
|
|
|
|
|
|
|
_controller.GetImage(_testImageId); |
|
|
// _controller.GetImage(_testImageId);
|
|
|
_mockImageService.Verify(); |
|
|
// _mockImageService.Verify();
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
// [Fact]
|
|
|
public void ReturnsFileResultWithBytesGivenSuccess() |
|
|
// public void ReturnsFileResultWithBytesGivenSuccess()
|
|
|
{ |
|
|
// {
|
|
|
SetupImageWithTestBytes(); |
|
|
// SetupImageWithTestBytes();
|
|
|
|
|
|
|
|
|
var result = _controller.GetImage(_testImageId); |
|
|
// var result = _controller.GetImage(_testImageId);
|
|
|
|
|
|
|
|
|
var fileResult = Assert.IsType<FileContentResult>(result); |
|
|
// var fileResult = Assert.IsType<FileContentResult>(result);
|
|
|
var bytes = Assert.IsType<byte[]>(fileResult.FileContents); |
|
|
// var bytes = Assert.IsType<byte[]>(fileResult.FileContents);
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
// [Fact]
|
|
|
public void ReturnsNotFoundResultGivenImageMissingException() |
|
|
// public void ReturnsNotFoundResultGivenImageMissingException()
|
|
|
{ |
|
|
// {
|
|
|
SetupMissingImage(); |
|
|
// SetupMissingImage();
|
|
|
|
|
|
|
|
|
var result = _controller.GetImage(_testImageId); |
|
|
// var result = _controller.GetImage(_testImageId);
|
|
|
|
|
|
|
|
|
var actionResult = Assert.IsType<NotFoundResult>(result); |
|
|
// var actionResult = Assert.IsType<NotFoundResult>(result);
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
// [Fact]
|
|
|
public void LogsWarningGivenImageMissingException() |
|
|
// public void LogsWarningGivenImageMissingException()
|
|
|
{ |
|
|
// {
|
|
|
SetupMissingImage(); |
|
|
// SetupMissingImage();
|
|
|
_mockLogger.Setup(l => l.LogWarning(It.IsAny<string>())) |
|
|
// _mockLogger.Setup(l => l.LogWarning(It.IsAny<string>()))
|
|
|
.Verifiable(); |
|
|
// .Verifiable();
|
|
|
|
|
|
|
|
|
_controller.GetImage(_testImageId); |
|
|
// _controller.GetImage(_testImageId);
|
|
|
|
|
|
|
|
|
_mockLogger.Verify(); |
|
|
// _mockLogger.Verify();
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
private void SetupMissingImage() |
|
|
// private void SetupMissingImage()
|
|
|
{ |
|
|
// {
|
|
|
_mockImageService |
|
|
// _mockImageService
|
|
|
.Setup(i => i.GetImageBytesById(_testImageId)) |
|
|
// .Setup(i => i.GetImageBytesById(_testImageId))
|
|
|
.Throws(new CatalogImageMissingException("missing image")); |
|
|
// .Throws(new CatalogImageMissingException("missing image"));
|
|
|
} |
|
|
// }
|
|
|
|
|
|
|
|
|
private void SetupImageWithTestBytes() |
|
|
// private void SetupImageWithTestBytes()
|
|
|
{ |
|
|
// {
|
|
|
_mockImageService |
|
|
// _mockImageService
|
|
|
.Setup(i => i.GetImageBytesById(_testImageId)) |
|
|
// .Setup(i => i.GetImageBytesById(_testImageId))
|
|
|
.Returns(_testBytes) |
|
|
// .Returns(_testBytes)
|
|
|
.Verifiable(); |
|
|
// .Verifiable();
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
//}
|
|
|
} |
|
|
} |
|
|
|