Ejemplo n.º 1
0
        public async Task CanAddClaim()
        {
            var claim = new Claim("testType", "testValue");
            var user  = await _store.FindByNameAsync(_user1.NormalizedUserName, CancellationToken.None);

            Assert.Empty(user.Claims);

            await _store.AddClaimsAsync(user, new[] { claim }, CancellationToken.None);

            await SaveToElastic(user);

            user = await GetFromElastic(user.NormalizedUserName);

            Assert.NotEmpty(user.Claims);
        }
Ejemplo n.º 2
0
        public async Task AddClaims_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);

            var newClaims = new List <Claim>
            {
                new Claim("type2", "value2"),
                new Claim("type3", "value3")
            };
            await store.AddClaimsAsync(user, newClaims, NoCancellationToken);

            await store.UpdateAsync(user, NoCancellationToken);

            var elasticUser = await store.FindByIdAsync(user.Id, NoCancellationToken);

            Assert.Equal(createResult, IdentityResult.Success);
            Assert.Equal(elasticUser.Claims.Count, 3);
        }