8.1.3.4 Highlighting the Current Category; UNIT TEST: REPORTING THE SELECTED CATEGORY

chap08
Jason Zhu 2021-09-08 23:24:09 +10:00
parent 32fa22777d
commit 6cc688fc9d
1 changed files with 25 additions and 0 deletions

View File

@ -149,5 +149,30 @@ namespace SportsStore.UnitTests
Assert.AreEqual(results[1], "Oranges");
Assert.AreEqual(results[2], "Plums");
}
[TestMethod]
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 categoryToSelected = "Apples";
// Action
string result = target.Menu(categoryToSelected).ViewBag.SelectedCategory;
// Assert
Assert.AreEqual(categoryToSelected, result);
}
}
}