public void DeleteUserClaim()
        {
            IdentityUser user = new IdentityUser {
                UserName = "******", Email = "*****@*****.**", PhoneNumber = "1234567890", PasswordHash = "@#$rfgt$##WE", EmailConfirmed = true, PhoneNumberConfirmed = true, TwoFactorEnabled = false, LockoutEnabled = false, AccessFailedCount = 0
            };

            user = userTable.Insert(user);
            object claim = new { UserId = user.Id, ClaimType = "Claim1", ClaimValue = "Value1" };

            claim = userClaimTable.Insert(claim);
            userClaimTable.Delete(claim);
            userClaimTable.Delete(where : "ClaimType = 'Claim1'");
            int count = userClaimTable.All("ClaimType = 'Claim1'").ToList().Count;

            Assert.AreEqual(0, count);
        }
        public void It_deletes_all_userclaims_of_user()
        {
            int            result;
            ClaimsIdentity claims;

            using (var transaction = _database.GetTransaction())
            {
                var user = _userTable.GetUserByName(name1).FirstOrDefault();
                CreateUserClaim(user, cType1, cValue1);
                result = _userClaimTable.Delete(user.Id);
                claims = _userClaimTable.FindByUserId(user.Id);
                transaction.Dispose();
            }

            Assert.AreEqual(1, result);
            Assert.IsTrue(!claims.Claims.Any());
        }
예제 #3
0
        /// <summary>
        /// Removes a claim assignment from the user.
        /// New Approach: Check if the given Claim object is assigned to the user and delete the
        /// assignment(s), if existent. It's not client-agnostic, here!
        /// </summary>
        /// <param name="user"></param>
        /// <param name="claim"></param>
        /// <returns></returns>
        public Task RemoveClaimAsync(TUser user, Claim claim)
        {
            if (user == null)
            {
                throw new ArgumentNullException(IdentityConstants.User);
            }

            if (claim == null)
            {
                throw new ArgumentNullException(IdentityConstants.Claim);
            }

            var claimsAssigned = _userClaimTable
                                 .GetClaims(user.Id)
                                 .Where(c => c.Type == claim.Type && c.Value == claim.Value)
                                 .ToList();

            foreach (var identityClaim in claimsAssigned)
            {
                _userClaimTable.Delete(identityClaim, user);
            }

            return(Task.FromResult <object>(null));
        }