public static UserManager <ApplicationUser> CreateUserManager(IUserStore <ApplicationUser> store = null) { store = store ?? new Mock <IUserStore <ApplicationUser> >().Object; var options = new Mock <IOptions <IdentityOptions> >(); var idOptions = new IdentityOptions(); idOptions.Lockout.AllowedForNewUsers = false; options.Setup(o => o.Value).Returns(idOptions); var userValidators = new List <IUserValidator <ApplicationUser> >(); var validator = new Mock <IUserValidator <ApplicationUser> >(); userValidators.Add(validator.Object); var pwdValidators = new List <PasswordValidator <ApplicationUser> >(); pwdValidators.Add(new PasswordValidator <ApplicationUser>()); var userManager = new UserManagerStub(store, options.Object, new PasswordHasher <ApplicationUser>(), userValidators, pwdValidators, new UpperInvariantLookupNormalizer(), new IdentityErrorDescriber(), null, new Mock <ILogger <UserManager <ApplicationUser> > >().Object); validator.Setup(v => v.ValidateAsync(userManager, It.IsAny <ApplicationUser>())) .Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); return(userManager); }
public async Task CreateUserAsync_NoOtherUsers_RoleDependsOnOtherUsers_OkAsync( bool hasAnyOtherUser, Role roleOfCreatedUser) { var stub = new UserManagerStub( IdentityResult.Success, IdentityResult.Success, (user, role) => { Assert.Equal(roleOfCreatedUser.ToString(), role); }, IdentityResult.Success); var emailDomainValidatorService = new EmailDomainValidatorService("example.com"); var target = new UserIdentityServiceStub(stub, emailDomainValidatorService, hasAnyOtherUser); IdentityServer.Database.Models.User createdUser = await target.CreateUserAsync(ClaimsUser()); Assert.Equal(UserExampleEmail, createdUser.Email); Assert.Equal(UserExampleEmail, createdUser.UserName); Assert.Equal(ExampleFirstName, createdUser.FirstName); Assert.Equal(ExampleLastName, createdUser.LastName); Assert.True(createdUser.EmailConfirmed); }