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); }
public async Task SetTwoFactorEnabled_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("type", "value1") }, Email = new ElasticConfirmation("*****@*****.**") }; var createResult = await store.CreateAsync(user, NoCancellationToken); await store.SetTwoFactorEnabledAsync(user, true, NoCancellationToken); await store.UpdateAsync(user, NoCancellationToken); var elasticUser = await store.FindByIdAsync(user.Id, NoCancellationToken); Assert.Equal(createResult, IdentityResult.Success); Assert.True(elasticUser.IsTwoFactorEnabled); }
public async Task Update_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")), new ElasticUserLogin(new UserLoginInfo("prov2", "key2", "test2")) }, Email = new ElasticConfirmation("*****@*****.**") }; var createResult = await store.CreateAsync(user, NoCancellationToken); user.Email.Value = "*****@*****.**"; await store.UpdateAsync(user, NoCancellationToken); var elasticUser = await store.FindByIdAsync(user.Id, NoCancellationToken); Assert.Equal(createResult, IdentityResult.Success); Assert.Equal(user.Email.Value, elasticUser.Email.Value); }
public async Task CanUpdateUser() { var originalDateCreated = _user2.DateCreated; var result = await _store.CreateAsync(_user2, CancellationToken.None); _elasticClient.Indices.Refresh(_indexName); Assert.True(result.Succeeded); var user = await _store.FindByIdAsync(_user2.Id, CancellationToken.None); Assert.Equal(_user2.Id, user.Id); DateTimeOffset newDateCreated = (originalDateCreated + TimeSpan.FromSeconds(1)); _user2.DateCreated = newDateCreated; var updateResult = await _store.UpdateAsync(_user2, CancellationToken.None); _elasticClient.Indices.Refresh(_indexName); user = await _store.FindByIdAsync(_user2.Id, CancellationToken.None); Assert.Equal( newDateCreated, user.DateCreated); DateTimeOffset newerDateCreated = (newDateCreated + TimeSpan.FromSeconds(1)); _user2.DateCreated = newerDateCreated; updateResult = await _store.UpdateAsync(_user2, CancellationToken.None); _elasticClient.Indices.Refresh(_indexName); user = await _store.FindByIdAsync(_user2.Id, CancellationToken.None); Assert.Equal( newerDateCreated, user.DateCreated); }