public void Can_Retrieve_Image_Data() { // Arrange Product prod = new Product { ProductID = 2, Name = "Test", ImageData = new byte[] { }, ImageMimeType = "image/png" }; Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1"}, prod, new Product { ProductID = 3, Name = "P3"} }.AsQueryable()); ProductController target = new ProductController(mock.Object); // Act ActionResult result = target.GetImage(2); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(FileResult)); Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType); }
public void Cannot_Retrieve_Image_Data_For_Invalid_ID() { // Arrange Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1"}, new Product { ProductID = 2, Name = "P2"}, new Product { ProductID = 3, Name = "P3"} }.AsQueryable()); ProductController target = new ProductController(mock.Object); // Act ActionResult result = target.GetImage(100); // Assert Assert.IsNull(result); }