Beispiel #1
0
        public void Can_Create_Categories()
        {
            // Arrange
            var mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new[]
            {
                new Product {ProductID = 1, Name = "P1", Category = "C2"},
                new Product {ProductID = 2, Name = "P2", Category = "C1"},
                new Product {ProductID = 3, Name = "P3", Category = "C1"},
                new Product {ProductID = 4, Name = "P4", Category = "C1"},
                new Product {ProductID = 5, Name = "P5", Category = "C2"},
                new Product {ProductID = 6, Name = "P6", Category = "C2"}
            });

            //Arrange
            NavController target = new NavController(mock.Object);

            //Act
            string[] results = ((IEnumerable<string>)target.Menu().Model).ToArray();

            // Assert
            Assert.AreEqual(results.Length, 2);
            Assert.AreEqual(results[0], "C1");
            Assert.AreEqual(results[1], "C2");
        }
Beispiel #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);
 }