Example #1
0
        public void Can_Delete_Valid_Products()
        {
            Product product = new Product { ProductID = 2, Name = "Test" };

            Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]{
                new Product{ProductID = 1, Name = "P1"},
                new Product{ProductID = 3, Name = "P3"}
            });

            AdminController target = new AdminController(mock.Object);

            target.Delete(product.ProductID);

            mock.Verify(m => m.DeleteProduct(product.ProductID));
        }
Example #2
0
 public void Can_Delete_Valid_Games()
 {
     Game game = new Game { GameId = 2, Name = "Game2" };
     // Arrange
     Mock<IGameRepository> mock = new Mock<IGameRepository>();
     mock.Setup(m => m.Games).Returns(new List<Game>
     {
         new Game { GameId = 1, Name = "Game1"},
         new Game { GameId = 2, Name = "Game2"},
         new Game { GameId = 3, Name = "Game3"},
         new Game { GameId = 4, Name = "Game4"},
         new Game { GameId = 5, Name = "Game5"}
     });
     AdminController ctrl = new AdminController(mock.Object);
     //Act
     ctrl.Delete(game.GameId);
     mock.Verify(m => m.DeleteGame(game.GameId));
 }
Example #3
0
        public void Can_Delete_Valid_Products()
        {
            // Arrange - create a Product
            Product prod = new Product { ProductID = 2, Name = "Test" };
            // Arrange - create the mock repository
            Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                    new Product {ProductID = 1, Name = "P1"},prod,
                    new Product {ProductID = 3, Name = "P3"},
                });
            // Arrange - create the controller
            AdminController target = new AdminController(mock.Object);

            // Act - delete the product
            target.Delete(prod.ProductID);

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