public async Task Test_Create_IdentityServerUser_Add_ClientIds_Async()
        {
            var userId     = Guid.NewGuid().ToString();
            var adminStore = new IdentityServer3AdminStore();
            var user       = new IdentityServerUser {
                Enabled = true, UserId = userId, UserName = "******" + userId
            };

            await adminStore.CreateIdentityServerUserAsync(user);

            var result = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.AreEqual(user.UserId, result.UserId);

            List <string> clientIdsToAdd = new List <string> {
                "clientid1", "clientid2"
            };
            await adminStore.AddClientIdToIdentityServerUserAsync(userId, clientIdsToAdd);

            var clientIds = await adminStore.FindClientIdsByUserAsync(userId);

            Assert.AreEqual(clientIds.Count(), clientIdsToAdd.Count);
            var finalList = clientIds.ToList().Except(clientIdsToAdd);

            Assert.IsFalse(finalList.Any());
        }
        public async Task Test_Create_IdentityServerUser_Add_AllowedScopes_Async()
        {
            var userId     = Guid.NewGuid().ToString();
            var adminStore = new IdentityServer3AdminStore();
            var user       = new IdentityServerUser {
                Enabled = true, UserId = userId, UserName = "******" + userId
            };

            await adminStore.CreateIdentityServerUserAsync(user);

            var result = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.AreEqual(user.UserId, result.UserId);
            List <string> scopesToAdd = new List <string> {
                "scope1", "scope2"
            };
            await adminStore.AddScopesToIdentityServerUserAsync(userId, scopesToAdd);

            var scopes = await adminStore.FindScopesByUserAsync(userId);

            Assert.AreEqual(scopes.Count(), scopesToAdd.Count);
            var finalList = scopes.ToList().Except(scopesToAdd);

            Assert.IsFalse(finalList.Any());
        }
        public async Task Test_Create_And_Delete_IdentityServerUserAsync()
        {
            var userId     = Guid.NewGuid().ToString();
            var adminStore = new IdentityServer3AdminStore();
            var user       = new IdentityServerUser {
                Enabled = true, UserId = userId, UserName = "******" + userId
            };

            var appliedInfo = await adminStore.CreateIdentityServerUserAsync(user);

            Assert.IsTrue(appliedInfo.Applied);
            Assert.IsNull(appliedInfo.Exception);
            var result = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.AreEqual(user.UserId, result.UserId);

            List <string> clientIdsToAdd = new List <string> {
                "clientid1", "clientid2", "clientid3", "clientid4"
            };
            await adminStore.AddClientIdToIdentityServerUserAsync(userId, clientIdsToAdd);

            var clientIds = await adminStore.FindClientIdsByUserAsync(userId);

            Assert.AreEqual(clientIds.Count(), clientIdsToAdd.Count);
            var finalList = clientIds.ToList().Except(clientIdsToAdd);

            Assert.IsFalse(finalList.Any());

            List <string> scopesToAdd = new List <string> {
                "scope1", "scope2", "scope3", "scope4"
            };
            await adminStore.AddScopesToIdentityServerUserAsync(userId, scopesToAdd);

            var scopes = await adminStore.FindScopesByUserAsync(userId);

            Assert.AreEqual(scopes.Count(), scopesToAdd.Count);
            finalList = scopes.ToList().Except(scopesToAdd);
            Assert.IsFalse(finalList.Any());

            appliedInfo = await adminStore.DeleteIdentityServerUserAsync(userId);

            Assert.IsTrue(appliedInfo.Applied);
            Assert.IsNull(appliedInfo.Exception);
            result = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.IsNull(result);
        }
        public async Task Test_Find_No_IdentityServerUserAsync()
        {
            var userId     = Guid.NewGuid().ToString();
            var adminStore = new IdentityServer3AdminStore();
            var result     = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.IsNull(result);
        }
        public async Task Test_Create_IdentityServerUserAsync()
        {
            var userId     = Guid.NewGuid().ToString();
            var adminStore = new IdentityServer3AdminStore();
            var user       = new IdentityServerUser {
                Enabled = true, UserId = userId, UserName = "******" + userId
            };
            var result = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.IsNull(result);
            await adminStore.CreateIdentityServerUserAsync(user);

            result = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.IsNotNull(result);



            Assert.AreEqual(user.UserId, result.UserId);
        }
        public async Task <IdentityServerUser> GetIdentityServerUser(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            var adminStore = new IdentityServer3AdminStore();
            var user       = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            return(user);
        }
        public async Task UpdateIdentityServerUser(string userId, bool enabled)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException("userId");
            }
            var adminStore = new IdentityServer3AdminStore();
            var user       = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            if (user != null)
            {
                user.Enabled = enabled;
                await adminStore.UpdateIdentityServerUserAsync(user);
            }
        }
        public async Task Test_Create_IdentityServerUser_Find_No_AllowedScopes_Async()
        {
            var userId     = Guid.NewGuid().ToString();
            var adminStore = new IdentityServer3AdminStore();
            var user       = new IdentityServerUser {
                Enabled = true, UserId = userId, UserName = "******" + userId
            };

            await adminStore.CreateIdentityServerUserAsync(user);

            var result = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.AreEqual(user.UserId, result.UserId);
            var scopes = await adminStore.FindScopesByUserAsync(userId);

            Assert.IsTrue(scopes.Count() == 0);
        }