public void CanRetrieveImageData() { // Arrange - create a Product with image data var product = new Product { ProductId = 2, Name = "Test", ImageData = new byte[] { }, ImageMimeType = "image/png" }; // Arrange - create the mock repository var localMock = new Mock<IProductRepository>(); localMock.Setup(m => m.Products).Returns( new[] { new Product { ProductId = 1, Name = "P1" }, product, new Product { ProductId = 3, Name = "P3" } }. AsQueryable()); // Arrange - create the controller var controller = new ProductController(localMock.Object); // Action - call the GetImage action method ActionResult result = controller.GetImage(2); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(FileResult)); Assert.AreEqual(product.ImageMimeType, ((FileResult)result).ContentType); }
public void CannotRetrieveImageDataForInvalidId() { // Arrange - create the controller var controller = new ProductController(_mockRepository.Object); // Action - call the GetImage action method ActionResult result = controller.GetImage(100); // Assert Assert.IsNull(result); }