Exemple #1
0
        public void Save_Ok()
        {
            var poco = new BootstrapMenu()
            {
                Name        = "UnitTest",
                Application = "0",
                Category    = "0",
                Icon        = "fa fa-fa",
                IsResource  = 0,
                Target      = "_blank",
                Order       = 10,
                Url         = "#",
                ParentId    = "0",
                ParentName  = "Test"
            };

            // insert
            Assert.True(MenuHelper.Save(poco));

            // update
            poco = MenuHelper.RetrieveAllMenus("Admin").Where(m => m.Id == poco.Id).FirstOrDefault();
            Assert.True(MenuHelper.Save(poco));

            // clean
            MenuHelper.Delete(new string[] { poco.Id });
        }
Exemple #2
0
        public void MenuDelete_Ok()
        {
            var menu = MenuHelper.RetrieveMenus("Admin").FirstOrDefault(m => m.Category == "0");

            Assert.True(MenuHelper.Delete(new string[] { menu.Id }));
            var menu2 = MenuHelper.RetrieveMenus("Admin").FirstOrDefault(m => m.Id == menu.Id);

            Assert.NotNull(menu2);

            // 保护模式下,正常選單可以刪除
            var poco = new BootstrapMenu()
            {
                Name        = "UnitTest",
                Application = "3",
                Category    = "1",
                Icon        = "fa fa-fa",
                IsResource  = 0,
                Target      = "_blank",
                Order       = 10,
                Url         = "#",
                ParentId    = "0",
                ParentName  = "Test",
            };

            // insert
            Assert.True(MenuHelper.Save(poco));

            // update
            poco = MenuHelper.RetrieveAllMenus("Admin").Where(m => m.Id == poco.Id).FirstOrDefault();
            Assert.True(MenuHelper.Save(poco));

            // clean
            MenuHelper.Delete(new string[] { poco.Id });
        }
Exemple #3
0
        public void RetrieveRolesByMenuId_Ok()
        {
            var roleId = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;

            MenuHelper.SaveMenusByRoleId(roleId, MenuHelper.RetrieveAllMenus("Admin").Select(m => m.Id));
            var rs = RoleHelper.RetrievesByMenuId(MenuHelper.RetrieveAllMenus("Admin").FirstOrDefault().Id).Where(r => r.Checked == "checked");

            Assert.NotEmpty(rs);
        }
Exemple #4
0
        public void SaveMenusByRoleId_Ok()
        {
            var roleId = RoleHelper.Retrieves().FirstOrDefault(r => r.RoleName == "Administrators").Id;

            Assert.True(MenuHelper.SaveMenusByRoleId(roleId, MenuHelper.RetrieveAllMenus("Admin").Select(m => m.Id)));
        }
Exemple #5
0
 public void RetrieveAllMenus_Ok()
 {
     Assert.NotEmpty(MenuHelper.RetrieveAllMenus("Admin"));
     Assert.Empty(MenuHelper.RetrieveAllMenus("_UnitTest"));
 }
Exemple #6
0
        /// <summary>
        /// 通过當前用户名與指定選單路徑獲取此選單下所有授權按鈕集合 (userName, url, auths) => bool
        /// </summary>
        /// <param name="userName">當前操作用户名</param>
        /// <param name="url">資源按鈕所属選單</param>
        /// <param name="auths">資源授權碼</param>
        /// <returns></returns>
        public virtual bool AuthorizateButtons(string userName, string url, string auths)
        {
            var menus = MenuHelper.RetrieveAllMenus(userName);

            return(DbHelper.AuthorizateButtons(menus, url, auths));
        }
Exemple #7
0
        public void SavaRolesByMenuId_Ok()
        {
            var menuId = MenuHelper.RetrieveAllMenus("Admin").FirstOrDefault().Id;

            Assert.True(RoleHelper.SavaByMenuId(menuId, RoleHelper.Retrieves().Select(r => r.Id)));
        }