// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Hosting; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Services; 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 { [TestCaseOrderer("Microsoft.AspNet.Identity.Test.PriorityOrderer", "Microsoft.AspNet.Identity.EntityFramework.Test")] public static class DbUtil { public static IServiceCollection ConfigureDbServices(string connectionString, IServiceCollection services = null) { return ConfigureDbServices(connectionString, services); } public static IServiceCollection ConfigureDbServices(string connectionString, IServiceCollection services = null) where TContext : DbContext { if (services == null) { services = new ServiceCollection(); } services.Add(HostingServices.GetDefaultServices()); services.AddEntityFramework().AddSqlServer().AddDbContext(options => options.UseSqlServer(connectionString)); services.Add(OptionsServices.GetDefaultServices()); services.AddInstance(new NullLoggerFactory()); return services; } public static IdentityDbContext Create(string connectionString) { return Create(connectionString); } public static TContext Create(string connectionString) where TContext : DbContext, new() { var serviceProvider = ConfigureDbServices(connectionString).BuildServiceProvider(); return serviceProvider.GetService(); } } }