public async Task CanReplaceClaim() { ElasticIdentityUser noClaimsUser2 = new ElasticIdentityUser(nameof(noClaimsUser2)); await _store.CreateAsync(noClaimsUser2, CancellationToken.None); var oldClaim = new Claim("testType", "testValue"); var newClaim = new Claim("newTestType", "newTestValue"); var user = await _store.FindByNameAsync(noClaimsUser2.NormalizedUserName, CancellationToken.None); await _store.AddClaimsAsync(user, new[] { oldClaim }, CancellationToken.None); await SaveToElastic(user); user = await GetFromElastic(user.NormalizedUserName); Assert.NotEmpty(user.Claims); await _store.ReplaceClaimAsync(user, oldClaim, newClaim, CancellationToken.None); await SaveToElastic(user); user = await GetFromElastic(user.NormalizedUserName); Assert.True(user.Claims.All(claim => claim.Type == newClaim.Type && claim.Value == newClaim.Value)); }
public async Task ReplaceClaim_Test() { var store = new ElasticUserStore <ElasticUser, ElasticRole>(_nestClient, new ElasticOptions { UsersIndex = _userIndex }); var user = new ElasticUser { UserName = "******", PasswordHash = "phash", Logins = new List <ElasticUserLogin> { new ElasticUserLogin(new UserLoginInfo("prov1", "key1", "test1")) }, Claims = new List <ElasticClaim> { new ElasticClaim("type1", "value1"), new ElasticClaim("type2", "value2") }, Email = new ElasticConfirmation("*****@*****.**") }; var createResult = await store.CreateAsync(user, NoCancellationToken); await store.ReplaceClaimAsync(user, new Claim("type2", "value2"), new Claim("type2", "value22"), NoCancellationToken); await store.UpdateAsync(user, NoCancellationToken); var elasticUser = await store.FindByIdAsync(user.Id, NoCancellationToken); var changedClaim = elasticUser.Claims.Find(x => x.Value == "value22"); Assert.Equal(createResult, IdentityResult.Success); Assert.NotNull(changedClaim); }