Пример #1
0
        public void Ad_Index_Contains_All_Products()
        {
            // Arrange - create the mock repository
            Mock <IAdvertisementRepository> mock = new Mock <IAdvertisementRepository>();

            mock.Setup(m => m.Advertisements).Returns((new Advertisement[]
            {
                new Advertisement {
                    AdvertisementID = 1, CompanyName = "A1"
                },
                new Advertisement {
                    AdvertisementID = 2, CompanyName = "A2"
                },
                new Advertisement {
                    AdvertisementID = 3, CompanyName = "A3"
                }
            }).AsQueryable <Advertisement>());

            // Arrange - create a controller
            AdminController target = new AdminController(null, mock.Object);

            // Action
            Advertisement[] result = GetViewModel <IEnumerable <Advertisement> >(target.AdIndex())?.ToArray();

            // Assert
            Assert.Equal(3, result.Count());
            Assert.Equal("A1", result[0].CompanyName);
            Assert.Equal("A2", result[1].CompanyName);
            Assert.Equal("A3", result[2].CompanyName);
        }