public async Task GetUsersInRole_Test() { var store = new ElasticUserStore <ElasticUser, ElasticRole>(_nestClient, new ElasticOptions { UsersIndex = _userIndex }); var user1 = 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 user2 = new ElasticUser { UserName = "******", PasswordHash = "phash", Logins = new List <ElasticUserLogin> { new ElasticUserLogin(new UserLoginInfo("prov2", "key2", "test2")) }, Claims = new List <ElasticClaim> { new ElasticClaim("type", "value2") }, Email = new ElasticConfirmation("*****@*****.**") }; var createResult1 = await store.CreateAsync(user1, NoCancellationToken); var createResult2 = await store.CreateAsync(user2, NoCancellationToken); await store.AddToRoleAsync(user1, "role1", NoCancellationToken); await store.AddToRoleAsync(user1, "role2", NoCancellationToken); await store.AddToRoleAsync(user2, "role1", NoCancellationToken); var usersForRole1 = await store.GetUsersInRoleAsync("role1", NoCancellationToken); var usersForRole2 = await store.GetUsersInRoleAsync("role2", NoCancellationToken); Assert.Equal(createResult1, IdentityResult.Success); Assert.Equal(createResult2, IdentityResult.Success); Assert.Equal(usersForRole1.Count, 2); Assert.Equal(usersForRole2.Count, 1); }
public async Task CanAddRoles() { const string roleName = "test"; var user = await _store.FindByNameAsync(_user1.NormalizedUserName, CancellationToken.None); Assert.Empty(user.Roles); await _store.AddToRoleAsync(user, roleName, CancellationToken.None); await SaveToElastic(user); //reload user = await _store.FindByNameAsync(_user1.NormalizedUserName, CancellationToken.None); Assert.True(user.Roles.Select(role => role.RoleId).Contains(roleName)); }
public async Task AddToRole_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.AddToRoleAsync(user, "role1", NoCancellationToken); var elasticUser = await store.FindByIdAsync(user.Id, NoCancellationToken); var isInRole = await store.IsInRoleAsync(elasticUser, "role1", NoCancellationToken); Assert.Equal(createResult, IdentityResult.Success); Assert.True(isInRole); }