コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: 4thePeace2/ArtGallery
        public void TestMethod3()
        {
            List <Picture> lista = new List <Picture>();

            lista.Add(new Picture()
            {
                Id     = 1,
                Name   = "test1",
                Galery = new Galery()
                {
                    Id = 1, Name = "Galery1"
                }
            });
            lista.Add(new Picture()
            {
                Id     = 2,
                Name   = "test2",
                Galery = new Galery()
                {
                    Id = 2, Name = "Galery2"
                }
            });

            var mockRepository = new Mock <IPictureRepository>();

            mockRepository.Setup(x => x.GetAll()).Returns(lista.AsQueryable());
            var controller = new PicturesController(mockRepository.Object);

            IQueryable <PictureDTO> result = controller.GetAll();

            Assert.IsNotNull(result);
            Assert.AreEqual(lista.Count, result.ToList().Count);

            Assert.AreEqual(lista.ElementAt(0).Id, result.ToList().ElementAt(0).Id);
            Assert.AreEqual(lista.ElementAt(0).Name, result.ToList().ElementAt(0).Name);
            Assert.AreEqual(lista.ElementAt(0).Galery.Name, result.ToList().ElementAt(0).GaleryName);

            Assert.AreEqual(lista.ElementAt(1).Id, result.ToList().ElementAt(1).Id);
            Assert.AreEqual(lista.ElementAt(1).Name, result.ToList().ElementAt(1).Name);
            Assert.AreEqual(lista.ElementAt(1).Galery.Name, result.ToList().ElementAt(1).GaleryName);
        }