public void TestUserRole() { //权限项1 string permName1 = Guid.NewGuid().ToString(); long permId1 = permissionService.AddPermission(permName1, permName1); //权限项2 string permName2 = Guid.NewGuid().ToString(); long permId2 = permissionService.AddPermission(permName2, permName2); //用户 string phoneNum = Guid.NewGuid().ToString().Substring(0, 11); adminUserId = adminUserService.AddAdminUser("wangwu", phoneNum, "123", "*****@*****.**", null); //角色1,2 string roleName1 = Guid.NewGuid().ToString(); string roleName2 = Guid.NewGuid().ToString(); long roleId1 = roleService.AddNew(roleName1); long roleId2 = roleService.AddNew(roleName2); //给角色1添加权限项1 permissionService.AddPermIds(roleId1, new long[] { permId1 }); //给角色2添加权限项2 permissionService.AddPermIds(roleId2, new long[] { permId2 }); //给用户adminuser添加角色1 roleService.AddRoleIds(adminUserId, new long[] { roleId1 }); Assert.IsTrue(adminUserService.HasPermission(adminUserId, permName1)); Assert.IsFalse(adminUserService.HasPermission(adminUserId, permName2)); roleService.UpdateRoleIds(adminUserId, new long[] { roleId2 }); Assert.IsFalse(adminUserService.HasPermission(adminUserId, permName1)); Assert.IsTrue(adminUserService.HasPermission(adminUserId, permName2)); CollectionAssert.AreEqual(roleService.GetByAdminUserId(adminUserId).Select(a => a.Id).ToArray(), new long[] { roleId2 }); }
public void TestHasPerm() { try { PermissionService permService = new PermissionService(); string permName1 = Guid.NewGuid().ToString(); long permId1 = permService.AddPermission(permName1, permName1); string permName2 = Guid.NewGuid().ToString(); long permId2 = permService.AddPermission(permName2, permName2); RoleService roleService = new RoleService(); string roleName = Guid.NewGuid().ToString(); long roleId = roleService.AddNew(roleName); string userPhone = "136138"; long userId = new AdminUserService().AddAdminUser("aaa", userPhone, "123", "*****@*****.**", null); roleService.AddRoleIds(userId, new long[] { roleId }); permService.AddPermIds(roleId, new long[] { permId1 }); Assert.IsTrue(service.HasPermission(userId, permName1)); Assert.IsFalse(service.HasPermission(userId, permName2)); service.MarkDeleted(userId); } catch (DbEntityValidationException ex) { foreach (var item in ex.EntityValidationErrors.SelectMany(err => err.ValidationErrors)) { Console.WriteLine(item.ErrorMessage); } } }
public void TestUserRole() { string permName1 = Guid.NewGuid().ToString(); long permId1 = permService.AddPermission(permName1, permName1); string permName2 = Guid.NewGuid().ToString(); long permId2 = permService.AddPermission(permName2, permName2); string roleName1 = Guid.NewGuid().ToString(); long roleId1 = roleService.AddNew(roleName1); string roleName2 = Guid.NewGuid().ToString(); long roleId2 = roleService.AddNew(roleName2); string userPhone = "178158"; userId = userService.AddAdminUser("aaa", userPhone, "123", "*****@*****.**", null); roleService.AddRoleIds(userId, new long[] { roleId1 }); permService.AddPermIds(roleId1, new long[] { permId1 }); Assert.IsTrue(userService.HasPermission(userId, permName1)); //Assert.IsFalse(userService.HasPermission(userId, permName2)); roleService.UpdateRoleIds(userId, new long[] { roleId2 }); Assert.IsFalse(userService.HasPermission(userId, permName1)); CollectionAssert.AreEqual(roleService.GetByAdminUserId(userId).Select(r => r.Id).ToArray(), new long[] { roleId2 }); }
public void HasPermission() { PermissionService permissionService = new PermissionService(); //权限项1 string permName1 = Guid.NewGuid().ToString(); long permId1 = permissionService.AddPermission(permName1, permName1); //权限项2 string permName2 = Guid.NewGuid().ToString(); long permId2 = permissionService.AddPermission(permName2, permName2); //用户 string phoneNum = Guid.NewGuid().ToString().Substring(0, 11); long adminUserId = adminUserService.AddAdminUser("李四", phoneNum, "123", "*****@*****.**", null); //角色1,2 RoleService roleService = new RoleService(); string roleName1 = Guid.NewGuid().ToString(); string roleName2 = Guid.NewGuid().ToString(); long roleId1 = roleService.AddNew(roleName1); long roleId2 = roleService.AddNew(roleName2); //给角色1添加权限项1 permissionService.AddPermIds(roleId1, new long[] { permId1 }); //给用户adminuser添加角色1 roleService.AddRoleIds(adminUserId, new long[] { roleId1 }); Assert.IsTrue(adminUserService.HasPermission(adminUserId, permName1)); Assert.IsFalse(adminUserService.HasPermission(adminUserId, permName2)); }
public void PermissionTest() { PermissionService permService = new PermissionService(); AdminUserService userService = new AdminUserService(); RoleService roleService = new RoleService(); string roleName1 = Guid.NewGuid().ToString(); string permName1 = Guid.NewGuid().ToString(); long roleId1 = roleService.AddNew(roleName1); long permId = permService.AddPermission(permName1, permName1); string userPhone = "139138"; long userId = userService.AddAdminUser("Aaa", userPhone, "mima", "email", null); roleService.AddRoleIds(userId, new long[] { roleId1 }); permService.AddPermIds(roleId1, new long[] { permId }); Assert.IsTrue(userService.HasPermission(userId, permName1)); Assert.IsFalse(userService.HasPermission(userId, "1")); userService.MarkDeleted(userId); }
public void TestAddPermIds() { permService.AddPermIds(1, new long[] { 1, 2 }); }