public void Validate_AllCallsSucceed_ReturnsNull() { var mockVal1 = new Mock<IValidator>(); var mockVal2 = new Mock<IValidator>(); var sub = new AggregateValidator(); sub.Add(mockVal1.Object); sub.Add(mockVal2.Object); var result = sub.Validate(new MockUserAccountService().Object, new MockUserAccount().Object, "test"); Assert.IsNull(result); }
public void Validate_AllCallsSucceed_ReturnsNull() { var mockVal1 = new Mock <IValidator>(); var mockVal2 = new Mock <IValidator>(); var sub = new AggregateValidator(); sub.Add(mockVal1.Object); sub.Add(mockVal2.Object); var result = sub.Validate(new MockUserAccountService().Object, new MockUserAccount().Object, "test"); Assert.IsNull(result); }
public void Validate_AllCallsSucceed_CallsAllValidators() { var mockVal1 = new Mock<IValidator>(); var mockVal2 = new Mock<IValidator>(); var sub = new AggregateValidator(); sub.Add(mockVal1.Object); sub.Add(mockVal2.Object); var svc = new MockUserAccountService(); var ua = new MockUserAccount(); var val = "test"; var result = sub.Validate(svc.Object, ua.Object, val); mockVal1.Verify(x=>x.Validate(svc.Object, ua.Object, val)); mockVal2.Verify(x=>x.Validate(svc.Object, ua.Object, val)); }
public void Validate_AllCallsSucceed_CallsAllValidators() { var mockVal1 = new Mock <IValidator>(); var mockVal2 = new Mock <IValidator>(); var sub = new AggregateValidator(); sub.Add(mockVal1.Object); sub.Add(mockVal2.Object); var svc = new MockUserAccountService(); var ua = new MockUserAccount(); var val = "test"; var result = sub.Validate(svc.Object, ua.Object, val); mockVal1.Verify(x => x.Validate(svc.Object, ua.Object, val)); mockVal2.Verify(x => x.Validate(svc.Object, ua.Object, val)); }
public UserAccountService(MembershipRebootConfiguration configuration, IUserAccountRepository userRepository) { if (configuration == null) throw new ArgumentNullException("configuration"); if (userRepository == null) throw new ArgumentNullException("userRepository"); this.Configuration = configuration; var validationEventBus = new EventBus(); validationEventBus.Add(new UserAccountValidator(this)); this.userRepository = new EventBusUserAccountRepository(userRepository, new AggregateEventBus { validationEventBus, configuration.ValidationBus }, configuration.EventBus); this.usernameValidator = new Lazy<AggregateValidator>(()=> { var val = new AggregateValidator(); if (!this.SecuritySettings.EmailIsUsername) { val.Add(UserAccountValidation.UsernameDoesNotContainAtSign); } val.Add(UserAccountValidation.UsernameMustNotAlreadyExist); val.Add(configuration.UsernameValidator); return val; }); this.emailValidator = new Lazy<AggregateValidator>(() => { var val = new AggregateValidator(); val.Add(UserAccountValidation.EmailIsValidFormat); val.Add(UserAccountValidation.EmailMustNotAlreadyExist); val.Add(configuration.EmailValidator); return val; }); this.passwordValidator = new Lazy<AggregateValidator>(() => { var val = new AggregateValidator(); val.Add(UserAccountValidation.PasswordMustBeDifferentThanCurrent); val.Add(configuration.PasswordValidator); return val; }); }
public void Validate_GetsErrorFromItems() { var mockVal = new Mock<IValidator>(); var error = new ValidationResult("Error"); mockVal.Setup(x => x.Validate(It.IsAny<UserAccountService>(), It.IsAny<UserAccount>(), It.IsAny<string>())).Returns(error); var sub = new AggregateValidator(); sub.Add(mockVal.Object); var result = sub.Validate(new MockUserAccountService().Object, new MockUserAccount().Object, "test"); Assert.AreSame(error, result); }
public void Validate_GetsErrorFromItems() { var mockVal = new Mock <IValidator>(); var error = new ValidationResult("Error"); mockVal.Setup(x => x.Validate(It.IsAny <UserAccountService>(), It.IsAny <UserAccount>(), It.IsAny <string>())).Returns(error); var sub = new AggregateValidator(); sub.Add(mockVal.Object); var result = sub.Validate(new MockUserAccountService().Object, new MockUserAccount().Object, "test"); Assert.AreSame(error, result); }
public UserAccountManager( IUserStore <ApplicationUser> store, IOptions <IdentityOptions> optionsAccessor, IPasswordHasher <ApplicationUser> passwordHasher, IEnumerable <IUserValidator <ApplicationUser> > userValidators, IEnumerable <IPasswordValidator <ApplicationUser> > passwordValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IServiceProvider services, IUnitOfWorkAsync unitOfWork, IOptions <IdentityOptions> identityOptions, IOptions <AppSettings> settings, ILogger <UserAccountManager> logger) : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger) { _identityOptions = identityOptions.Value; _logger = logger; _settings = settings.Value; Repository = unitOfWork.RepositoryAsync <ApplicationUser>(); Settings = settings.Value.Auth; EventsHandler = new EventsHandler(); AddEventHandler(new MultiUserAccountEventsHandler(services)); var accountValidators = new UserAccountValidators(); _usernameValidator = new Lazy <AggregateValidator <ApplicationUser> >(() => { var val = new AggregateValidator <ApplicationUser>(); if (!_settings.Auth.EmailIsUsername) { val.Add(UserAccountValidation.UsernameDoesNotContainAtSign); val.Add(UserAccountValidation.UsernameCanOnlyStartOrEndWithLetterOrDigit); val.Add(UserAccountValidation.UsernameOnlyContainsValidCharacters); val.Add(UserAccountValidation.UsernameOnlySingleInstanceOfSpecialCharacters); } val.Add(UserAccountValidation.UsernameMustNotAlreadyExist); val.Add(accountValidators.UsernameValidator); return(val); }); _emailValidator = new Lazy <AggregateValidator <ApplicationUser> >(() => { var val = new AggregateValidator <ApplicationUser> { UserAccountValidation.EmailIsRequiredIfRequireAccountVerificationEnabled, UserAccountValidation.EmailIsValidFormat, UserAccountValidation.EmailMustNotAlreadyExist, accountValidators.EmailValidator }; return(val); }); _phoneNumberValidator = new Lazy <AggregateValidator <ApplicationUser> >(() => { var val = new AggregateValidator <ApplicationUser> { UserAccountValidation.PhoneNumberIsRequiredIfRequireAccountVerificationEnabled, UserAccountValidation.PhoneNumberMustNotAlreadyExist, accountValidators.PhoneNumberValidator }; return(val); }); _passwordValidator = new Lazy <AggregateValidator <ApplicationUser> >(() => { var val = new AggregateValidator <ApplicationUser> { UserAccountValidation.PasswordMustBeDifferentThanCurrent, accountValidators.PasswordValidator }; return(val); }); }
public UserAccountService(IServiceProvider serviceProvider, IUnitOfWorkAsync unitOfWork) : base(unitOfWork) { _crypto = (ICrypto)serviceProvider.GetService(typeof(ICrypto)); var settings = (IOptions <AppSettings>)serviceProvider.GetService(typeof(IOptions <AppSettings>)); _settings = settings.Value; _logger = (ILogger <UserAccountService>)serviceProvider.GetService(typeof(ILogger <UserAccountService>)); Settings = settings.Value.Auth; AddEventHandler(new EmailUserAccountEventsHandler(serviceProvider)); var accountvalidators = new UserAccountValidators(); _usernameValidator = new Lazy <AggregateValidator <UserAccount> >(() => { var val = new AggregateValidator <UserAccount>(); if (!_settings.Auth.EmailIsUsername) { val.Add(UserAccountValidation.UsernameDoesNotContainAtSign); val.Add(UserAccountValidation.UsernameCanOnlyStartOrEndWithLetterOrDigit); val.Add(UserAccountValidation.UsernameOnlyContainsValidCharacters); val.Add(UserAccountValidation.UsernameOnlySingleInstanceOfSpecialCharacters); } val.Add(UserAccountValidation.UsernameMustNotAlreadyExist); val.Add(accountvalidators.UsernameValidator); return(val); }); _emailValidator = new Lazy <AggregateValidator <UserAccount> >(() => { var val = new AggregateValidator <UserAccount> { UserAccountValidation.EmailIsRequiredIfRequireAccountVerificationEnabled, UserAccountValidation.EmailIsValidFormat, UserAccountValidation.EmailMustNotAlreadyExist, accountvalidators.EmailValidator }; return(val); }); _phoneNumberValidator = new Lazy <AggregateValidator <UserAccount> >(() => { var val = new AggregateValidator <UserAccount> { UserAccountValidation.PhoneNumberIsRequiredIfRequireAccountVerificationEnabled, UserAccountValidation.PhoneNumberMustNotAlreadyExist, accountvalidators.PhoneNumberValidator }; return(val); }); _passwordValidator = new Lazy <AggregateValidator <UserAccount> >(() => { var val = new AggregateValidator <UserAccount> { UserAccountValidation.PasswordMustBeDifferentThanCurrent, accountvalidators.PasswordValidator }; return(val); }); }