Esempio n. 1
1
        public async void FindByEmailAsync_GivenAnEmailAddress_ReturnsAUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = false,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var foundUser = await userStore.FindByEmailAsync("[email protected]");

            foundUser.Should().NotBeNull();
        }
        public async void HasPasswordAsync_GivenAUserWithAPasswordHash_ReturnsTrue()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var hasPasswordHash = await userStore.HasPasswordAsync(user);

            hasPasswordHash.Should().BeTrue();
        }
        public async void SetPasswordHashAsync_GivenAUserAndPasswordHash_SetsTheHashForTheUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            await userStore.SetPasswordHashAsync(user, "1234");

            var passwordHash = await userStore.GetPasswordHashAsync(user);

            passwordHash.Should().Be("1234");
        }
Esempio n. 4
0
        public async void UpdateAsync_GivenAnUpdate_UpdatesTheUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var existingUser = await userStore.FindByNameAsync("UserName");
            existingUser.Email = "[email protected]";
            existingUser.PhoneNumber = "1234";

            await userStore.UpdateAsync(existingUser);

            var updatedUser = await userStore.FindByNameAsync("UserName");

            updatedUser.Should().NotBeNull();
            updatedUser.Email.Should().Be("[email protected]");
            updatedUser.PhoneNumber.Should().Be("1234");
        }
Esempio n. 5
0
        public async void CreateAsync_GivenNewUser_CreatesNewUserAndAssignsUserId()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var insertedUser = await userStore.FindByIdAsync(user.Id);

            insertedUser.Should().NotBeNull();
            insertedUser.Email.Should().Be("[email protected]");
        }
Esempio n. 6
0
        public async void RemoveClaimAsync_GivenAUserAndClaim_RemovesTheClaim()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var insertedUser = await userStore.FindByIdAsync(user.Id);

            await userStore.AddClaimAsync(insertedUser, new Claim("ClaimType2", "ClaimValue2"));

            await userStore.RemoveClaimAsync(insertedUser, new Claim("ClaimType2", "ClaimValue2"));

            IList<Claim> claims = await userStore.GetClaimsAsync(user);

            claims.Should().HaveCount(0);
        }
Esempio n. 7
0
        public async void RemoveFromRoleAsync_GivenAUserAndRole_RemovesTheUserFromTheRole()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            await userStore.AddToRoleAsync(user, "User");

            await userStore.RemoveFromRoleAsync(user, "User");

            var roles = await userStore.GetRolesAsync(user);

            roles.Should().HaveCount(0);
        }
Esempio n. 8
0
        public async void SetUp()
        {
            List<Role> roles = new List<Role>
            {
                new Role
                {
                    Name = "Admin"
                },
                new Role
                {
                    Name = "User"
                },
                new Role
                {
                    Name = "Manager"
                }
            };

            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var store = new RoleStore(applicationDatabaseConfiguration);

            var entities = await store.GetRoles();

            if (entities.Count == 0)
            {
                foreach (var role in roles)
                {
                    await store.Insert(role);
                }
            }
        }
        public async void SetLockoutEndDateAsync_GivenAUserAndLockoutDate_LockoutDateIsSet()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = false,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };
            await userStore.CreateAsync(user);

            await userStore.SetLockoutEndDateAsync(user, Convert.ToDateTime("01/01/2014"));

            var lockoutDate = await userStore.GetLockoutEndDateAsync(user);

            lockoutDate.Should().Be(Convert.ToDateTime("01/01/2014"));
        }
Esempio n. 10
0
        public async void SetLockoutEnabledAsync_GivenAUserAndATrueFlag_LockoutEnabledIsSetToTrue()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = false,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };
            await userStore.CreateAsync(user);

            await userStore.SetLockoutEnabledAsync(user, true);

            var isLockedOut  = await userStore.GetLockoutEnabledAsync(user);

            isLockedOut.Should().BeTrue();
        }
Esempio n. 11
0
        public async void DeleteAsync_GivenAnExistingUser_UpdatesTheAccountToInActive()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var existingUser = await userStore.FindByNameAsync("UserName");
            existingUser.UserName = "HideMe";
            await userStore.UpdateAsync(existingUser);

            await userStore.DeleteAsync(existingUser);

            existingUser.IsAccountActive.Should().BeFalse();
        }
Esempio n. 12
0
        /// <summary>
        /// Remove all test data
        /// </summary>
        public static void TruncateAllTables()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            using (var sqlConnection = new SqlConnection(applicationDatabaseConfiguration.GetConnectionString()))
            {
                sqlConnection.Open();

                sqlConnection.Execute("TRUNCATE TABLE [identity].[Role]");

                sqlConnection.Execute("TRUNCATE TABLE [identity].[User]");

                sqlConnection.Execute("TRUNCATE TABLE [identity].[UserClaim]");

                sqlConnection.Execute("TRUNCATE TABLE [identity].[UserLogin]");

                sqlConnection.Execute("TRUNCATE TABLE [identity].[UserRole]");

            }
        }
Esempio n. 13
0
        public async void Users_GivenAUserStore_ReturnsAllActiveUsers()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var users = userStore.Users;
            users.Should().NotBeNullOrEmpty();
        }
Esempio n. 14
0
        public async void ResetAccessFailedCountAsync_GivenAUser_ResetsFailedCountToZero()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "[email protected]",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = false,
                AccessFailedCount = 0,
                UserName = "UserName",
                IsAccountActive = true
            };
            await userStore.CreateAsync(user);

            await userStore.IncrementAccessFailedCountAsync(user);

            await userStore.ResetAccessFailedCountAsync(user);

            var failedCount = await userStore.GetAccessFailedCountAsync(user);

            failedCount.Should().Be(0);
        }