Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/10 11:45:44 (14 years ago)
Author:
bfarka
Message:

added bugfixes and unittests for roleprovider (#1046)

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

Legend:

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

    r3955 r3960  
    2020            userRole.HeuristicLabRole = role;
    2121            userRole.HeuristicLabUser = user;
    22 
    2322            db.HeuristicLabUserRole.InsertOnSubmit(userRole);
    24 
    2523          }
    2624        }
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs

    r3955 r3960  
    130130    public void GetRolesForUserTest() {
    131131      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
    132       string username = string.Empty; // TODO: Initialize to an appropriate value
    133       string[] expected = null; // TODO: Initialize to an appropriate value
    134       string[] actual;
    135       actual = target.GetRolesForUser(username);
    136       Assert.AreEqual(expected, actual);
    137       Assert.Inconclusive("Verify the correctness of this test method.");
     132      string dummyUser = "dummyUser";
     133      Assert.IsTrue(target.GetRolesForUser(null).Length == 0);
     134      Assert.IsTrue(target.GetRolesForUser(dummyUser).Length == 0);
     135      Persistence.HeuristicLabUser user = new Persistence.HeuristicLabUser("dummyUser", "foo", "foo", "foo");
     136      Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("dummyUser2", "foo", "foo", "foo");
     137      db.HeuristicLabUsers.InsertOnSubmit(user);
     138      db.HeuristicLabUsers.InsertOnSubmit(user2);
     139      db.SubmitChanges();
     140      target.CreateRole("testRole1");
     141      target.CreateRole("testRole2");
     142      List<string> users = new List<string>();
     143      List<string> roles = new List<string>();
     144      users.Add("dummyUser");
     145      users.Add("dummyUser2");
     146      roles.Add("testRole1");
     147      target.AddUsersToRoles(users.ToArray(), roles.ToArray());
     148      users.Remove("dummyUser2");
     149      roles.Add("testRole2");
     150      roles.Remove("testRole1");
     151      target.AddUsersToRoles(users.ToArray(), roles.ToArray());
     152      string[] rolesForUser = target.GetRolesForUser("dummyUser");
     153      Assert.IsTrue(rolesForUser.Length == 2);
     154      Assert.IsTrue(rolesForUser.Contains("testRole1"));
     155      Assert.IsTrue(rolesForUser.Contains("testRole2"));
     156
     157      rolesForUser = target.GetRolesForUser("dummyUser2");
     158      Assert.IsTrue(rolesForUser.Length == 1);
     159      Assert.IsTrue(rolesForUser.Contains("testRole1"));
     160
     161     
     162     
    138163    }
    139164
     
    166191    [TestMethod()]
    167192    public void FindUsersInRoleTest() {
    168       HeuristicLabRoleProvider target = new HeuristicLabRoleProvider(); // TODO: Initialize to an appropriate value
    169       string roleName = string.Empty; // TODO: Initialize to an appropriate value
    170       string usernameToMatch = string.Empty; // TODO: Initialize to an appropriate value
    171       string[] expected = null; // TODO: Initialize to an appropriate value
    172       string[] actual;
    173       actual = target.FindUsersInRole(roleName, usernameToMatch);
    174       Assert.AreEqual(expected, actual);
    175       Assert.Inconclusive("Verify the correctness of this test method.");
     193      HeuristicLabRoleProvider target = new HeuristicLabRoleProvider();
     194      Assert.IsTrue(target.FindUsersInRole(null, null).Length == 0);
     195      Assert.IsTrue(target.FindUsersInRole("dummyRole", null).Length == 0);
     196      Assert.IsTrue(target.FindUsersInRole(null, "dummyUser").Length == 0);
     197      Persistence.HeuristicLabUser user = new Persistence.HeuristicLabUser("dummyUser", "foo", "foo", "foo");
     198      Persistence.HeuristicLabUser user2 = new Persistence.HeuristicLabUser("dummyUser2", "foo", "foo", "foo");
     199      db.HeuristicLabUsers.InsertOnSubmit(user);
     200      db.HeuristicLabUsers.InsertOnSubmit(user2);
     201      db.SubmitChanges();
     202      target.CreateRole("testRole");
     203      Assert.IsTrue(target.FindUsersInRole("testRole", "dummyUser").Length == 0);
     204      Assert.IsTrue(target.FindUsersInRole("testRole", "dummyUser2").Length == 0);
     205      Assert.IsTrue(target.FindUsersInRole("testRole", "dummyUser3").Length == 0);
     206
     207      target.AddUsersToRoles(new string[] { "dummyUser", "dummyUser2" }, new string[] {"testRole" });
     208      Assert.IsTrue(target.FindUsersInRole("testRole", "dummyUser").Length == 2);
     209      Assert.IsTrue(target.FindUsersInRole("testRole", "dummyUser2").Length == 1);
     210      Assert.IsTrue(target.FindUsersInRole("testRole", "dummyUser3").Length == 0);
     211
     212
    176213    }
    177214
     
    206243
    207244    protected int getUserRolesCount() {
    208       return db.HeuristicLabUserRole.Count();
    209            
    210      
     245      return db.HeuristicLabUserRole.Count();     
    211246    }
    212247
Note: See TracChangeset for help on using the changeset viewer.