Changeset 4000 for branches/HeuristicLab.Services.Authentication Prototype
- Timestamp:
- 07/06/10 13:48:48 (14 years ago)
- Location:
- branches/HeuristicLab.Services.Authentication Prototype
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabRoleProvider.cs
r3978 r4000 54 54 } 55 55 56 // 57 // RoleProvider.DeleteRole 58 // 56 59 public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { 57 throw new NotImplementedException(); 60 String[] roleArray = new String[1]; 61 roleArray[0] = roleName; 62 Persistence.DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext(); 63 64 if (!RoleExists(roleName)) { 65 return false; 66 //throw new Exception("Role does not exist."); 67 } 68 69 if (throwOnPopulatedRole && GetUsersInRole(roleName).Length > 0) { 70 return false; 71 //throw new ProviderException("Cannot delete a populated role."); 72 } 73 74 RemoveUsersFromRoles(GetUsersInRole(roleName), roleArray); 75 76 Persistence.HeuristicLabRole role = db.HeuristicLabRole.Single(r => r.RoleName == roleName); 77 db.HeuristicLabRole.DeleteOnSubmit(role); 78 db.Dispose(); 79 80 return true; 58 81 } 59 82 … … 107 130 Persistence.HeuristicLabRole role = context.HeuristicLabRole.Single(r => r.RoleName == roleName); 108 131 foreach (Persistence.HeuristicLabUserRole roleUser in role.HeuristicLabUserRoles) { 109 if (!userList.Contains(roleUser.HeuristicLabUser.UserName))132 if (!userList.Contains(roleUser.HeuristicLabUser.UserName)) 110 133 userList.Add(roleUser.HeuristicLabUser.UserName); 111 134 } … … 153 176 } 154 177 } 155 } 178 }//HeuristicLabRoleProvider -
branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs
r3978 r4000 94 94 //and add all these users to groups admin and users 95 95 AddUsersToRolesTest(); 96 HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); 96 HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); 97 97 string[] users = new string[2]; 98 98 string[] roles = new string[1]; … … 278 278 [TestMethod()] 279 279 public void DeleteRoleTest() { 280 HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value 281 string roleName = string.Empty; // TODO: Initialize to an appropriate value 282 bool throwOnPopulatedRole = false; // TODO: Initialize to an appropriate value 283 bool expected = false; // TODO: Initialize to an appropriate value 284 bool actual; 285 actual = target.DeleteRole(roleName, throwOnPopulatedRole); 286 Assert.AreEqual(expected, actual); 287 Assert.Inconclusive("Verify the correctness of this test method."); 280 281 //creates users dkhan,hmayer,bfarka (with AddUsersToRolesTest()) 282 //and add all these users to groups admin and users 283 AddUsersToRolesTest(); 284 HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); 285 string[] users = new string[2]; 286 string[] roles = new string[1]; 287 288 //remove hmayer from role admin 289 users[0] = "hmayr"; 290 roles[0] = "admin"; 291 292 //before removing, check if all three users exits correctly in admin group 293 Assert.IsTrue((target.GetRolesForUser("hmayr").ToList()).Contains(roles[0])); 294 Assert.IsTrue((target.GetRolesForUser("dkhan").ToList()).Contains(roles[0])); 295 Assert.IsTrue((target.GetRolesForUser("bfarka").ToList()).Contains(roles[0])); 296 297 //try to delete Role admin (with user hmayr from admin group exists) 298 Assert.IsFalse(target.DeleteRole(roles[0], true)); 299 300 Assert.IsTrue(target.IsUserInRole(users[0], roles[0])); 301 302 //final populateRole if false 303 //try to delete Role admin (with user hmayr from admin group exists) 304 Assert.IsTrue(target.DeleteRole(roles[0], false)); 305 Assert.IsFalse(target.IsUserInRole(users[0], roles[0])); 306 Assert.IsFalse((target.GetRolesForUser("hmayr").ToList()).Contains(roles[0])); 288 307 } 289 308 … … 351 370 try { 352 371 Persistence.HeuristicLabRole role = new Persistence.HeuristicLabRole(); 353 role.RoleName = "role1";372 role.RoleName = "role1"; 354 373 Persistence.HeuristicLabRole role1 = new Persistence.HeuristicLabRole(); 355 role1.RoleName = "role1";374 role1.RoleName = "role1"; 356 375 db.HeuristicLabRole.InsertOnSubmit(role); 357 376 db.HeuristicLabRole.InsertOnSubmit(role1); … … 364 383 } 365 384 } 366 367 368 369 370 371 } 385 } //HeuristicLabRoleProviderTest
Note: See TracChangeset
for help on using the changeset viewer.