public void AddToRoleTest() { string accountName = "!@#$%^&*()_+-=1234567890qwertyuiop[]\\{}|asdfghjkl;':\"zxcvbnm,./<>?"; AppUser dbUser = database.Users.SingleOrDefault(u => u.AccountName == accountName); if (dbUser != null) { database.Users.Remove(dbUser); database.SaveChanges(); } AppUser user = new AppUser { Name = "张三李四·.", AccountName = accountName, Email = "*****@*****.**", Mobile = "18888888888" }; string password = "******"zxcvbnm,./<>?"; IdentityResult result = helper.CreateUser(user, password, AppRoleEnum.OrgnizationMember, OrganizationEnum.SEA团队); if (!result.Succeeded) { Assert.Inconclusive("CreateUser方法运行失败,本测试无法运行。"); } dbUser = database.Users.SingleOrDefault(u => u.AccountName == user.AccountName); helper.AddToRole(dbUser.Id, AppRoleEnum.LogViewer); AppUserIdentityClaims claims = helper.CreateClaims(user.AccountName, password); if (!claims.IsAuthenticated) { Assert.Inconclusive("CreateClaims方法运行失败,未取得IdentityClaims。"); } if (!claims.IsInRole(AppRoleEnum.LogViewer)) { Assert.Fail("角色添加失败!"); } database.Users.Remove(dbUser); database.SaveChanges(); }