Change GetService calls to GetRequiredService

GetRequiredService throws for missing services like GetService used to.
This commit is contained in:
Stephen Halter 2014-10-16 16:07:53 -07:00
parent 0df5dfd36b
commit e720edf4bd
17 changed files with 56 additions and 56 deletions

View File

@ -12,7 +12,7 @@ namespace IdentitySample.Models
{ {
public static async Task InitializeIdentityDatabaseAsync(IServiceProvider serviceProvider) public static async Task InitializeIdentityDatabaseAsync(IServiceProvider serviceProvider)
{ {
using (var db = serviceProvider.GetService<ApplicationDbContext>()) using (var db = serviceProvider.GetRequiredService<ApplicationDbContext>())
{ {
var sqlServerDataStore = db.Configuration.DataStore as SqlServerDataStore; var sqlServerDataStore = db.Configuration.DataStore as SqlServerDataStore;
if (sqlServerDataStore != null) if (sqlServerDataStore != null)
@ -36,11 +36,11 @@ namespace IdentitySample.Models
/// <returns></returns> /// <returns></returns>
private static async Task CreateAdminUser(IServiceProvider serviceProvider) private static async Task CreateAdminUser(IServiceProvider serviceProvider)
{ {
var options = serviceProvider.GetService<IOptions<IdentityDbContextOptions>>().Options; var options = serviceProvider.GetRequiredService<IOptions<IdentityDbContextOptions>>().Options;
const string adminRole = "Administrator"; const string adminRole = "Administrator";
var userManager = serviceProvider.GetService<UserManager<ApplicationUser>>(); var userManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
var roleManager = serviceProvider.GetService<RoleManager<IdentityRole>>(); var roleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
if (!await roleManager.RoleExistsAsync(adminRole)) if (!await roleManager.RoleExistsAsync(adminRole))
{ {
await roleManager.CreateAsync(new IdentityRole(adminRole)); await roleManager.CreateAsync(new IdentityRole(adminRole));

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Identity
/// <returns></returns> /// <returns></returns>
public virtual async Task Validate(CookieValidateIdentityContext context, ClaimsIdentity identity) public virtual async Task Validate(CookieValidateIdentityContext context, ClaimsIdentity identity)
{ {
var manager = context.HttpContext.RequestServices.GetService<SignInManager<TUser>>(); var manager = context.HttpContext.RequestServices.GetRequiredService<SignInManager<TUser>>();
var userId = identity.GetUserId(); var userId = identity.GetUserId();
var user = await manager.ValidateSecurityStampAsync(identity, userId); var user = await manager.ValidateSecurityStampAsync(identity, userId);
if (user != null) if (user != null)

View File

@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
options.Password.RequireUppercase = false; options.Password.RequireUppercase = false;
options.User.UserNameValidationRegex = null; options.User.UserNameValidationRegex = null;
}); });
return services.BuildServiceProvider().GetService<UserManager<IdentityUser>>(); return services.BuildServiceProvider().GetRequiredService<UserManager<IdentityUser>>();
} }
protected override RoleManager<IdentityRole> CreateRoleManager(object context) protected override RoleManager<IdentityRole> CreateRoleManager(object context)
@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
services.Add(OptionsServices.GetDefaultServices()); services.Add(OptionsServices.GetDefaultServices());
services.AddEntityFramework().AddInMemoryStore(); services.AddEntityFramework().AddInMemoryStore();
services.AddIdentityInMemory((InMemoryContext)context); services.AddIdentityInMemory((InMemoryContext)context);
return services.BuildServiceProvider().GetService<RoleManager<IdentityRole>>(); return services.BuildServiceProvider().GetRequiredService<RoleManager<IdentityRole>>();
} }
} }
} }

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
var store = new RoleStore<IdentityRole>(new InMemoryContext()); var store = new RoleStore<IdentityRole>(new InMemoryContext());
services.AddIdentity().AddRoleStore(store); services.AddIdentity().AddRoleStore(store);
var provider = services.BuildServiceProvider(); var provider = services.BuildServiceProvider();
var manager = provider.GetService<RoleManager<IdentityRole>>(); var manager = provider.GetRequiredService<RoleManager<IdentityRole>>();
Assert.NotNull(manager); Assert.NotNull(manager);
IdentityResultAssert.IsSuccess(await manager.CreateAsync(new IdentityRole("arole"))); IdentityResultAssert.IsSuccess(await manager.CreateAsync(new IdentityRole("arole")));
} }
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
services.AddTransient<IRoleValidator<IdentityRole>, RoleValidator<IdentityRole>>(); services.AddTransient<IRoleValidator<IdentityRole>, RoleValidator<IdentityRole>>();
services.AddSingleton<RoleManager<IdentityRole>>(); services.AddSingleton<RoleManager<IdentityRole>>();
var provider = services.BuildServiceProvider(); var provider = services.BuildServiceProvider();
var manager = provider.GetService<RoleManager<IdentityRole>>(); var manager = provider.GetRequiredService<RoleManager<IdentityRole>>();
Assert.NotNull(manager); Assert.NotNull(manager);
IdentityResultAssert.IsSuccess(await manager.CreateAsync(new IdentityRole("someRole"))); IdentityResultAssert.IsSuccess(await manager.CreateAsync(new IdentityRole("someRole")));
} }

View File

@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
{ {
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddIdentity().AddRoleStore(new RoleStore<IdentityRole>(context)); services.AddIdentity().AddRoleStore(new RoleStore<IdentityRole>(context));
return services.BuildServiceProvider().GetService<RoleManager<IdentityRole>>(); return services.BuildServiceProvider().GetRequiredService<RoleManager<IdentityRole>>();
} }
public static RoleManager<IdentityRole> CreateRoleManager() public static RoleManager<IdentityRole> CreateRoleManager()

View File

@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
public static TContext Create<TContext>(string connectionString) where TContext : DbContext, new() public static TContext Create<TContext>(string connectionString) where TContext : DbContext, new()
{ {
var serviceProvider = ConfigureDbServices<TContext>(connectionString).BuildServiceProvider(); var serviceProvider = ConfigureDbServices<TContext>(connectionString).BuildServiceProvider();
return serviceProvider.GetService<TContext>(); return serviceProvider.GetRequiredService<TContext>();
} }
} }

View File

@ -54,8 +54,8 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
services.AddDefaultIdentity<IdentityDbContext, IdentityUser, IdentityRole>(); services.AddDefaultIdentity<IdentityDbContext, IdentityUser, IdentityRole>();
}); });
var userStore = builder.ApplicationServices.GetService<IUserStore<IdentityUser>>(); var userStore = builder.ApplicationServices.GetRequiredService<IUserStore<IdentityUser>>();
var userManager = builder.ApplicationServices.GetService<UserManager<IdentityUser>>(); var userManager = builder.ApplicationServices.GetRequiredService<UserManager<IdentityUser>>();
Assert.NotNull(userStore); Assert.NotNull(userStore);
Assert.NotNull(userManager); Assert.NotNull(userManager);

View File

@ -76,7 +76,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
context = CreateTestContext(); context = CreateTestContext();
} }
services.AddIdentity<TUser, TRole>().AddRoleStore(new RoleStore<TRole, TestDbContext, TKey>((TestDbContext)context)); services.AddIdentity<TUser, TRole>().AddRoleStore(new RoleStore<TRole, TestDbContext, TKey>((TestDbContext)context));
return services.BuildServiceProvider().GetService<RoleManager<TRole>>(); return services.BuildServiceProvider().GetRequiredService<RoleManager<TRole>>();
} }
public void EnsureDatabase() public void EnsureDatabase()
@ -96,8 +96,8 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
services.AddIdentityEntityFramework<TestDbContext, TUser, TRole, TKey>(); services.AddIdentityEntityFramework<TestDbContext, TUser, TRole, TKey>();
}); });
var userStore = builder.ApplicationServices.GetService<IUserStore<TUser>>(); var userStore = builder.ApplicationServices.GetRequiredService<IUserStore<TUser>>();
var userManager = builder.ApplicationServices.GetService<UserManager<TUser>>(); var userManager = builder.ApplicationServices.GetRequiredService<UserManager<TUser>>();
Assert.NotNull(userStore); Assert.NotNull(userStore);
Assert.NotNull(userManager); Assert.NotNull(userManager);
@ -130,8 +130,8 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
}); });
}); });
var userStore = builder.ApplicationServices.GetService<IUserStore<TUser>>(); var userStore = builder.ApplicationServices.GetRequiredService<IUserStore<TUser>>();
var userManager = builder.ApplicationServices.GetService<UserManager<TUser>>(); var userManager = builder.ApplicationServices.GetRequiredService<UserManager<TUser>>();
Assert.NotNull(userStore); Assert.NotNull(userStore);
Assert.NotNull(userManager); Assert.NotNull(userManager);

View File

@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
} }
var services = DbUtil.ConfigureDbServices(ConnectionString); var services = DbUtil.ConfigureDbServices(ConnectionString);
services.AddIdentity<GuidUser, GuidRole>().AddRoleStore(new ApplicationRoleStore((TestDbContext)context)); services.AddIdentity<GuidUser, GuidRole>().AddRoleStore(new ApplicationRoleStore((TestDbContext)context));
return services.BuildServiceProvider().GetService<RoleManager<GuidRole>>(); return services.BuildServiceProvider().GetRequiredService<RoleManager<GuidRole>>();
} }
} }
} }

View File

@ -56,8 +56,8 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
services.AddDefaultIdentity<ApplicationDbContext, ApplicationUser, IdentityRole>(); services.AddDefaultIdentity<ApplicationDbContext, ApplicationUser, IdentityRole>();
}); });
var userStore = builder.ApplicationServices.GetService<IUserStore<ApplicationUser>>(); var userStore = builder.ApplicationServices.GetRequiredService<IUserStore<ApplicationUser>>();
var userManager = builder.ApplicationServices.GetService<UserManager<ApplicationUser>>(); var userManager = builder.ApplicationServices.GetRequiredService<UserManager<ApplicationUser>>();
Assert.NotNull(userStore); Assert.NotNull(userStore);
Assert.NotNull(userManager); Assert.NotNull(userManager);
@ -92,8 +92,8 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
}); });
}); });
var userStore = builder.ApplicationServices.GetService<IUserStore<ApplicationUser>>(); var userStore = builder.ApplicationServices.GetRequiredService<IUserStore<ApplicationUser>>();
var userManager = builder.ApplicationServices.GetService<UserManager<ApplicationUser>>(); var userManager = builder.ApplicationServices.GetRequiredService<UserManager<ApplicationUser>>();
Assert.NotNull(userStore); Assert.NotNull(userStore);
Assert.NotNull(userManager); Assert.NotNull(userManager);
@ -164,7 +164,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
{ {
var services = DbUtil.ConfigureDbServices(ConnectionString); var services = DbUtil.ConfigureDbServices(ConnectionString);
services.AddIdentity().AddRoleStore(new RoleStore<IdentityRole>(context)); services.AddIdentity().AddRoleStore(new RoleStore<IdentityRole>(context));
return services.BuildServiceProvider().GetService<RoleManager<IdentityRole>>(); return services.BuildServiceProvider().GetRequiredService<RoleManager<IdentityRole>>();
} }
protected override RoleManager<IdentityRole> CreateRoleManager(object context) protected override RoleManager<IdentityRole> CreateRoleManager(object context)

View File

@ -45,8 +45,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
UserName = "Yolo" UserName = "Yolo"
}; };
const string password = "Yol0Sw@g!"; const string password = "Yol0Sw@g!";
var userManager = app.ApplicationServices.GetService<UserManager<ApplicationUser>>(); var userManager = app.ApplicationServices.GetRequiredService<UserManager<ApplicationUser>>();
var signInManager = app.ApplicationServices.GetService<SignInManager<ApplicationUser>>(); var signInManager = app.ApplicationServices.GetRequiredService<SignInManager<ApplicationUser>>();
IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password)); IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password));
var result = await signInManager.PasswordSignInAsync(user.UserName, password, isPersistent, false); var result = await signInManager.PasswordSignInAsync(user.UserName, password, isPersistent, false);

View File

@ -29,14 +29,14 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
options.Password.RequireUppercase = false; options.Password.RequireUppercase = false;
options.User.UserNameValidationRegex = null; options.User.UserNameValidationRegex = null;
}); });
return services.BuildServiceProvider().GetService<UserManager<IdentityUser>>(); return services.BuildServiceProvider().GetRequiredService<UserManager<IdentityUser>>();
} }
protected override RoleManager<IdentityRole> CreateRoleManager(object context) protected override RoleManager<IdentityRole> CreateRoleManager(object context)
{ {
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddIdentity().AddInMemory(); services.AddIdentity().AddInMemory();
return services.BuildServiceProvider().GetService<RoleManager<IdentityRole>>(); return services.BuildServiceProvider().GetRequiredService<RoleManager<IdentityRole>>();
} }
} }
} }

View File

@ -23,10 +23,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
builder.UseServices(services => services.AddIdentity<ApplicationUser>().AddInMemory()); builder.UseServices(services => services.AddIdentity<ApplicationUser>().AddInMemory());
var userStore = builder.ApplicationServices.GetService<IUserStore<ApplicationUser>>(); var userStore = builder.ApplicationServices.GetRequiredService<IUserStore<ApplicationUser>>();
var roleStore = builder.ApplicationServices.GetService<IRoleStore<IdentityRole>>(); var roleStore = builder.ApplicationServices.GetRequiredService<IRoleStore<IdentityRole>>();
var userManager = builder.ApplicationServices.GetService<UserManager<ApplicationUser>>(); var userManager = builder.ApplicationServices.GetRequiredService<UserManager<ApplicationUser>>();
var roleManager = builder.ApplicationServices.GetService<RoleManager<IdentityRole>>(); var roleManager = builder.ApplicationServices.GetRequiredService<RoleManager<IdentityRole>>();
Assert.NotNull(userStore); Assert.NotNull(userStore);
Assert.NotNull(userManager); Assert.NotNull(userManager);
@ -42,20 +42,20 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
var builder = new ApplicationBuilder(new ServiceCollection().BuildServiceProvider()); var builder = new ApplicationBuilder(new ServiceCollection().BuildServiceProvider());
builder.UseServices(services => services.AddIdentity<ApplicationUser>().AddInMemory()); builder.UseServices(services => services.AddIdentity<ApplicationUser>().AddInMemory());
var userStore = builder.ApplicationServices.GetService<IUserStore<ApplicationUser>>(); var userStore = builder.ApplicationServices.GetRequiredService<IUserStore<ApplicationUser>>();
var roleStore = builder.ApplicationServices.GetService<IRoleStore<IdentityRole>>(); var roleStore = builder.ApplicationServices.GetRequiredService<IRoleStore<IdentityRole>>();
var userManager = builder.ApplicationServices.GetService<UserManager<ApplicationUser>>(); var userManager = builder.ApplicationServices.GetRequiredService<UserManager<ApplicationUser>>();
var roleManager = builder.ApplicationServices.GetService<RoleManager<IdentityRole>>(); var roleManager = builder.ApplicationServices.GetRequiredService<RoleManager<IdentityRole>>();
Assert.NotNull(userStore); Assert.NotNull(userStore);
Assert.NotNull(userManager); Assert.NotNull(userManager);
Assert.NotNull(roleStore); Assert.NotNull(roleStore);
Assert.NotNull(roleManager); Assert.NotNull(roleManager);
var userStore2 = builder.ApplicationServices.GetService<IUserStore<ApplicationUser>>(); var userStore2 = builder.ApplicationServices.GetRequiredService<IUserStore<ApplicationUser>>();
var roleStore2 = builder.ApplicationServices.GetService<IRoleStore<IdentityRole>>(); var roleStore2 = builder.ApplicationServices.GetRequiredService<IRoleStore<IdentityRole>>();
var userManager2 = builder.ApplicationServices.GetService<UserManager<ApplicationUser>>(); var userManager2 = builder.ApplicationServices.GetRequiredService<UserManager<ApplicationUser>>();
var roleManager2 = builder.ApplicationServices.GetService<RoleManager<IdentityRole>>(); var roleManager2 = builder.ApplicationServices.GetRequiredService<RoleManager<IdentityRole>>();
// Stores are singleton, managers are scoped // Stores are singleton, managers are scoped
Assert.Equal(userStore, userStore2); Assert.Equal(userStore, userStore2);
@ -70,8 +70,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
const string userName = "admin"; const string userName = "admin";
const string roleName = "Admins"; const string roleName = "Admins";
const string password = "1qaz@WSX"; const string password = "1qaz@WSX";
var userManager = serviceProvider.GetService<UserManager<ApplicationUser>>(); var userManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
var roleManager = serviceProvider.GetService<RoleManager<IdentityRole>>(); var roleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();
var user = new ApplicationUser { UserName = userName }; var user = new ApplicationUser { UserName = userName };
IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password)); IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password));

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity.Test
var services = new ServiceCollection(); var services = new ServiceCollection();
var validator = new UserValidator<IdentityUser>(); var validator = new UserValidator<IdentityUser>();
services.AddIdentity<IdentityUser>().AddUserValidator(validator); services.AddIdentity<IdentityUser>().AddUserValidator(validator);
Assert.Equal(validator, services.BuildServiceProvider().GetService<IUserValidator<IdentityUser>>()); Assert.Equal(validator, services.BuildServiceProvider().GetRequiredService<IUserValidator<IdentityUser>>());
} }
[Fact] [Fact]
@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Identity.Test
var services = new ServiceCollection(); var services = new ServiceCollection();
var validator = new PasswordValidator<IdentityUser>(); var validator = new PasswordValidator<IdentityUser>();
services.AddIdentity<IdentityUser>().AddPasswordValidator(validator); services.AddIdentity<IdentityUser>().AddPasswordValidator(validator);
Assert.Equal(validator, services.BuildServiceProvider().GetService<IPasswordValidator<IdentityUser>>()); Assert.Equal(validator, services.BuildServiceProvider().GetRequiredService<IPasswordValidator<IdentityUser>>());
} }
[Fact] [Fact]
@ -41,13 +41,13 @@ namespace Microsoft.AspNet.Identity.Test
services.AddIdentity<IdentityUser>(); services.AddIdentity<IdentityUser>();
var provider = services.BuildServiceProvider(); var provider = services.BuildServiceProvider();
var userValidator = provider.GetService<IUserValidator<IdentityUser>>() as UserValidator<IdentityUser>; var userValidator = provider.GetRequiredService<IUserValidator<IdentityUser>>() as UserValidator<IdentityUser>;
Assert.NotNull(userValidator); Assert.NotNull(userValidator);
var pwdValidator = provider.GetService<IPasswordValidator<IdentityUser>>() as PasswordValidator<IdentityUser>; var pwdValidator = provider.GetRequiredService<IPasswordValidator<IdentityUser>>() as PasswordValidator<IdentityUser>;
Assert.NotNull(pwdValidator); Assert.NotNull(pwdValidator);
var hasher = provider.GetService<IPasswordHasher<IdentityUser>>() as PasswordHasher<IdentityUser>; var hasher = provider.GetRequiredService<IPasswordHasher<IdentityUser>>() as PasswordHasher<IdentityUser>;
Assert.NotNull(hasher); Assert.NotNull(hasher);
} }
@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Identity.Test
{ {
var services = new ServiceCollection(); var services = new ServiceCollection();
services.AddIdentity<IdentityUser>().AddInstance(instance); services.AddIdentity<IdentityUser>().AddInstance(instance);
Assert.Equal(instance, services.BuildServiceProvider().GetService<TService>()); Assert.Equal(instance, services.BuildServiceProvider().GetRequiredService<TService>());
} }
} }

View File

@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Identity.Test
var services = new ServiceCollection {OptionsServices.GetDefaultServices()}; var services = new ServiceCollection {OptionsServices.GetDefaultServices()};
services.AddIdentity(config.GetSubKey("identity")); services.AddIdentity(config.GetSubKey("identity"));
var accessor = services.BuildServiceProvider().GetService<IOptions<IdentityOptions>>(); var accessor = services.BuildServiceProvider().GetRequiredService<IOptions<IdentityOptions>>();
Assert.NotNull(accessor); Assert.NotNull(accessor);
var options = accessor.Options; var options = accessor.Options;
Assert.Equal(roleClaimType, options.ClaimsIdentity.RoleClaimType); Assert.Equal(roleClaimType, options.ClaimsIdentity.RoleClaimType);
@ -96,7 +96,7 @@ namespace Microsoft.AspNet.Identity.Test
var services = new ServiceCollection { OptionsServices.GetDefaultServices() }; var services = new ServiceCollection { OptionsServices.GetDefaultServices() };
services.AddIdentity(config.GetSubKey("identity"), services.AddIdentity(config.GetSubKey("identity"),
o => { o.User.RequireUniqueEmail = false; o.Lockout.MaxFailedAccessAttempts++; }); o => { o.User.RequireUniqueEmail = false; o.Lockout.MaxFailedAccessAttempts++; });
var accessor = services.BuildServiceProvider().GetService<IOptions<IdentityOptions>>(); var accessor = services.BuildServiceProvider().GetRequiredService<IOptions<IdentityOptions>>();
Assert.NotNull(accessor); Assert.NotNull(accessor);
var options = accessor.Options; var options = accessor.Options;
Assert.False(options.User.RequireUniqueEmail); Assert.False(options.User.RequireUniqueEmail);
@ -120,9 +120,9 @@ namespace Microsoft.AspNet.Identity.Test
services.ConfigureOptions<PasswordsNegativeLengthSetup>(); services.ConfigureOptions<PasswordsNegativeLengthSetup>();
}); });
var setup = builder.ApplicationServices.GetService<IConfigureOptions<IdentityOptions>>(); var setup = builder.ApplicationServices.GetRequiredService<IConfigureOptions<IdentityOptions>>();
Assert.IsType(typeof(PasswordsNegativeLengthSetup), setup); Assert.IsType(typeof(PasswordsNegativeLengthSetup), setup);
var optionsGetter = builder.ApplicationServices.GetService<IOptions<IdentityOptions>>(); var optionsGetter = builder.ApplicationServices.GetRequiredService<IOptions<IdentityOptions>>();
Assert.NotNull(optionsGetter); Assert.NotNull(optionsGetter);
var myOptions = optionsGetter.Options; var myOptions = optionsGetter.Options;
Assert.True(myOptions.Password.RequireLowercase); Assert.True(myOptions.Password.RequireLowercase);
@ -141,7 +141,7 @@ namespace Microsoft.AspNet.Identity.Test
services.AddIdentity<IdentityUser>().ConfigureIdentity(options => options.User.RequireUniqueEmail = true); services.AddIdentity<IdentityUser>().ConfigureIdentity(options => options.User.RequireUniqueEmail = true);
}); });
var optionsGetter = app.ApplicationServices.GetService<IOptions<IdentityOptions>>(); var optionsGetter = app.ApplicationServices.GetRequiredService<IOptions<IdentityOptions>>();
Assert.NotNull(optionsGetter); Assert.NotNull(optionsGetter);
var myOptions = optionsGetter.Options; var myOptions = optionsGetter.Options;

View File

@ -53,8 +53,8 @@ namespace Microsoft.AspNet.Identity.Test
// UserName = "Yolo" // UserName = "Yolo"
// }; // };
// const string password = "Yol0Sw@g!"; // const string password = "Yol0Sw@g!";
// var userManager = app.ApplicationServices.GetService<ApplicationUserManager>(); // var userManager = app.ApplicationServices.GetRequiredService<ApplicationUserManager>();
// var HttpSignInManager = app.ApplicationServices.GetService<ApplicationHttpSignInManager>(); // var HttpSignInManager = app.ApplicationServices.GetRequiredService<ApplicationHttpSignInManager>();
// IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password)); // IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password));
// var result = await HttpSignInManager.PasswordSignInAsync(user.UserName, password, isPersistent, false); // var result = await HttpSignInManager.PasswordSignInAsync(user.UserName, password, isPersistent, false);

View File

@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Identity.Test
services.Add(OptionsServices.GetDefaultServices()); services.Add(OptionsServices.GetDefaultServices());
services.AddTransient<IUserStore<TestUser>, NoopUserStore>(); services.AddTransient<IUserStore<TestUser>, NoopUserStore>();
services.AddTransient<TestManager>(); services.AddTransient<TestManager>();
var manager = services.BuildServiceProvider().GetService<TestManager>(); var manager = services.BuildServiceProvider().GetRequiredService<TestManager>();
Assert.NotNull(manager.PasswordHasher); Assert.NotNull(manager.PasswordHasher);
Assert.NotNull(manager.PasswordValidator); Assert.NotNull(manager.PasswordValidator);
Assert.NotNull(manager.UserValidator); Assert.NotNull(manager.UserValidator);