public void Can_Create_Categories()
        {
            //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", Category = "Apples"},
                new Game {GameID = 2, Name = "P2", Category = "Apples"},
                new Game {GameID = 3, Name = "P3", Category = "Plums"},
                new Game {GameID = 4, Name = "P4", Category = "Oranges"},
            }.AsQueryable());

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

            //Act - Get the set of categories
            string[] results = ((IEnumerable<string>)target.Menu().Model).ToArray();

            //Assert
            Assert.AreEqual(results.Length, 3);
            Assert.AreEqual(results[0], "Apples");
            Assert.AreEqual(results[1], "Oranges");
            Assert.AreEqual(results[2], "Plums");
        }
Exemple #2
0
 public void Indicates_Selected_Category()
 {
     // 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", Category = "Apples"},
     new Product {ProductID = 4, Name = "P2", Category = "Oranges"},
     });
     // Arrange - create the controller
     NavController target = new NavController(mock.Object);
     // Arrange - define the category to selected
     string categoryToSelect = "Apples";
     // Action
     string result = target.Menu(categoryToSelect).ViewBag.SelectedCategory;
     // Assert
     Assert.AreEqual(categoryToSelect, result);
 }
        public void Indicates_Selected_Category()
        {
            //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", Category = "Apples"},
                new Game {GameID = 4, Name = "P2", Category = "Oranges"},
            }.AsQueryable());

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

            // Arrange - Define the category to select
            string categoryToSelect = "Apples";

            // Action
            string result = target.Menu(categoryToSelect).ViewBag.SelectedCategory;

            //Assert
            Assert.AreEqual(categoryToSelect, result);
        }