public void ActiveRootMenu() { var menu = new Menu { new MenuItem().Action<HomeController>(c => c.Index()) .Add(new MenuItem().Action<HomeController>(c => c.Contact())), new MenuItem().Action<HomeController>(c => c.About()) }; var menuForView = new MenuForUser(menu, "Home", "Index", null); foreach (var menuItemForView in menuForView) { var isActive = menuItemForView.ControllerName.Equals("Home") && menuItemForView.ActionName.Equals("Index"); Assert.AreEqual(isActive, menuItemForView.IsActive); } }
public void AuthorizeOnClassWithoutUser() { var menu = new Menu { new MenuItem().Action<HomeController>(c => c.Contact()) .Add(new MenuItem().Action<HomeController>(c => c.Contact())), new MenuItem().Action<HomeController>(c => c.About()) }; var menuForView = new MenuForUser(menu, "Home", "Contact", null); var menuItemsForView = menuForView.ToArray(); Assert.AreEqual(1, menuItemsForView.Length); var menuItemForView = menuItemsForView[0]; Assert.AreEqual("Home", menuItemForView.ControllerName); Assert.AreEqual("About", menuItemForView.ActionName); }
public void AuthorizeOnClassWithUser() { var menu = new Menu { new MenuItem().Action<HomeController>(c => c.Index()) .Add(new MenuItem().Action<HomeController>(c => c.Contact())), new MenuItem().Action<HomeController>(c => c.About()) }; var identityMock = new Mock<IIdentity>(); identityMock.Setup(identity => identity.IsAuthenticated).Returns(true); var userMock = new Mock<IPrincipal>(); userMock.Setup(user => user.Identity).Returns(identityMock.Object); var menuForView = new MenuForUser(menu, "Home", "Contact", userMock.Object); var menuItemsForView = menuForView.ToArray(); Assert.AreEqual(2, menuItemsForView.Length); }