Пример #1
1
        public async void FindByEmailAsync_GivenAnEmailAddress_ReturnsAUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = false,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "******",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var foundUser = await userStore.FindByEmailAsync("*****@*****.**");

            foundUser.Should().NotBeNull();
        }
Пример #2
0
        public async void FindAsync_GivenUserLoginInfo_ReturnsTheCorrectUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = false,
                AccessFailedCount      = 0,
                UserName               = "******",
                IsAccountActive        = true
            };

            var userLoginInfo = new UserLoginInfo("loginProvider", "providerKey");

            await userStore.CreateAsync(user);

            await userStore.AddLoginAsync(user, userLoginInfo);

            var foundUser = await userStore.FindAsync(userLoginInfo);

            foundUser.Email.Should().Be("*****@*****.**");
        }
Пример #3
0
        public async void RemoveFromRoleAsync_GivenAUserAndRole_RemovesTheUserFromTheRole()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                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);
        }
        public async void SetTwoFactorEnabledAsync_GivenAUserAndATrueFlag_TwoFactorIsEnabled()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

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

            await userStore.SetTwoFactorEnabledAsync(user, true);

            var isTwoFactorEnabled = await userStore.GetTwoFactorEnabledAsync(user);

            isTwoFactorEnabled.Should().BeTrue();
        }
Пример #5
0
        public async void CreateAsync_GivenNewUser_CreatesNewUserAndAssignsUserId()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = true,
                AccessFailedCount      = 0,
                UserName               = "******",
                IsAccountActive        = true
            };

            await userStore.CreateAsync(user);

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

            insertedUser.Should().NotBeNull();
            insertedUser.Email.Should().Be("*****@*****.**");
        }
Пример #6
0
        public async void UpdateAsync_GivenAnUpdate_UpdatesTheUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = true,
                AccessFailedCount      = 0,
                UserName               = "******",
                IsAccountActive        = true
            };

            await userStore.CreateAsync(user);

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

            existingUser.Email       = "*****@*****.**";
            existingUser.PhoneNumber = "1234";

            await userStore.UpdateAsync(existingUser);

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

            updatedUser.Should().NotBeNull();
            updatedUser.Email.Should().Be("*****@*****.**");
            updatedUser.PhoneNumber.Should().Be("1234");
        }
Пример #7
0
        public async void ResetAccessFailedCountAsync_GivenAUser_ResetsFailedCountToZero()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = false,
                AccessFailedCount      = 0,
                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);
        }
Пример #8
0
        public async void RemoveClaimAsync_GivenAUserAndClaim_RemovesTheClaim()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = true,
                AccessFailedCount      = 0,
                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);
        }
Пример #9
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 SetSecurityStampAsync_GivenAUserAndASecurityStamp_SetsTheStampForTheUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

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

            await userStore.SetSecurityStampAsync(user, "stamp");

            var stamp = await userStore.GetSecurityStampAsync(user);

            stamp.Should().Be("stamp");
        }
Пример #11
0
        public async void RemoveClaimAsync_GivenAUserAndClaim_RemovesTheClaim()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                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);
        }
Пример #12
0
        public async void Users_GivenAUserStore_ReturnsAllActiveUsers()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = true,
                AccessFailedCount      = 0,
                UserName               = "******",
                IsAccountActive        = true
            };

            await userStore.CreateAsync(user);

            var users = userStore.Users;

            users.Should().NotBeNullOrEmpty();
        }
Пример #13
0
        public async void FindByEmailAsync_GivenAnEmailAddress_ReturnsAUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = false,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = true,
                AccessFailedCount      = 0,
                UserName               = "******",
                IsAccountActive        = true
            };

            await userStore.CreateAsync(user);

            var foundUser = await userStore.FindByEmailAsync("*****@*****.**");

            foundUser.Should().NotBeNull();
        }
Пример #14
0
        public async void SetLockoutEndDateAsync_GivenAUserAndLockoutDate_LockoutDateIsSet()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = false,
                AccessFailedCount      = 0,
                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"));
        }
Пример #15
0
        public async void UpdateAsync_GivenAnUpdate_UpdatesTheUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "******",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var existingUser = await userStore.FindByNameAsync("UserName");
            existingUser.Email = "*****@*****.**";
            existingUser.PhoneNumber = "1234";

            await userStore.UpdateAsync(existingUser);

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

            updatedUser.Should().NotBeNull();
            updatedUser.Email.Should().Be("*****@*****.**");
            updatedUser.PhoneNumber.Should().Be("1234");
        }
Пример #16
0
        public async void RemoveFromRoleAsync_GivenAUserAndRole_RemovesTheUserFromTheRole()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = true,
                AccessFailedCount      = 0,
                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);
        }
Пример #17
0
        public async void SetPasswordHashAsync_GivenAUserAndPasswordHash_SetsTheHashForTheUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "******",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

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

            var passwordHash = await userStore.GetPasswordHashAsync(user);

            passwordHash.Should().Be("1234");
        }
Пример #18
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);
                }
            }
        }
Пример #19
0
        public async void SetLockoutEndDateAsync_GivenAUserAndLockoutDate_LockoutDateIsSet()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = false,
                AccessFailedCount = 0,
                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"));
        }
Пример #20
0
        public async void SetLockoutEnabledAsync_GivenAUserAndATrueFlag_LockoutEnabledIsSetToTrue()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

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

            await userStore.SetLockoutEnabledAsync(user, true);

            var isLockedOut  = await userStore.GetLockoutEnabledAsync(user);

            isLockedOut.Should().BeTrue();
        }
Пример #21
0
        public async void HasPasswordAsync_GivenAUserWithAPasswordHash_ReturnsTrue()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "******",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var hasPasswordHash = await userStore.HasPasswordAsync(user);

            hasPasswordHash.Should().BeTrue();
        }
Пример #22
0
        public async void CreateAsync_GivenNewUser_CreatesNewUserAndAssignsUserId()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "******",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

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

            insertedUser.Should().NotBeNull();
            insertedUser.Email.Should().Be("*****@*****.**");
        }
Пример #23
0
        public async void SetEmailAsync_GivenAUserAndEmail_SetTheUsersEmail()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = true,
                AccessFailedCount      = 0,
                UserName               = "******",
                IsAccountActive        = true
            };

            await userStore.CreateAsync(user);

            await userStore.SetEmailAsync(user, "*****@*****.**");

            var emailAddress = await userStore.GetEmailAsync(user);

            emailAddress.Should().Be("*****@*****.**");
        }
Пример #24
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 = "******";
            await userStore.UpdateAsync(existingUser);

            await userStore.DeleteAsync(existingUser);

            existingUser.IsAccountActive.Should().BeFalse();
        }
Пример #25
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 = "******";
            await userStore.UpdateAsync(existingUser);

            await userStore.DeleteAsync(existingUser);

            existingUser.IsAccountActive.Should().BeFalse();
        }
Пример #26
0
        public static ApplicationUserManager Create(IdentityFactoryOptions <ApplicationUserManager> options, IOwinContext context)
        {
            var manager = new ApplicationUserManager(new UserStore <ApplicationUser>(ApplicationDatabaseConfiguration.Create()));

            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator <ApplicationUser, int>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail             = true
            };

            // Configure validation logic for passwords
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength          = 6,
                RequireNonLetterOrDigit = false,
                RequireDigit            = false,
                RequireLowercase        = false,
                RequireUppercase        = false,
            };

            // Configure user lockout defaults
            manager.UserLockoutEnabledByDefault          = true;
            manager.DefaultAccountLockoutTimeSpan        = TimeSpan.FromMinutes(5);
            manager.MaxFailedAccessAttemptsBeforeLockout = 5;

            // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
            // You can write your own provider and plug it in here.
            manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider <ApplicationUser, int>
            {
                MessageFormat = "Your security code is {0}"
            });
            manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider <ApplicationUser, int>
            {
                Subject    = "Security Code",
                BodyFormat = "Your security code is {0}"
            });
            manager.EmailService = new EmailService();
            manager.SmsService   = new SmsService();
            var dataProtectionProvider = options.DataProtectionProvider;

            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser, int>(dataProtectionProvider.Create("ASP.NET Identity"));
            }
            return(manager);
        }
Пример #27
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]");

            }
        }
Пример #28
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]");
            }
        }
Пример #29
0
        public async void GetLogins_GivenAUser_ReturnsAllLoginsForUser()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore <User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email                  = "*****@*****.**",
                IsEmailConfirmed       = true,
                PasswordHash           = "PasswordHash",
                PhoneNumber            = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled     = false,
                LockoutEndDateUtc      = null,
                IsLockoutEnabled       = false,
                AccessFailedCount      = 0,
                UserName               = "******",
                IsAccountActive        = true
            };

            await userStore.CreateAsync(user);

            await userStore.AddLoginAsync(user, new UserLoginInfo("loginProvider", "providerKey"));

            await userStore.AddLoginAsync(user, new UserLoginInfo("loginProvider1", "providerKey1"));

            var userLoginInfo = new UserLoginInfo("loginProvider2", "providerKey2");

            await userStore.AddLoginAsync(user, userLoginInfo);

            await userStore.RemoveLoginAsync(user, userLoginInfo);

            var logins = await userStore.GetLoginsAsync(user);

            logins.Should().HaveCount(2);
        }
Пример #30
0
        public async void ResetAccessFailedCountAsync_GivenAUser_ResetsFailedCountToZero()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = false,
                AccessFailedCount = 0,
                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);
        }
Пример #31
0
        public async void Users_GivenAUserStore_ReturnsAllActiveUsers()
        {
            var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
            var userStore = new UserStore<User>(applicationDatabaseConfiguration);

            var user = new User
            {
                Email = "*****@*****.**",
                IsEmailConfirmed = true,
                PasswordHash = "PasswordHash",
                PhoneNumber = "PhoneNumber",
                IsPhoneNumberConfirmed = true,
                IsTwoFactorEnabled = false,
                LockoutEndDateUtc = null,
                IsLockoutEnabled = true,
                AccessFailedCount = 0,
                UserName = "******",
                IsAccountActive = true
            };

            await userStore.CreateAsync(user);

            var users = userStore.Users;
            users.Should().NotBeNullOrEmpty();
        }
        public void Create_WhenCalled_ReturnsANewApplicationDatabaseConfiguration()
        {
            var applicationDatabaseConfiguration = ApplicationDatabaseConfiguration.Create();

            applicationDatabaseConfiguration.Should().BeOfType <ApplicationDatabaseConfiguration>();
        }