示例#1
0
        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);
        }
示例#2
0
        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);
        }