public void UserWithoutClaims_RemoveClaim_DoesNothing() { var user = new IdentityUser(); string claimType = "test-claim"; string claimValue = "test-value"; var claim = new Claim(claimType, claimValue); user.RemoveClaim(claim); Assert.Empty(user.Claims); }
public void UserWithOneClaim_RemoveTheClaim_NoClaimsRemain() { var user = new IdentityUser(); string claimType = "test-claim"; string claimValue = "test-value"; var claim1 = new Claim(claimType, claimValue); var claim2 = new Claim(claimType, claimValue); user.AddClaim(claim1); user.RemoveClaim(claim2); Assert.Empty(user.Claims); }
public void UserWithOneClaim_RemoveNonExistingClaim_DoesNothing() { var user = new IdentityUser(); string claimType = "test-claim"; string claimValue = "test-value"; var claim = new Claim(claimType, claimValue); user.AddClaim(claim); user.RemoveClaim(new Claim("non-existing-type", "non-existing-value")); Assert.Equal(1, user.Claims.Count); Assert.Equal(claimType, user.Claims[0].ClaimType); Assert.Equal(claimValue, user.Claims[0].ClaimValue); }
public async Task RemoveClaimAsync(IdentityUser user, Models.UserClaim claim) { using (var db = new SqlDbContext(_options)) { try { var dbUser = db.IdentityUser.FirstOrDefault(tbl => tbl.Id == user.Id); if (dbUser == null) { user.RemoveClaim(claim); db.Update(user); } await db.SaveChangesAsync(); } catch (Exception exc) { } } }
public void UserWithTwoClaims_RemoveOneOfTheClaims_OtherClaimRemains() { var user = new IdentityUser(); string claimType1 = "test-claim-1"; string claimValue1 = "test-value-1"; var claim1 = new Claim(claimType1, claimValue1); string claimType2 = "test-claim-2"; string claimValue2 = "test-value-2"; var claim2 = new Claim(claimType2, claimValue2); user.AddClaim(claim1); user.AddClaim(claim2); user.RemoveClaim(new Claim(claimType1, claimValue1)); Assert.Equal(1, user.Claims.Count); Assert.Equal(claimType2, user.Claims[0].ClaimType); Assert.Equal(claimValue2, user.Claims[0].ClaimValue); }