public void Can_Edit_Game()
        {
            // Arrange - Create the mock repository
            Mock<IGameRepository> mock = new Mock<IGameRepository>();
            mock.Setup(m => m.Games).Returns(new Game[]
            {
                new Game {GameID = 1, Name = "P1"},
                new Game {GameID = 2, Name = "P2"},
                new Game {GameID = 3, Name = "P3"},
            }.AsQueryable());

            // Arrange - Create the controller
            AdminController target = new AdminController(mock.Object);

            // Act
            Game p1 = target.Edit(1).ViewData.Model as Game;
            Game p2 = target.Edit(2).ViewData.Model as Game;
            Game p3 = target.Edit(3).ViewData.Model as Game;

            // Assert
            Assert.AreEqual(1, p1.GameID);
            Assert.AreEqual(2, p2.GameID);
            Assert.AreEqual(3, p3.GameID);
        }
Exemple #2
0
 public void Cannot_Edit_Nonexistent_Product()
 {
     // Arrange - create the mock repository
     Mock<IProductRepository> mock = new Mock<IProductRepository>();
     mock.Setup(m => m.Products).Returns(new Product[] {
         new Product {ProductID = 1, Name = "P1"},
         new Product {ProductID = 2, Name = "P2"},
         new Product {ProductID = 3, Name = "P3"},
     });
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Act
     Product result = (Product)target.Edit(4).ViewData.Model;
     // Assert
     Assert.IsNull(result);
 }
Exemple #3
0
 public void Cannot_Save_Invalid_Changes()
 {
     // Arrange - create mock repository
     Mock<IProductRepository> mock = new Mock<IProductRepository>();
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Arrange - create a product
     Product product = new Product { Name = "Test" };
     // Arrange - add an error to the model state
     target.ModelState.AddModelError("error", "error");
     // Act - try to save the product
     ActionResult result = target.Edit(product);
     // Assert - check that the repository was not called
     mock.Verify(m => m.SaveProduct(It.IsAny<Product>()), Times.Never());
     // Assert - check the method result type
     Assert.IsInstanceOfType(result, typeof(ViewResult));
 }
        public void Cannot_Edit_Nonexistent_Game()
        {
            // Arrange - Create the mock repository
            Mock<IGameRepository> mock = new Mock<IGameRepository>();
            mock.Setup(m => m.Games).Returns(new Game[]
            {
                new Game {GameID = 1, Name = "P1"},
                new Game {GameID = 2, Name = "P2"},
                new Game {GameID = 3, Name = "P3"},
            }.AsQueryable());

            // Arrange - Create the controller
            AdminController target = new AdminController(mock.Object);

            // Act
            Game result = (Game)target.Edit(4).ViewData.Model;

            // Assert
            Assert.IsNull(result);
        }
        public void Cannot_Save_Invalid_Changes()
        {
            // Arrange - Create mock repository
            Mock<IGameRepository> mock = new Mock<IGameRepository>();

            // Arrange - Create the controller
            AdminController target = new AdminController(mock.Object);

            // Arrange - Create a game
            Game game = new Game { Name = "Test" };

            // Arrange - Add an error to the model state
            target.ModelState.AddModelError("error", "error");

            // Act - Try to save the game
            ActionResult result = target.Edit(game);

            // Assert - Check that the repository was not called
            mock.Verify(m => m.SaveGame(It.IsAny<Game>()), Times.Never());

            // Assert - Check the method result type
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
Exemple #6
0
 public void Can_Edit_Product()
 {
     // Arrange - create the mock repository
     Mock<IProductRepository> mock = new Mock<IProductRepository>();
     mock.Setup(m => m.Products).Returns(new Product[] {
         new Product {ProductID = 1, Name = "P1"},
         new Product {ProductID = 2, Name = "P2"},
         new Product {ProductID = 3, Name = "P3"},
     });
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Act
     Product p1 = target.Edit(1).ViewData.Model as Product;
     Product p2 = target.Edit(2).ViewData.Model as Product;
     Product p3 = target.Edit(3).ViewData.Model as Product;
     // Assert
     Assert.AreEqual(1, p1.ProductID);
     Assert.AreEqual(2, p2.ProductID);
     Assert.AreEqual(3, p3.ProductID);
 }
Exemple #7
0
 public void Can_Save_Valid_Changes()
 {
     // Arrange - create mock repository
     Mock<IProductRepository> mock = new Mock<IProductRepository>();
     // Arrange - create the controller
     AdminController target = new AdminController(mock.Object);
     // Arrange - create a product
     Product product = new Product { Name = "Test" };
     // Act - try to save the product
     ActionResult result = target.Edit(product);
     // Assert - check that the repository was called
     mock.Verify(m => m.SaveProduct(product));
     // Assert - check the method result type
     Assert.IsNotInstanceOfType(result, typeof(ViewResult));
 }
        public void Can_Save_Valid_Changes()
        {
            // Arrange - Create mock repository
            Mock<IGameRepository> mock = new Mock<IGameRepository>();

            // Arrange - Create the controller
            AdminController target = new AdminController(mock.Object);

            // Arrange - Create a game
            Game game = new Game { Name = "Test" };

            // Act - Try to save the game
            ActionResult result = target.Edit(game);

            // Assert - Check that the repository was called
            mock.Verify(m => m.SaveGame(game));

            // Assert - Check the method result type
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }