我有一个测试要求删除 SimpleMembershipProvider UserProfile 表中的所有用户。我想在我的 SeedMembership() 方法中执行此操作(如下)。像membership.DeleteAllUsers 这样的东西。知道如何做到这一点吗?
private int SeedMembership()
{
if (!WebMatrix.WebData.WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("TestConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}
var roles = (SimpleRoleProvider)Roles.Provider;
var membership = (SimpleMembershipProvider)Membership.Provider;
if (!roles.RoleExists("Admin"))
{
roles.CreateRole("Admin");
}
if (!roles.RoleExists("User"))
{
roles.CreateRole("User");
}
// Somehow delete all users here
if (membership.GetUser("user", false) == null)
{
membership.CreateUserAndAccount("user", "covert");
}
if (!roles.GetRolesForUser("user").Contains("Admin"))
{
roles.AddUsersToRoles(new[] { "user" }, new[] { "admin" });
}
return membership.GetUserId("user");
}