public LoggableEntityTests() { using (context = new TestingContext()) { context.DropData(); SetUpData(); } context = new TestingContext(); model = context.Set<Role>().Single(); entry = context.Entry<BaseModel>(model); }
private JsTree CreatePrivilegesTree(Role role) { JsTreeNode rootNode = new JsTreeNode(Titles.All); JsTree expectedTree = new JsTree(); expectedTree.Nodes.Add(rootNode); expectedTree.SelectedIds = role.RolePrivileges.Select(rolePrivilege => rolePrivilege.PrivilegeId).ToList(); IEnumerable<Privilege> allPrivileges = role .RolePrivileges .Select(rolePriv => rolePriv.Privilege) .Select(privilege => new Privilege { Id = privilege.Id, Area = ResourceProvider.GetPrivilegeAreaTitle(privilege.Area), Controller = ResourceProvider.GetPrivilegeControllerTitle(privilege.Area, privilege.Controller), Action = ResourceProvider.GetPrivilegeActionTitle(privilege.Area, privilege.Controller, privilege.Action) }); foreach (IGrouping<String, Privilege> areaPrivilege in allPrivileges.GroupBy(privilege => privilege.Area).OrderBy(privilege => privilege.Key ?? privilege.FirstOrDefault().Controller)) { JsTreeNode areaNode = new JsTreeNode(areaPrivilege.Key); foreach (IGrouping<String, Privilege> controllerPrivilege in areaPrivilege.GroupBy(privilege => privilege.Controller).OrderBy(privilege => privilege.Key)) { JsTreeNode controllerNode = new JsTreeNode(controllerPrivilege.Key); foreach (IGrouping<String, Privilege> actionPrivilege in controllerPrivilege.GroupBy(privilege => privilege.Action).OrderBy(privilege => privilege.Key)) controllerNode.Nodes.Add(new JsTreeNode(actionPrivilege.First().Id, actionPrivilege.Key)); if (areaNode.Title == null) rootNode.Nodes.Add(controllerNode); else areaNode.Nodes.Add(controllerNode); } if (areaNode.Title != null) rootNode.Nodes.Add(areaNode); } return expectedTree; }