C#-单元测试自定义角色提供程序
作者:互联网
我正在尝试使用自定义角色提供程序方法.每个测试都是独立的,这意味着它独立于其他测试,并且在每个测试中我都创建了测试用户,测试角色等.
很好,我知道其他方法,但是适合此目的.
所以,我在努力与can_get_roles_for_user,这是代码
[Test]
public void can_get_roles_for_user()
{
MembershipCreateStatus status = new MembershipCreateStatus();
provider.CreateUser("testuser", "password", "testuseremail@google.com", "question", "answer", true, Guid.NewGuid(), out status);
provider.CreateUser("testuser2", "password", "testuseremail@google.com", "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?**
}
欢迎任何建议,指向您或其他测试角色提供者的链接.
谢谢
解决方法:
您可以简单地比较角色集合:
CollectionAssert.AreEquivalent(roles, _roleProvider.GetRolesForUser(user.UserName));
标签:membership-provider,tdd,asp-net-membership,c 来源: https://codeday.me/bug/20191201/2079313.html