Exemplo n.º 1
0
        public async Task TestCreateUserAndDuplicatesClaims()
        {
            using (var fixture = new WebHostFixture())
            {
                var userManager = fixture.GetUserManager();
                var roleManager = fixture.GetRoleManager();
                await InitializeIdentity.SeedPermissions <PermissionsTest>(roleManager).SeedAsync();

                await InitializeIdentity.SeedPermissions <PermissionsTest>(roleManager).SeedAsync();

                var defaultRole = roleManager.Roles.ToList()[0];
                var claims      = await roleManager.GetClaimsAsync(defaultRole);

                var user = new ApplicationUser {
                    Email    = "*****@*****.**",
                    UserName = "******"
                };
                // IN SEQUENCE
                var created = await userManager.CreateAsync(user, "Aa@123456");

                //
                var result = await userManager.AddClaimsAsync(user, claims);

                //
                var userClaims = await userManager.GetClaimsAsync(user);

                Assert.True(result.Succeeded);
                Assert.Equal(2, claims.Count());
                Assert.Equal(2, userClaims.Count());
            }
        }
Exemplo n.º 2
0
        public async Task TestCreateUser()
        {
            using (var fixture = new WebHostFixture())
            {
                var userManager = fixture.GetUserManager();
                var user        = new ApplicationUser {
                    Email    = "*****@*****.**",
                    UserName = "******"
                };

                var created = await userManager.CreateAsync(user, "Aa@123456");

                var find = await userManager.FindByEmailAsync(user.Email);

                var users = userManager.Users.ToList();
                Assert.True(created.Succeeded);
                Assert.Equal(find.Email, user.Email);
                Assert.Single(users);
            }
        }