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