Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3963 for branches


Ignore:
Timestamp:
06/26/10 12:51:55 (14 years ago)
Author:
mholper
Message:

implemented RoleProvider.IsUserInRole (#1046)

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

Legend:

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

    r3962 r3963  
    100100    }
    101101
     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>
    102109    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;
    104117    }
    105118
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabRoleProviderTest.cs

    r3960 r3963  
    1212    private TestContext testContextInstance;
    1313    private const string TEST_ROLE_NAME = "testRole";
     14    private const string TEST_USER_NAME = "testUser";
    1415    /// <summary>
    1516    ///Gets or sets the test context which provides
     
    9697
    9798    /// <summary>
    98     ///A test for IsUserInRole
     99    /// test if user is in Role (positive and negative Assertion)
    99100    ///</summary>
    100101    [TestMethod()]
    101102    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"));
    110124    }
    111125
Note: See TracChangeset for help on using the changeset viewer.