// 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.Identity.Test; using Microsoft.Data.Entity; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.OptionsModel; using System; namespace Microsoft.AspNet.Identity.Entity.Test { public static class TestIdentityFactory { public static IdentityContext CreateContext() { var services = new ServiceCollection(); services.AddEntityFramework().AddInMemoryStore(); var serviceProvider = services.BuildServiceProvider(); var db = new IdentityContext(serviceProvider); db.Database.EnsureCreated(); return db; } public static UserManager CreateManager(IdentityContext context) { return MockHelpers.CreateManager(() => new InMemoryUserStore(context)); } public static UserManager CreateManager() { return CreateManager(CreateContext()); } public static RoleManager CreateRoleManager(IdentityContext context) { var services = new ServiceCollection(); services.Add(OptionsServices.GetDefaultServices()); services.AddIdentity(b => b.AddRoleStore(() => new EntityRoleStore(context))); return services.BuildServiceProvider().GetService>(); } public static RoleManager CreateRoleManager() { return CreateRoleManager(CreateContext()); } } }