public async Task Resgiter_WhenModelIsValidWithNullPassword_ExpectSuccessAndUserPasswordSet()
        {
            //arrange
            var username = Guid.NewGuid().ToString();
            var user     = new IdentityExpressUser()
            {
                UserName           = username,
                NormalizedUserName = normalizer.Normalize(username)
            };

            using (var context = new IdentityExpressDbContext(options))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }

            var model = new RegisterInputModel
            {
                ConfirmPassword = "******",
                Password        = "******",
                Username        = username
            };


            var list = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("ConfirmPassword", "Password123!"),
                new KeyValuePair <string, string>("Password", "Password123!"),
                new KeyValuePair <string, string>("Username", username)
            };


            //act
            var result = await client.PostAsync("/account/register", new FormUrlEncodedContent(list));

            //assert
            Assert.True(result.IsSuccessStatusCode);

            IdentityExpressUser foundUser;

            using (var context = new IdentityExpressDbContext(options))
            {
                foundUser = await context.Users.FirstOrDefaultAsync(x => x.UserName == username);
            }

            Assert.NotNull(foundUser);
            Assert.NotNull(foundUser.PasswordHash);
        }
        public async Task Resgiter_WhenUserAlreadyHasPassword_ExpectFailureAndPasswordNotUpdated()
        {
            //arrange
            var username = Guid.NewGuid().ToString();
            var user     = new IdentityExpressUser()
            {
                UserName           = username,
                NormalizedUserName = normalizer.Normalize(username)
            };

            var passwordHasher = new PasswordHasher <IdentityExpressUser>();
            var hash           = passwordHasher.HashPassword(user, "hello");

            user.PasswordHash = hash;

            using (var context = new IdentityExpressDbContext(options))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }

            var model = new RegisterInputModel
            {
                ConfirmPassword = "******",
                Password        = "******",
                Username        = username
            };
            var json = JsonConvert.SerializeObject(model);

            //act
            var result = await client.PostAsync("/account/register", new StringContent(json, Encoding.UTF8, "application/json"));

            //assert
            Assert.True(result.IsSuccessStatusCode);

            IdentityExpressUser foundUser;

            using (var context = new IdentityExpressDbContext(options))
            {
                foundUser = await context.Users.FirstOrDefaultAsync(x => x.UserName == username);
            }

            Assert.NotNull(foundUser);
            Assert.Equal(hash, foundUser.PasswordHash);
        }
        public async Task Register_WhenUserAlreadyHasPassword_ExpectFailureAndPasswordNotUpdated()
        {
            //arrange
            var username = Guid.NewGuid().ToString();
            var user     = new IdentityExpressUser()
            {
                UserName           = username,
                NormalizedUserName = normalizer.NormalizeName(username)
            };

            var passwordHasher = new PasswordHasher <IdentityExpressUser>();
            var hash           = passwordHasher.HashPassword(user, "hello");

            user.PasswordHash = hash;

            using (var context = new IdentityExpressDbContext(options))
            {
                context.Users.Add(user);
                context.SaveChanges();
            }

            var registerInputModel = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("ConfirmPassword", "Password123!"),
                new KeyValuePair <string, string>("Password", "Password123!"),
                new KeyValuePair <string, string>("Username", username)
            };

            //act
            var result = await client.PostAsync("/account/register", new FormUrlEncodedContent(registerInputModel));

            //assert
            Assert.True(result.IsSuccessStatusCode);

            IdentityExpressUser foundUser;

            using (var context = new IdentityExpressDbContext(options))
            {
                foundUser = await context.Users.FirstOrDefaultAsync(x => x.UserName == username);
            }

            Assert.NotNull(foundUser);
            Assert.Equal(hash, foundUser.PasswordHash);
        }