Changeset 3967 for branches/HeuristicLab.Services.Authentication Prototype
- Timestamp:
- 06/28/10 10:34:08 (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
r3964 r3967 101 101 102 102 public override string[] GetUsersInRole(string roleName) { 103 throw new NotImplementedException(); 103 List<string> userList = new List<string>(); 104 DataClassesDataContext context = DatabaseUtil.createDataClassesDataContext(); 105 if (roleName != null && context.HeuristicLabRole.Count(r => r.RoleName == roleName) > 0) { 106 107 Persistence.HeuristicLabRole role = context.HeuristicLabRole.Single(r => r.RoleName == roleName); 108 foreach (Persistence.HeuristicLabUserRole roleUser in role.HeuristicLabUserRoles) { 109 if(!userList.Contains(roleUser.HeuristicLabUser.UserName)) 110 userList.Add(roleUser.HeuristicLabUser.UserName); 111 } 112 } 113 context.Dispose(); 114 return userList.ToArray(); 104 115 } 105 116 … … 121 132 122 133 Persistence.DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext(); 123 bool returnValue = ( DatabaseUtil.createDataClassesDataContext().HeuristicLabRole.Count(r => r.RoleName == roleName) == 1);134 bool returnValue = (db.HeuristicLabRole.Count(r => r.RoleName == roleName) == 1); 124 135 db.Dispose(); 125 136 return returnValue; -
branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs
r3964 r3967 128 128 public void GetUsersInRoleTest() { 129 129 HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value 130 string roleName = string.Empty; // TODO: Initialize to an appropriate value 131 string[] expected = null; // TODO: Initialize to an appropriate value 132 string[] actual; 133 actual = target.GetUsersInRole(roleName); 134 Assert.AreEqual(expected, actual); 135 Assert.Inconclusive("Verify the correctness of this test method."); 130 string dummyRole = "dummyRole"; 131 Assert.IsTrue(target.GetUsersInRole(null).Length == 0); 132 Assert.IsTrue(target.GetUsersInRole(dummyRole).Length == 0); 133 Persistence.HeuristicLabUser user = new Persistence.HeuristicLabUser("dummyUser", "foo", "foo", "foo"); 134 Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("dummyUser2", "foo", "foo", "foo"); 135 db.HeuristicLabUsers.InsertOnSubmit(user); 136 db.HeuristicLabUsers.InsertOnSubmit(user2); 137 db.SubmitChanges(); 138 target.CreateRole("testRole1"); 139 target.CreateRole("testRole2"); 140 List<string> users = new List<string>(); 141 List<string> roles = new List<string>(); 142 roles.Add("testRole1"); 143 roles.Add("testRole2"); 144 users.Add("dummyUser"); 145 146 //--> dummyUser get Role testRole1+testRole2 147 target.AddUsersToRoles(users.ToArray(), roles.ToArray()); 148 string[] usersForRole = target.GetUsersInRole("testRole2"); 149 Assert.IsTrue(usersForRole.Length == 1); 150 Assert.IsTrue(usersForRole.Contains("dummyUser")); 151 152 //--> dummyUser2 get onl Role testRole1 153 roles.Remove("testRole2"); 154 users.Remove("dummyUser"); 155 users.Add("dummyUser2"); 156 target.AddUsersToRoles(users.ToArray(), roles.ToArray()); 157 158 usersForRole = target.GetUsersInRole("testRole1"); 159 Assert.IsTrue(usersForRole.Length == 2); 160 Assert.IsTrue(usersForRole.Contains("dummyUser")); 161 Assert.IsTrue(usersForRole.Contains("dummyUser2")); 162 136 163 } 137 164
Note: See TracChangeset
for help on using the changeset viewer.