From 6cc688fc9def0dd5e0be67650143c4134305356f Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Wed, 8 Sep 2021 23:24:09 +1000 Subject: [PATCH] 8.1.3.4 Highlighting the Current Category; UNIT TEST: REPORTING THE SELECTED CATEGORY --- .../SportsStore.UnitTests/UnitTest1.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/SportsStore/SportsStore.UnitTests/UnitTest1.cs b/SportsStore/SportsStore.UnitTests/UnitTest1.cs index 243d7e7..cc35209 100644 --- a/SportsStore/SportsStore.UnitTests/UnitTest1.cs +++ b/SportsStore/SportsStore.UnitTests/UnitTest1.cs @@ -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 mock = new Mock(); + 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); + } } }