- Timestamp:
- 06/26/10 12:51:55 (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
r3962 r3963 100 100 } 101 101 102 103 /// <summary> 104 /// true if given username has exists in given Role, else false 105 /// </summary> 106 /// <param name="username"></param> 107 /// <param name="roleName"></param> 108 /// <returns>bool</returns> 102 109 public override bool IsUserInRole(string username, string roleName) { 103 throw new NotImplementedException(); 110 bool returnValue = false; 111 DataClassesDataContext context = DatabaseUtil.createDataClassesDataContext(); 112 if (username != null && roleName != null) 113 { 114 returnValue = (context.HeuristicLabUserRole.Count(ur => ur.HeuristicLabRole.RoleName == roleName && ur.HeuristicLabUser.UserName == username) > 0); 115 } 116 return returnValue; 104 117 } 105 118 -
branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs
r3960 r3963 12 12 private TestContext testContextInstance; 13 13 private const string TEST_ROLE_NAME = "testRole"; 14 private const string TEST_USER_NAME = "testUser"; 14 15 /// <summary> 15 16 ///Gets or sets the test context which provides … … 96 97 97 98 /// <summary> 98 /// A test for IsUserInRole99 /// test if user is in Role (positive and negative Assertion) 99 100 ///</summary> 100 101 [TestMethod()] 101 102 public void IsUserInRoleTest() { 102 HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value 103 string username = string.Empty; // TODO: Initialize to an appropriate value 104 string roleName = string.Empty; // TODO: Initialize to an appropriate value 105 bool expected = false; // TODO: Initialize to an appropriate value 106 bool actual; 107 actual = target.IsUserInRole(username, roleName); 108 Assert.AreEqual(expected, actual); 109 Assert.Inconclusive("Verify the correctness of this test method."); 103 HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value 104 Dictionary<string, Persistence.HeuristicLabUser> users = new Dictionary<string, Persistence.HeuristicLabUser>(); 105 List<string> roles = new List<string>(); 106 users.Add("mholper", new Persistence.HeuristicLabUser("mholper", "foo", "password", "comment")); 107 108 roles.Add("admin"); 109 roles.Add("users"); 110 foreach (string role in roles) 111 { 112 target.CreateRole(role); 113 } 114 foreach (Persistence.HeuristicLabUser user in users.Values) 115 { 116 db.HeuristicLabUsers.InsertOnSubmit(user); 117 } 118 db.SubmitChanges(); 119 string[] rolesToTest = new string[1]; 120 rolesToTest[0] = "admin"; 121 target.AddUsersToRoles(users.Keys.ToArray(), rolesToTest); // roles.ToArray()); 122 Assert.IsTrue(target.IsUserInRole("mholper", "admin")); 123 Assert.IsFalse(target.IsUserInRole("mholper", "user")); 110 124 } 111 125
Note: See TracChangeset
for help on using the changeset viewer.