Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4000


Ignore:
Timestamp:
07/06/10 13:48:48 (14 years ago)
Author:
mholper
Message:

implemented last Method HeuristicLabRoleProvider.DeleteRole and UnitTest (#1046)
--> HeuristicLabRoleProvider finished now, all HeuristicLabRoleProviderTest passed (#1077)

Location:
branches/HeuristicLab.Services.Authentication Prototype
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabRoleProvider.cs

    r3978 r4000  
    5454    }
    5555
     56    //
     57    // RoleProvider.DeleteRole
     58    //
    5659    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;
    5881    }
    5982
     
    107130        Persistence.HeuristicLabRole role = context.HeuristicLabRole.Single(r => r.RoleName == roleName);
    108131        foreach (Persistence.HeuristicLabUserRole roleUser in role.HeuristicLabUserRoles) {
    109           if(!userList.Contains(roleUser.HeuristicLabUser.UserName))
     132          if (!userList.Contains(roleUser.HeuristicLabUser.UserName))
    110133            userList.Add(roleUser.HeuristicLabUser.UserName);
    111134        }
     
    153176    }
    154177  }
    155 }
     178}//HeuristicLabRoleProvider
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs

    r3978 r4000  
    9494      //and add all these users to groups admin and users
    9595      AddUsersToRolesTest();
    96       HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); 
     96      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider();
    9797      string[] users = new string[2];
    9898      string[] roles = new string[1];
     
    278278    [TestMethod()]
    279279    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]));
    288307    }
    289308
     
    351370      try {
    352371        Persistence.HeuristicLabRole role = new Persistence.HeuristicLabRole();
    353         role.RoleName ="role1";
     372        role.RoleName = "role1";
    354373        Persistence.HeuristicLabRole role1 = new Persistence.HeuristicLabRole();
    355         role1.RoleName ="role1";
     374        role1.RoleName = "role1";
    356375        db.HeuristicLabRole.InsertOnSubmit(role);
    357376        db.HeuristicLabRole.InsertOnSubmit(role1);
     
    364383    }
    365384  }
    366 
    367  
    368 
    369 
    370 
    371 }
     385} //HeuristicLabRoleProviderTest
Note: See TracChangeset for help on using the changeset viewer.