// Copyright (c) .NET Foundation. 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.Framework.DependencyInjection; 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.AddSingleton(); services.AddEntityFramework().AddSqlServer().AddDbContext(options => options.UseSqlServer(connectionString)); 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.GetRequiredService(); } } }