public void HighlightSelectedCategory(Message[] messages) { // Arrange string categoryToSelect = "Cat2"; // Arrange Mock <IMessageService> mock = new Mock <IMessageService>(); mock.Setup(srv => srv.GetAllMessages()).Returns(messages); MessageNavigationMenuViewComponent target = new MessageNavigationMenuViewComponent(mock.Object); target.ViewComponentContext = new ViewComponentContext { ViewContext = new ViewContext { RouteData = new RouteData() } }; target.RouteData.Values["category"] = categoryToSelect; // Action string result = (string)(target.Invoke() as ViewViewComponentResult).ViewData["SelectedCategory"]; // Assert Assert.Equal(categoryToSelect, result); }
public void GetAllCategories(Message[] messages) { // Arrange Mock <IMessageService> mock = new Mock <IMessageService>(); mock.Setup(srv => srv.GetAllMessages()).Returns(messages); MessageNavigationMenuViewComponent target = new MessageNavigationMenuViewComponent(mock.Object); // Acts string[] results = ((IEnumerable <string>)(target.Invoke() as ViewViewComponentResult).ViewData.Model).ToArray(); // Assert Assert.True(Enumerable.SequenceEqual(new string[] { "Cat1", "Cat2" }, results)); }