Ejemplo n.º 1
0
        public async Task FindById_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("prov1", "key1", "name1"),
                    new ElasticUserLogin("prov2", "key2", "name2")
                },
                Email = new ElasticConfirmation("*****@*****.**")
            };

            var createResult = await store.CreateAsync(user, NoCancellationToken);

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

            Assert.Equal(createResult, IdentityResult.Success);
            Assert.Equal(user.Id, elasticUser.Id);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public async Task RemoveClaim_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 claimsToBeRemoved = new List <Claim>
            {
                new Claim("type2", "value2")
            };

            await store.RemoveClaimsAsync(user, claimsToBeRemoved, NoCancellationToken);

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

            Assert.Equal(createResult, IdentityResult.Success);
            Assert.Equal(elasticUser.Claims.Count, 2);
        }
Ejemplo n.º 4
0
        public async Task CanCreateUser()
        {
            var result = await _store.CreateAsync(_user2, CancellationToken.None);

            Assert.True(result.Succeeded);
            var user = await _store.FindByIdAsync(_user2.Id, CancellationToken.None);

            Assert.Equal(_user2.Id, user.Id);
        }