Inheritance: BaseModel
コード例 #1
0
        public UnitOfWorkTests()
        {
            context = new TestingContext();
            model = ObjectFactory.CreateRole();
            unitOfWork = new UnitOfWork(context);

            context.DropData();
        }
コード例 #2
0
        public UnitOfWorkTests()
        {
            context = new TestingContext();
            model = ObjectFactory.CreateRole();
            logger = Substitute.For<IAuditLogger>();
            unitOfWork = new UnitOfWork(context, logger);

            context.DropData();
        }
コード例 #3
0
        public RoleValidatorTests()
        {
            context = new TestingContext();
            validator = new RoleValidator(new UnitOfWork(context));

            context.DropData();
            role = ObjectFactory.CreateRole();
            context.Set<Role>().Add(role);
            context.SaveChanges();
        }
コード例 #4
0
        public LoggableEntityTests()
        {
            using (context = new TestingContext())
            {
                context.DropData();
                SetUpData();
            }

            context = new TestingContext();
            model = context.Set<Role>().Single();
            entry = context.Entry<BaseModel>(model);
        }
コード例 #5
0
        private void SetUpData()
        {
            role = ObjectFactory.CreateRole();
            foreach (String controller in new[] { "Roles", "Profile" })
                foreach (String action in new[] { "Edit", "Delete" })
                {
                    RolePermission rolePermission = ObjectFactory.CreateRolePermission(role.Permissions.Count + 1);
                    rolePermission.Permission.Area = controller == "Roles" ? "Administration" : null;
                    rolePermission.Permission.Controller = controller;
                    rolePermission.Permission.Action = action;
                    rolePermission.RoleId = role.Id;
                    rolePermission.Role = null;

                    role.Permissions.Add(rolePermission);
                }

            context.Add(role);
            context.SaveChanges();
            context.DropState();
        }
コード例 #6
0
        private void RemoveFromAccounts(Role role)
        {
            foreach (Account account in UnitOfWork.Select<Account>().Where(account => account.RoleId == role.Id))
            {
                account.RoleId = null;

                UnitOfWork.Update(account);
            }
        }
コード例 #7
0
        private void DeletePermissions(Role role)
        {
            IQueryable<RolePermission> permissions = UnitOfWork
                .Select<RolePermission>()
                .Where(rolePermission => rolePermission.RoleId == role.Id);

            foreach (RolePermission permission in permissions)
                UnitOfWork.Delete(permission);
        }
コード例 #8
0
 private void Delete(Role role)
 {
     UnitOfWork.Delete(role);
 }
コード例 #9
0
        private void EditPermissions(Role role, RoleView view)
        {
            List<Int32> permissions = view.Permissions.SelectedIds.ToList();
            RolePermission[] rolePermissions = UnitOfWork.Select<RolePermission>()
                .Where(rolePermission => rolePermission.RoleId == role.Id).ToArray();

            foreach (RolePermission rolePermission in rolePermissions)
                if (!permissions.Remove(rolePermission.PermissionId))
                    UnitOfWork.Delete(rolePermission);

            foreach (Int32 permissionId in permissions)
                UnitOfWork.Insert(new RolePermission
                {
                    RoleId = role.Id,
                    PermissionId = permissionId
                });
        }
コード例 #10
0
        private void Edit(Role role, RoleView view)
        {
            role.Title = view.Title;

            UnitOfWork.Update(role);
        }
コード例 #11
0
        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;
        }
コード例 #12
0
        public void Edit_Role()
        {
            role = context.Set<Role>().AsNoTracking().Single();
            RoleView view = Mapper.Map<RoleView>(role);
            view.Title = role.Title += "Test";

            service.Edit(view);

            Role actual = context.Set<Role>().AsNoTracking().Single();
            RoleView expected = view;

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Title, actual.Title);
            Assert.Equal(expected.Id, actual.Id);
        }
コード例 #13
0
        private void EditRolePermissions(Role role, RoleView view)
        {
            List<Int32> selectedPermissions = view.Permissions.SelectedIds.ToList();

            foreach (RolePermission rolePermission in role.Permissions.ToArray())
                if (!selectedPermissions.Remove(rolePermission.PermissionId))
                    UnitOfWork.Delete(rolePermission);

            foreach (Int32 permissionId in selectedPermissions)
                UnitOfWork.Insert(new RolePermission { RoleId = role.Id, PermissionId = permissionId });
        }
コード例 #14
0
        private void SetUpData()
        {
            Account account = ObjectFactory.CreateAccount();
            role = ObjectFactory.CreateRole();
            account.RoleId = role.Id;

            context.Set<Account>().Add(account);

            role.RolePrivileges = new List<RolePrivilege>();

            Int32 privilegeNumber = 1;
            IEnumerable<String> controllers = new[] { "Accounts", "Roles" };
            IEnumerable<String> actions = new[] { "Index", "Create", "Details", "Edit", "Delete" };

            foreach (String controller in controllers)
                foreach (String action in actions)
                {
                    RolePrivilege rolePrivilege = ObjectFactory.CreateRolePrivilege(privilegeNumber++);
                    rolePrivilege.Privilege = new Privilege { Area = "Administration", Controller = controller, Action = action };
                    rolePrivilege.Privilege.Id = rolePrivilege.Id;
                    rolePrivilege.PrivilegeId = rolePrivilege.Id;
                    rolePrivilege.RoleId = role.Id;
                    rolePrivilege.Role = role;

                    role.RolePrivileges.Add(rolePrivilege);
                }

            context.Set<Role>().Add(role);
            context.SaveChanges();
        }