示例#1
0
 public void NullServices_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () =>
     {
         IdentityServices.AddPasswords(services: null);
     });
 }
示例#2
0
 public void NullServices_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () =>
     {
         IdentityServices.AddUserStore <User, FakeUserStore>(services: null);
     });
 }
示例#3
0
 public void NullServices_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () =>
     {
         IdentityServices.AddInfrastructure(services: null);
     });
 }
示例#4
0
 public void NullServices_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () =>
     {
         IdentityServices.AddUserClaims <User>(services: null);
     });
 }
示例#5
0
 public void NullServices_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () =>
     {
         IdentityServices.AddTimedLockoutStore <FakeTimedLockoutStore>(
             services: null);
     });
 }
示例#6
0
 public void NullServices_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () =>
     {
         IdentityServices.AddSingleUseTokenService <FakeSingleUseTokenService>(
             services: null);
     });
 }
示例#7
0
 public void NullOptions_Throws()
 {
     Assert.Throws <ArgumentNullException>("options", () =>
     {
         IdentityServices.AddOptions(
             services: new ServiceCollection(),
             options: null);
     });
 }
示例#8
0
 public void NullServices_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () =>
     {
         IdentityServices.AddOptions(
             services: null,
             options: new IdentityOptions());
     });
 }
示例#9
0
 public void NullServices_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () =>
     {
         IdentityServices.AddUserValidators <User>(
             services: null,
             options: new UserOptions());
     });
 }
示例#10
0
                public void WhenCalled_AddsRetrieveOperation()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddUserEmailStore <User, FakeUserEmailStore>(services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <IRetrieveOperation <EmailAddress, User> >());
                }
示例#11
0
                public void WhenCalled_AddsSystemClock()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddInfrastructure(services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <SystemClock>());
                }
示例#12
0
                public void WhenCalled_AddsCrudStore()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddUserStore <User, FakeUserStore>(services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <ICrudStore <UserKey, User> >());
                }
示例#13
0
                public void WhenCalled_AddsUserOptions()
                {
                    var services = new ServiceCollection();
                    var options  = new IdentityOptions();

                    IdentityServices.AddOptions(services, options);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <UserOptions>());
                }
示例#14
0
                public void WhenCalled_AddsPasswordHasher()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddPasswords(services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <IPasswordHasher>());
                    Assert.True(provider.GetRequiredService <IPasswordHasher>() is Pbkdf2PasswordHasher);
                }
示例#15
0
                public void WhenCalled_AddsHttpContextAccessor()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddInfrastructure(services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <IHttpContextAccessor>());
                    Assert.True(provider.GetRequiredService <IHttpContextAccessor>() is HttpContextAccessor);
                }
示例#16
0
                public void WhenCalled_AddsSingleUseTokenService()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddTimedLockoutStore <FakeTimedLockoutStore>(
                        services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <ICrudStore <string, TimedLockout> >());
                    Assert.True(provider.GetRequiredService <ICrudStore <string, TimedLockout> >() is FakeTimedLockoutStore);
                }
示例#17
0
                public void WhenCalled_AddsSingleUseTokenService()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddSingleUseTokenService <FakeSingleUseTokenService>(
                        services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <ISingleUseTokenService>());
                    Assert.True(provider.GetRequiredService <ISingleUseTokenService>() is FakeSingleUseTokenService);
                }
示例#18
0
                public void WhenCalled_AddsMinimumLengthPasswordStrengthValidator()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddPasswords(services);

                    var provider = services.BuildServiceProvider();

                    var validators = provider.GetRequiredService <IEnumerable <IPasswordStrengthValidator> >();

                    Assert.NotNull(validators);
                    Assert.Single(validators);
                    Assert.True(validators.First() is MinimumLengthPasswordStrengthValidator);
                }
示例#19
0
                public void WhenCalled_AddsUserClaimsConverter()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddOptions(services, new IdentityOptions());
                    IdentityServices.AddInfrastructure(services);

                    // Act
                    IdentityServices.AddUserClaims <User>(services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <IUserClaimsConverter <User> >());
                    Assert.True(provider.GetRequiredService <IUserClaimsConverter <User> >() is UserClaimsConverter <User>);
                }
示例#20
0
                public void WhenCalled_AddsAuthenticationService()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddOptions(services, new IdentityOptions());
                    IdentityServices.AddInfrastructure(services);
                    IdentityServices.AddUserStore <User, FakeUserStore>(services);

                    // Act
                    IdentityServices.AddUserClaims <User>(services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <IAuthenticationService <ClaimsPrincipal> >());
                    Assert.True(provider.GetRequiredService <IAuthenticationService <ClaimsPrincipal> >() is ClaimsAuthenticationService <User>);
                }
示例#21
0
                public void RequireEmailWithBlankUser_DoesNotAddEmailValidator()
                {
                    var services = new ServiceCollection();
                    var options  = new UserOptions()
                    {
                        RequireEmail = true
                    };

                    IdentityServices.AddUserValidators <object>(services, options);

                    var provider = services.BuildServiceProvider();

                    var validators = provider.GetRequiredService <IEnumerable <IUserValidator <User> > >();

                    Assert.Empty(validators.Where(v => v is UserEmailRequiredValidator <User>));
                }
示例#22
0
                public void RequireEmailWithImplementingUser_AddsEmailValidator()
                {
                    var services = new ServiceCollection();
                    var options  = new UserOptions()
                    {
                        RequireEmail = true
                    };

                    IdentityServices.AddUserValidators <User>(services, options);

                    var provider = services.BuildServiceProvider();

                    var validators = provider.GetRequiredService <IEnumerable <IUserValidator <User> > >();

                    Assert.Single(validators.Where(v => v is UserEmailRequiredValidator <User>));
                }
示例#23
0
                public void NotRequirePasswordWithImplementingUser_DoesNotAddPasswordValidator()
                {
                    var services = new ServiceCollection();
                    var options  = new UserOptions()
                    {
                        RequirePassword = false
                    };

                    IdentityServices.AddUserValidators <User>(services, options);

                    var provider = services.BuildServiceProvider();

                    var validators = provider.GetRequiredService <IEnumerable <IUserValidator <User> > >();

                    Assert.Empty(validators.Where(v => v is UserPasswordHashRequiredValidator <User>));
                }
示例#24
0
                public void WhenCalled_AddsIUserHelper()
                {
                    var services = Services();

                    IdentityServices.AddInfrastructure(services);
                    IdentityServices.AddPasswords(services);
                    IdentityServices.AddUserEmailStore <User, FakeUserEmailStore>(services);
                    IdentityServices.AddSingleUseTokenService <FakeSingleUseTokenService>(
                        services);
                    IdentityServices.AddTimedLockoutStore <FakeTimedLockoutStore>(services);

                    // Act
                    IdentityServices.AddUserHelpers <User>(services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <IUserHelper>());
                    Assert.True(provider.GetRequiredService <IUserHelper>() is UserHelper <User>);
                }
示例#25
0
                public void NotNullServices_AddsIIdentityService()
                {
                    var services = new ServiceCollection();

                    IdentityServices.AddOptions(services, new IdentityOptions());
                    IdentityServices.AddInfrastructure(services);
                    IdentityServices.AddPasswords(services);
                    IdentityServices.AddUserHelpers <User>(services);
                    IdentityServices.AddUserValidators <User>(services, new UserOptions());
                    IdentityServices.AddSingleUseTokenService <FakeSingleUseTokenService>(
                        services);
                    IdentityServices.AddTimedLockoutStore <FakeTimedLockoutStore>(services);
                    IdentityServices.AddUserEmailStore <User, FakeUserEmailStore>(services);
                    IdentityServices.AddUserStore <User, FakeUserStore>(services);
                    IdentityServices.AddUserClaims <User>(services);

                    // Act
                    IdentityServices.AddIdentityServices <User>(services);

                    var provider = services.BuildServiceProvider();

                    Assert.NotNull(provider.GetRequiredService <IIdentityService <User> >());
                    Assert.True(provider.GetRequiredService <IIdentityService <User> >() is IdentityService <User>);
                }