Esempio n. 1
0
        public void AddClaim()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);
            var rs     = CreateRoleStore(client);

            // cleanup
            // cleanup
            client.Cypher.Match("(n:IdentityRole)").Where("n.Name= 'TEST_ROLE'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityClaim)").Where("n.Type= 'TEST_CLAIM'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();


            var user = CreateUser(client, us);
            var role = CreateRole(client, rs);

            us.AddClaimsAsync(user, new[] { new Claim("TEST_CLAIM", "TEST_CLAIM_VALUE") }, default).Wait();
            us.UpdateAsync(user, CancellationToken.None).Wait();
            var u = us.FindByIdAsync(user.Id, default).Result;

            Assert.Single(u.Claims);
            Assert.Equal(u.Claims.FirstOrDefault().Type, "TEST_CLAIM");
            Assert.Equal(u.Claims.FirstOrDefault().Value, "TEST_CLAIM_VALUE");

            // cleanup
            client.Cypher.Match("(n:IdentityRole)").Where("n.Name= 'TEST_ROLE'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityClaim)").Where("n.Type= 'TEST_CLAIM'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
        }
Esempio n. 2
0
        public void RemoveRole()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);
            var rs     = CreateRoleStore(client);

            // cleanup
            // cleanup
            client.Cypher.Match("(n:IdentityRole)").Where("n.Name= 'TEST_ROLE'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();

            var user = CreateUser(client, us);
            var role = CreateRole(client, rs);

            us.AddToRoleAsync(user, role.Name, default).Wait();
            us.UpdateAsync(user, CancellationToken.None).Wait();
            var u = us.FindByIdAsync(user.Id, default).Result;

            Assert.Single(u.Roles);
            us.RemoveFromRoleAsync(u, "TEST_ROLE", default);
            us.UpdateAsync(u, CancellationToken.None).Wait();
            u = us.FindByIdAsync(user.Id, default).Result;
            Assert.Empty(u.Roles);
            // cleanup
            client.Cypher.Match("(n:IdentityRole)").Where("n.Name= 'TEST_ROLE'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
        }
Esempio n. 3
0
        public void Update()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);

            // cleanup
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();

            var user = CreateUser(client, us);

            user.SetEmail("*****@*****.**");
            var res = us.UpdateAsync(user, default).Result;

            Assert.True(res.Succeeded);
            user = us.FindByIdAsync(user.Id, default).Result;
            Assert.Equal("*****@*****.**", user.Email.Value);
            user.SetEmail("*****@*****.**");
            res = us.UpdateAsync(user, default).Result;
            Assert.True(res.Succeeded);

            // cleanup
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
        }
Esempio n. 4
0
        public void GetUsersInRole()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);
            var rs     = CreateRoleStore(client);

            // cleanup
            Clean(client);
            var data = CreateTestData(client, us, rs);
            var u    = us.GetUsersInRoleAsync(data.Item1.NormalizedName, default).Result;

            Assert.Single(u);

            // cleanup
            Clean(client);
        }
Esempio n. 5
0
        public void GetUsersForClaim()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);
            var rs     = CreateRoleStore(client);

            // cleanup
            Clean(client);
            var data = CreateTestData(client, us, rs);
            var u    = us.GetUsersForClaimAsync(new Claim(data.Item2.Type, data.Item2.Value), default).Result;

            Assert.Single(u);

            // cleanup
            Clean(client);
        }
Esempio n. 6
0
        public void FindByLogin()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);
            var rs     = CreateRoleStore(client);

            // cleanup
            Clean(client);
            var data = CreateTestData(client, us, rs);
            var u    = us.FindByLoginAsync(data.Item3.LoginProvider, data.Item3.ProviderKey, default).Result;

            Assert.NotNull(u);
            Assert.NotNull(u.Id);
            Assert.NotNull(u.UserName);
            Assert.NotNull(u.Email);
            Assert.NotNull(u.CreatedOn);
            // cleanup
            Clean(client);
        }
Esempio n. 7
0
        public void Create()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);

            // cleanup
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();

            var u = CreateUser(client, us);

            Assert.NotNull(u);
            Assert.NotNull(u.Id);
            Assert.NotNull(u.UserName);
            Assert.NotNull(u.Email);
            Assert.NotNull(u.CreatedOn);
            // cleanup
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
        }
Esempio n. 8
0
        public void GeneralPurposeTests()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);
            var rs     = CreateRoleStore(client);

            // cleanup
            Clean(client);
            var data = CreateTestData(client, us, rs);

            us.SetEmailConfirmedAsync(data.Item4, true, default);
            us.SetLockoutEnabledAsync(data.Item4, true, default);
            us.SetLockoutEndDateAsync(data.Item4, DateTimeOffset.MaxValue, default);
            us.SetPasswordHashAsync(data.Item4, "AAA", default);
            us.SetPhoneNumberAsync(data.Item4, "AAAAAA", default);
            us.SetPhoneNumberConfirmedAsync(data.Item4, true, default);
            us.SetTwoFactorEnabledAsync(data.Item4, true, default);
            var r = us.UpdateAsync(data.Item4, default).Result;

            Assert.True(r.Succeeded);
            // cleanup
            Clean(client);
        }
Esempio n. 9
0
        public void RemoveLogin()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);
            var rs     = CreateRoleStore(client);

            // cleanup
            // cleanup
            client.Cypher.Match("(n:IdentityRole)").Where("n.Name= 'TEST_ROLE'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityExternalLogin)").Where("n.LoginProvider= 'GOOGLE'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();


            var user = CreateUser(client, us);
            var role = CreateRole(client, rs);

            us.AddLoginAsync(user, new UserLoginInfo("GOOGLE", "KEY", "XGOOGLE"), default).Wait();
            us.UpdateAsync(user, CancellationToken.None).Wait();
            var u = us.FindByIdAsync(user.Id, default).Result;

            Assert.Single(u.Logins);
            us.RemoveLoginAsync(u, "GOOGLE", "KEY", default);
            us.UpdateAsync(u, CancellationToken.None).Wait();
            u = us.FindByIdAsync(user.Id, default).Result;
            Assert.Empty(u.Logins);

            // cleanup
            client.Cypher.Match("(n:IdentityRole)").Where("n.Name= 'TEST_ROLE'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
            client.Cypher.Match("(n:IdentityExternalLogin)").Where("n.LoginProvider= 'GOOGLE'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
        }
Esempio n. 10
0
        public void Delete()
        {
            var client = RoleStoreTests.CreateGraphClient();
            var us     = CreateStore(client);

            // cleanup
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();

            var user = CreateUser(client, us);

            var res = us.DeleteAsync(user, default).Result;

            Assert.True(res.Succeeded);
            var du = client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'")
                     .AsAnnotatedQuery()
                     .Return(n => n.As <IdentityUser>())
                     .AsCypherQuery().ResultsAsync.Result.FirstOrDefault();

            Assert.Null(du);
            // cleanup
            client.Cypher.Match("(n:IdentityUser)").Where("n.Email_Value= '*****@*****.**'").DetachDelete("n")
            .ExecuteWithoutResultsAsync().Wait();
        }