Move away from using OptionsSetup in test

This commit is contained in:
Hao Kung 2016-01-14 14:07:31 -08:00
parent 84804fec20
commit 3a7917c566
1 changed files with 2 additions and 9 deletions

View File

@ -107,23 +107,16 @@ namespace Microsoft.AspNet.Identity.Test
Assert.Equal(1001, options.Lockout.MaxFailedAccessAttempts); Assert.Equal(1001, options.Lockout.MaxFailedAccessAttempts);
} }
public class PasswordsNegativeLengthSetup : ConfigureOptions<IdentityOptions>
{
public PasswordsNegativeLengthSetup()
: base(options => options.Password.RequiredLength = -1)
{ }
}
[Fact] [Fact]
public void CanCustomizeIdentityOptions() public void CanCustomizeIdentityOptions()
{ {
var services = new ServiceCollection() var services = new ServiceCollection()
.ConfigureOptions<PasswordsNegativeLengthSetup>(); .Configure<IdentityOptions>(options => options.Password.RequiredLength = -1);
services.AddIdentity<TestUser,TestRole>(); services.AddIdentity<TestUser,TestRole>();
var serviceProvider = services.BuildServiceProvider(); var serviceProvider = services.BuildServiceProvider();
var setup = serviceProvider.GetRequiredService<IConfigureOptions<IdentityOptions>>(); var setup = serviceProvider.GetRequiredService<IConfigureOptions<IdentityOptions>>();
Assert.IsType(typeof(PasswordsNegativeLengthSetup), setup); Assert.NotNull(setup);
var optionsGetter = serviceProvider.GetRequiredService<IOptions<IdentityOptions>>(); var optionsGetter = serviceProvider.GetRequiredService<IOptions<IdentityOptions>>();
Assert.NotNull(optionsGetter); Assert.NotNull(optionsGetter);
var myOptions = optionsGetter.Value; var myOptions = optionsGetter.Value;