React to GetDefaultServices changes

This commit is contained in:
Hao Kung 2014-11-24 13:28:26 -08:00
parent 66f9803d06
commit d4733f9238
7 changed files with 9 additions and 21 deletions

View File

@ -5,8 +5,6 @@ using Microsoft.AspNet.Hosting;
using Microsoft.Data.Entity;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel;
using Xunit;
namespace Microsoft.AspNet.Identity.EntityFramework.Test
@ -25,10 +23,8 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
{
services = new ServiceCollection();
}
services.Add(HostingServices.GetDefaultServices());
services.AddHosting();
services.AddEntityFramework().AddSqlServer().AddDbContext<TContext>(options => options.UseSqlServer(connectionString));
services.Add(OptionsServices.GetDefaultServices());
services.AddInstance<ILoggerFactory>(new LoggerFactory());
return services;
}

View File

@ -49,7 +49,6 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
builder.UseServices(services =>
{
DbUtil.ConfigureDbServices<IdentityDbContext>(ConnectionString, services);
services.Add(DataProtectionServices.GetDefaultServices());
services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<IdentityDbContext>();
});

View File

@ -54,7 +54,6 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
builder.UseServices(services =>
{
DbUtil.ConfigureDbServices<ApplicationDbContext>(ConnectionString, services);
services.Add(DataProtectionServices.GetDefaultServices());
services.AddIdentity<ApplicationUser, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>();
});
@ -79,8 +78,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
builder.UseServices(services =>
{
services.AddInstance<ILoggerFactory>(new LoggerFactory());
services.Add(HostingServices.GetDefaultServices());
services.AddHosting();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(ConnectionString));

View File

@ -67,7 +67,6 @@ namespace Microsoft.AspNet.Identity.Test
{
var services = new ServiceCollection();
services.AddIdentity();
services.Add(OptionsServices.GetDefaultServices());
var provider = services.BuildServiceProvider();
var userValidator = provider.GetRequiredService<IUserValidator<IdentityUser>>() as UserValidator<IdentityUser>;
@ -85,8 +84,6 @@ namespace Microsoft.AspNet.Identity.Test
{
var services = new ServiceCollection();
services.AddIdentity().AddDefaultTokenProviders();
services.Add(DataProtectionServices.GetDefaultServices());
services.Add(OptionsServices.GetDefaultServices());
var provider = services.BuildServiceProvider();
var tokenProviders = provider.GetRequiredService<IEnumerable<IUserTokenProvider<IdentityUser>>>();

View File

@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Identity.Test
var config = new Configuration { new MemoryConfigurationSource(dic) };
Assert.Equal(roleClaimType, config.Get("identity:claimsidentity:roleclaimtype"));
var services = new ServiceCollection {OptionsServices.GetDefaultServices()};
var services = new ServiceCollection();
if (useDefaultSubKey)
{
services.AddIdentity(config);
@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Identity.Test
{"identity:lockout:MaxFailedAccessAttempts", "1000"}
};
var config = new Configuration { new MemoryConfigurationSource(dic) };
var services = new ServiceCollection { OptionsServices.GetDefaultServices() };
var services = new ServiceCollection();
services.AddIdentity(config,
o => { o.User.RequireUniqueEmail = false; o.Lockout.MaxFailedAccessAttempts++; });
var accessor = services.BuildServiceProvider().GetRequiredService<IOptions<IdentityOptions>>();
@ -148,6 +148,7 @@ namespace Microsoft.AspNet.Identity.Test
var app = new ApplicationBuilder(CallContextServiceLocator.Locator.ServiceProvider);
app.UseServices(services =>
{
services.AddOptions();
services.ConfigureIdentity(options => options.User.RequireUniqueEmail = true);
});

View File

@ -30,10 +30,10 @@ namespace Microsoft.AspNet.Identity.Test
[Fact]
public void EnsureDefaultServicesDefaultsWithStoreWorks()
{
var services = new ServiceCollection {IdentityServices.GetDefaultServices<TestUser, IdentityRole>()};
services.Add(OptionsServices.GetDefaultServices());
services.AddTransient<IUserStore<TestUser>, NoopUserStore>();
services.AddTransient<TestManager>();
var services = new ServiceCollection()
.AddTransient<IUserStore<TestUser>, NoopUserStore>()
.AddTransient<TestManager>();
services.AddIdentity<TestUser, IdentityRole>();
var manager = services.BuildServiceProvider().GetRequiredService<TestManager>();
Assert.NotNull(manager.PasswordHasher);
Assert.NotNull(manager.PasswordValidator);

View File

@ -9,7 +9,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Testing;
using Xunit;
using Microsoft.AspNet.Security.DataProtection;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
@ -28,9 +27,7 @@ namespace Microsoft.AspNet.Identity.Test
{
protected virtual void SetupIdentityServices(IServiceCollection services, object context = null)
{
services.AddOptions();
services.AddHosting();
services.Add(DataProtectionServices.GetDefaultServices());
services.AddIdentity<TUser, TRole>().AddDefaultTokenProviders();
AddUserStore(services, context);
AddRoleStore(services, context);