我有一个测试方法来测试用户是否被添加到角色中。但是我将用户添加到该角色不起作用。有人可以解释我做错了什么吗?
public override void AddUsersToRoles(string[] usernames, string[] roleNames)
{
try
{
Profile.MembershipMapper memberMapper = new Profile.MembershipMapper();
memberMapper.AddUsersToRoles(_memberUtil.GetApplicationId(), usernames, roleNames);
}
catch (Exception ex)
{
throw new ProviderException("AddUsersToRoles", ex);
}
}
string sRoleName = "TestRole";
string sUsername = "test.user";//"testUserX"
// Use a known user for relationships
AsaMembershipProvider prov = this.GetMembershipProvider();
MembershipUser user = prov.GetUser(sUsername, false);
// Create a new role
AsaRoleProvider roleProv = this.GetRoleProvider();
roleProv.CreateRole(sRoleName);
// Verify that role exists
bool bRoleExists = roleProv.RoleExists(sRoleName);
Assert.IsTrue(bRoleExists);
// Add users to that role
string[] usernames = new string[] { sUsername};
string[] roleNames = new string[] { sRoleName };
//Doesnt add user
roleProv.AddUsersToRoles(usernames, roleNames);