Example #1
0
 public void GetUserClaimSyncTest()
 {
     var db = UnitTestHelper.CreateDefaultDb();
     var manager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(db));
     var user = new IdentityUser("u1");
     var result = manager.Create(user);
     UnitTestHelper.IsSuccess(result);
     Assert.NotNull(user);
     var claims = new[]
     {
         new Claim("c1", "v1"),
         new Claim("c2", "v2"),
         new Claim("c3", "v3")
     };
     foreach (Claim c in claims)
     {
         UnitTestHelper.IsSuccess(manager.AddClaim(user.Id, c));
     }
     var userClaims = new List<Claim>(manager.GetClaims(user.Id));
     Assert.Equal(3, userClaims.Count);
     foreach (Claim c in claims)
     {
         Assert.True(userClaims.Exists(u => u.Type == c.Type && u.Value == c.Value));
     }
 }
 public void AddClaim()
 {
     var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(this._session));
     var user = new ApplicationUser() { UserName = "test", Email = "[email protected]", EmailConfirmed = true };
     userManager.Create(user, "Welcome");
     userManager.AddClaim(user.Id, new Claim(ClaimTypes.Role, "Admin"));
     Assert.AreEqual(1, userManager.GetClaims(user.Id).Count());
 }