Esempio n. 1
0
        public void GetReturnsMultipleObjects()
        {
            //Mapper.Initialize(cfg =>
            //{
            //    cfg.CreateMap<Picture, PictureDTO>() // automatski će mapirati Author.Name u AuthorName
            //    .ForMember(dest => dest.GalleryName, opt => opt.MapFrom(src => src.Galery.Name)); // ako želimo eksplicitno zadati mapiranje
            //});
            // Arrange
            List <Picture> pictures = new List <Picture>();

            pictures.Add(new Picture {
                Id = 1, Name = "Picture1", Price = 200, Galery = new Gallery {
                    Id = 1, Name = "blabla"
                }
            });
            pictures.Add(new Picture {
                Id = 2, Name = "Picture2", Price = 400, Galery = new Gallery {
                    Id = 2, Name = "blabla"
                }
            });

            var mockRepository = new Mock <IPictureRepo>();

            mockRepository.Setup(x => x.SearchByPrice(100, 500)).Returns(pictures.AsQueryable);
            var controller = new PicturesController(mockRepository.Object);

            // Act
            var result = controller.GetSearchByPrice(100, 500);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(pictures.Count, result.ToList().Count);
            Assert.AreEqual(pictures.ElementAt(0).Id, result.ElementAt(0).Id);
            Assert.AreEqual(pictures.ElementAt(1).Id, result.ElementAt(1).Id);
        }