Esempio n. 1
0
        public void Can_Retrieve_Image_Data()
        {
            // Arrange - create a Product with image data
            Product prod = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };
            // Arrange - create the mock repository
            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());
            // Arrange - create the controller
            ProductController target = new ProductController(mock.Object);

            // Act - call the GetImage action method
            ActionResult result = target.GetImage(2);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(prod.ImageMimeType,
            ((FileResult)result).ContentType);
        }
Esempio n. 2
0
 public void Cannot_Retrieve_Image_Data_For_Invalid_ID()
 {
     var mock = new Mock<IProductRepository>();
     mock.Setup(m => m.Products).Returns(new Product[]
     {
      new Product(){ProductID = 1,Name = "P1"}, 
      new Product(){ProductID = 2,Name="P2"}, 
     }.AsQueryable());
     var target = new ProductController(mock.Object);
     ActionResult result = target.GetImage(100);
     Assert.IsNull(result);
 }
Esempio n. 3
0
        public void Cannot_Retrieve_Image_Data_For_Invalid_ID()
        {
            // Arrange - create the mock repository
            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"}
                }.AsQueryable());
            // Arrange - create the controller
            ProductController target = new ProductController(mock.Object);

            // Act - call the GetImage action method
            ActionResult result = target.GetImage(100);

            // Assert
            Assert.IsNull(result);
        }
Esempio n. 4
0
 public void Can_Retrieve_Image_Data()
 {
     var prod = new Product
     {
         ProductID = 2,
         Name = "Test",
         ImageData = new byte[] { },
         ImageMimeType = "image/png"
     };
     var mock = new Mock<IProductRepository>();
     mock.Setup(m => m.Products)
         .Returns(value: new Product[]
         {
             new Product{ProductID = 1,Name = "P1"},
             prod,
             new Product(){ProductID = 3,Name = "P3"}, 
         }.AsQueryable());
     var target = new ProductController(mock.Object);
     ActionResult result = target.GetImage(2);
     Assert.IsNotNull(result);
     Assert.IsInstanceOfType(result, typeof(FileResult));
     Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType);
 }