Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3978


Ignore:
Timestamp:
06/29/10 20:00:06 (14 years ago)
Author:
bfarka
Message:

fixed bug in RomveUsersFromRoles and fixed some tests (1046)

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

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/HeuristicLab.Services.Authentication Prototyp.sln

    r3956 r3978  
    1111  ProjectSection(SolutionItems) = preProject
    1212    HeuristicLab.Services.Authentication Prototyp.vsmdi = HeuristicLab.Services.Authentication Prototyp.vsmdi
     13    HeuristicLab.Services.Authentication Prototyp1.vsmdi = HeuristicLab.Services.Authentication Prototyp1.vsmdi
    1314    HeuristicLab.Services.Authentication Prototyp2.vsmdi = HeuristicLab.Services.Authentication Prototyp2.vsmdi
    1415    LocalTestRun.testrunconfig = LocalTestRun.testrunconfig
     
    1718Global
    1819  GlobalSection(TestCaseManagementSettings) = postSolution
    19     CategoryFile = HeuristicLab.Services.Authentication Prototyp2.vsmdi
     20    CategoryFile = HeuristicLab.Services.Authentication Prototyp1.vsmdi
    2021  EndGlobalSection
    2122  GlobalSection(SolutionConfigurationPlatforms) = preSolution
  • branches/HeuristicLab.Services.Authentication Prototype/Persistence/HeuristicLabUserRole.cs

    r3955 r3978  
    77  partial class HeuristicLabUserRole {
    88    public override bool Equals(object obj) {
    9       return ((HeuristicLabUserRole)obj).HeuristicLabRole.Equals(this.HeuristicLabRole) && ((HeuristicLabUserRole)obj).HeuristicLabUser.Equals(this.HeuristicLabUser);
     9        if(this.ID == null ^ ((HeuristicLabUserRole)obj).ID == null )
     10        {
     11          return false;
     12        }
     13        else if (this.ID == null && ((HeuristicLabUserRole)obj).ID == null)
     14        {
     15         return base.Equals(obj);
     16        }
     17        return ((HeuristicLabUserRole)obj).ID.Equals(this.ID);
    1018    }
    1119  }
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabRoleProvider.cs

    r3967 r3978  
    126126
    127127    public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) {
    128       throw new NotImplementedException();
     128
     129      DataClassesDataContext context = DatabaseUtil.createDataClassesDataContext();
     130
     131      foreach (string userName in usernames) {
     132        if (userName != null && context.HeuristicLabUsers.Count(u => u.UserName == userName) > 0) {
     133          Persistence.HeuristicLabUser user = context.HeuristicLabUsers.Single(u => u.UserName == userName);
     134          foreach (Persistence.HeuristicLabUserRole userRole in user.HeuristicLabUserRoles) {
     135            if (roleNames.Contains(userRole.HeuristicLabRole.RoleName)) {
     136              context.HeuristicLabUserRole.DeleteOnSubmit(userRole);
     137              //deleteList.Add(userRole);
     138            }//if
     139          }//foreach
     140        }//if
     141      }//foreach
     142      context.SubmitChanges();
     143      context.Dispose();
    129144    }
    130145
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs

    r3974 r3978  
    9090    [TestMethod()]
    9191    public void RemoveUsersFromRolesTest() {
    92       HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
    93       string[] usernames = null; // TODO: Initialize to an appropriate value
    94       string[] roleNames = null; // TODO: Initialize to an appropriate value
    95       target.RemoveUsersFromRoles(usernames, roleNames);
    96       Assert.Inconclusive("A method that does not return a value cannot be verified.");
     92
     93      //creates users dkhan,hmayer,bfarka (with AddUsersToRolesTest())
     94      //and add all these users to groups admin and users
     95      AddUsersToRolesTest();
     96      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider();
     97      string[] users = new string[2];
     98      string[] roles = new string[1];
     99
     100      //remove hmayer from role admin
     101      users[0] = "hmayr";
     102      roles[0] = "admin";
     103
     104
     105      //before removing, check if all three users exits correctly in admin group
     106      Assert.IsTrue((target.GetRolesForUser("hmayr").ToList()).Contains(roles[0]));
     107      Assert.IsTrue((target.GetRolesForUser("dkhan").ToList()).Contains(roles[0]));
     108      Assert.IsTrue((target.GetRolesForUser("bfarka").ToList()).Contains(roles[0]));
     109
     110      //remmove hmayr from  admin group
     111      target.RemoveUsersFromRoles(users, roles);
     112
     113      //final check
     114      Assert.IsTrue((target.GetRolesForUser("dkhan").ToList()).Contains(roles[0]));
     115      Assert.IsTrue((target.GetRolesForUser("bfarka").ToList()).Contains(roles[0]));
     116      Assert.IsFalse((target.GetRolesForUser("hmayr").ToList()).Contains(roles[0]));
     117
    97118    }
    98119
     
    132153      Assert.IsTrue(target.GetUsersInRole(null).Length == 0);
    133154      Assert.IsTrue(target.GetUsersInRole(dummyRole).Length == 0);
    134       Persistence.HeuristicLabUser user = new Persistence.HeuristicLabUser("dummyUser", "foo", "foo", "foo");
    135       Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("dummyUser2", "foo", "foo", "foo");
     155      Persistence.HeuristicLabUser user = new Persistence.HeuristicLabUser("dummyUser", "foo1", "foo", "foo");
     156      Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("dummyUser2", "foo2", "foo", "foo");
    136157      db.HeuristicLabUsers.InsertOnSubmit(user);
    137158      db.HeuristicLabUsers.InsertOnSubmit(user2);
     
    174195      Assert.IsTrue(target.GetRolesForUser(dummyUser).Length == 0);
    175196      Persistence.HeuristicLabUser user = new Persistence.HeuristicLabUser("dummyUser", "foo", "foo", "foo");
    176       Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("dummyUser2", "foo", "foo", "foo");
     197      Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("dummyUser2", "foo2", "foo", "foo");
    177198      db.HeuristicLabUsers.InsertOnSubmit(user);
    178199      db.HeuristicLabUsers.InsertOnSubmit(user2);
     
    212233      roleNames.Add("Pascal");
    213234      roleNames.Add("Java");
    214       roleNames.Add("Pascal");
     235      roleNames.Add("c++");
    215236      roleNames.Add("VisalBasic");
    216237      foreach (string s in roleNames) {
     
    235256      Assert.IsTrue(target.FindUsersInRole(null, "dummyUser").Length == 0);
    236257      Persistence.HeuristicLabUser user = new Persistence.HeuristicLabUser("dummyUser", "foo", "foo", "foo");
    237       Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("dummyUser2", "foo", "foo", "foo");
     258      Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("dummyUser2", "foo2", "foo", "foo");
    238259      db.HeuristicLabUsers.InsertOnSubmit(user);
    239260      db.HeuristicLabUsers.InsertOnSubmit(user2);
     
    294315      Dictionary<string, Persistence.HeuristicLabUser> users = new Dictionary<string, Persistence.HeuristicLabUser>();
    295316      List<string> roles = new List<string>();
    296       users.Add("dkhan", new Persistence.HeuristicLabUser("dkhan", "foo", "password", "comment"));
    297       users.Add("hmayr", new Persistence.HeuristicLabUser("hmayr", "foo", "password", "comment"));
    298       users.Add("bfarka", new Persistence.HeuristicLabUser("bfarka", "foo", "password", "comment"));
     317      users.Add("dkhan", new Persistence.HeuristicLabUser("dkhan", "foo1", "password", "comment"));
     318      users.Add("hmayr", new Persistence.HeuristicLabUser("hmayr", "foo2", "password", "comment"));
     319      users.Add("bfarka", new Persistence.HeuristicLabUser("bfarka", "foo3", "password", "comment"));
    299320
    300321      roles.Add("admin");
     
    314335      db.SubmitChanges();
    315336      target.AddUsersToRoles(users.Keys.ToArray(), roles.ToArray());
    316       Assert.IsTrue(getUserRolesCount() == (roles.Count + users.Count));
     337      Assert.IsTrue(getUserRolesCount() == (roles.Count * users.Count));
    317338
    318339    }
Note: See TracChangeset for help on using the changeset viewer.