Пример #1
0
        public void Recive_Invalid_Id_Image_Test()
        {
            // Arrange
            Mock <ILotsRepository> mock = new Mock <ILotsRepository>();

            mock.Setup(m => m.Lots).Returns(new Lot[]
            {
                new Lot {
                    LotID = 1, Name = "P1"
                },
                new Lot {
                    LotID = 2, Name = "P2"
                }
            }.AsQueryable());
            LotsController target = new LotsController(mock.Object, null);
            // Act
            ActionResult result = target.GetImage(100, 0);

            // Assert
            Assert.IsNull(result);
        }
Пример #2
0
        public void Get_Image_Test()
        {
            // Arrange - create a Lot with image data
            Lot prod = new Lot
            {
                LotID  = 2,
                Name   = "Test",
                Images = new List <Image>
                {
                    new Image
                    {
                        ImageData     = new byte[] {},
                        ImageMimeType = "image/png"
                    }
                }
            };
            // Arrange - create the mock repository
            Mock <ILotsRepository> mock = new Mock <ILotsRepository>();

            mock.Setup(m => m.Lots).Returns(new Lot[] {
                new Lot {
                    LotID = 1, Name = "P1"
                },
                prod,
                new Lot {
                    LotID = 3, Name = "P3"
                }
            }.AsQueryable());
            // Arrange - create the controller
            LotsController target = new LotsController(mock.Object, null);
            // Act - call the GetImage action method
            ActionResult result = target.GetImage(2, 0);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(prod.Images.First().ImageMimeType, ((FileResult)result).ContentType);
        }