BobRock
BobRock

Reputation: 3467

unit testing custom role provider

I'm trying to exercise custom role provider methods. Each test is on its own, which means that it's indepent from other test and that in every test I create test user, test role, etc. That's fine, I know for other approaches but this suits ok for this purpose.

So, I'm struggling with can_get_roles_for_user, here's the code

[Test]
public void can_get_roles_for_user()
{
    MembershipCreateStatus status = new MembershipCreateStatus();
    provider.CreateUser("testuser", "password", "[email protected]", "question", "answer", true, Guid.NewGuid(), out status);
    provider.CreateUser("testuser2", "password", "[email protected]", "question", "answer", true, Guid.NewGuid(), out status);

    roleProvider.CreateRole("TestRole");
    roleProvider.CreateRole("AdministratorRole");

    string[] users = { "TestUser", "TestUserAdministrator" };
    string[] roles = { "TestRole", "AdministratorTestRole" };

    roleProvider.AddUsersToRoles(users, roles);

    var user = _provider.GetUser("TestUser", false);
    string[] userRoles = _roleProvider.GetRolesForUser(user.UserName);

    **//WHAT SHOULD I ASSERT HERE?**

}

Any sugg, links to your or some other test role provider are welcome.

Thanks

Upvotes: 3

Views: 705

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236188

You can simply compare roles collections:

CollectionAssert.AreEquivalent(roles, _roleProvider.GetRolesForUser(user.UserName));

Upvotes: 3

Related Questions