コード例 #1
0
ファイル: MenuTests.cs プロジェクト: whesius/allors
        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);
            }
        }
コード例 #2
0
ファイル: MenuTests.cs プロジェクト: whesius/allors
        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);
        }
コード例 #3
0
ファイル: MenuTests.cs プロジェクト: whesius/allors
        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);
        }