Exemple #1
0
        public void Ad_Can_Delete_Valid_Products()
        {
            // Arrange - create a advertisement
            Advertisement advertisement = new Advertisement {
                CompanyName = "Test"
            };

            // 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"
                }
            }.AsQueryable <Advertisement>());

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

            // Act - delete the product
            target.AdDelete(advertisement.AdvertisementID);

            // Assert - ensure that the repository delete method was
            // called with the correct Product
            mock.Verify(m => m.DeleteAdvertisement(advertisement.AdvertisementID));
        }