Esempio n. 1
0
        public void TestMethod4()
        {
            List <Picture> lista1 = new List <Picture>();

            lista1.Add(new Picture()
            {
                Id     = 1,
                Name   = "test1",
                Price  = 120m,
                Galery = new Galery()
                {
                    Id = 1, Name = "Galery1"
                }
            });
            lista1.Add(new Picture()
            {
                Id     = 2,
                Name   = "test2",
                Price  = 130m,
                Galery = new Galery()
                {
                    Id = 2, Name = "Galery2"
                }
            });

            var mockRepository = new Mock <IPictureRepository>();

            mockRepository.Setup(x => x.PostSearch(101m, 150m)).Returns(lista1.AsQueryable());
            var controller = new PicturesController(mockRepository.Object);

            IHttpActionResult result = controller.PostSearch(101m, 150m);
            var finalResult          = result as OkNegotiatedContentResult <IQueryable <PictureDTO> >;

            Assert.IsNotNull(finalResult);
            Assert.AreEqual(lista1.Count, finalResult.Content.ToList().Count);

            Assert.AreEqual(lista1.ElementAt(0).Id, finalResult.Content.ToList().ElementAt(0).Id);
            Assert.AreEqual(lista1.ElementAt(0).Name, finalResult.Content.ToList().ElementAt(0).Name);
            Assert.AreEqual(lista1.ElementAt(0).Galery.Name, finalResult.Content.ToList().ElementAt(0).GaleryName);

            Assert.AreEqual(lista1.ElementAt(1).Id, finalResult.Content.ToList().ElementAt(1).Id);
            Assert.AreEqual(lista1.ElementAt(1).Name, finalResult.Content.ToList().ElementAt(1).Name);
            Assert.AreEqual(lista1.ElementAt(1).Galery.Name, finalResult.Content.ToList().ElementAt(1).GaleryName);
        }