Reacting to DI changes
This commit is contained in:
parent
b0480e874f
commit
c907762882
|
|
@ -17,13 +17,13 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
|
|||
|
||||
protected override void AddUserStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddInstance<IUserStore<IdentityUser>>(new UserStore<IdentityUser>((InMemoryContext)context));
|
||||
services.AddSingleton<IUserStore<IdentityUser>>(new UserStore<IdentityUser>((InMemoryContext)context));
|
||||
}
|
||||
|
||||
protected override void AddRoleStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
var store = new RoleStore<IdentityRole, InMemoryContext>((InMemoryContext)context);
|
||||
services.AddInstance<IRoleStore<IdentityRole>>(store);
|
||||
services.AddSingleton<IRoleStore<IdentityRole>>(store);
|
||||
}
|
||||
|
||||
protected override IdentityUser CreateTestUser(string namePrefix = "", string email = "", string phoneNumber = "",
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
|
|||
public static RoleManager<IdentityRole> CreateRoleManager(InMemoryContext context)
|
||||
{
|
||||
var services = CreateTestServices();
|
||||
services.AddInstance<IRoleStore<IdentityRole>>(new RoleStore<IdentityRole>(context));
|
||||
services.AddSingleton<IRoleStore<IdentityRole>>(new RoleStore<IdentityRole>(context));
|
||||
return services.BuildServiceProvider().GetRequiredService<RoleManager<IdentityRole>>();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,12 +93,12 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
|||
|
||||
protected override void AddUserStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddInstance<IUserStore<TUser>>(new UserStore<TUser, TRole, TestDbContext, TKey>((TestDbContext)context));
|
||||
services.AddSingleton<IUserStore<TUser>>(new UserStore<TUser, TRole, TestDbContext, TKey>((TestDbContext)context));
|
||||
}
|
||||
|
||||
protected override void AddRoleStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddInstance<IRoleStore<TRole>>(new RoleStore<TRole, TestDbContext, TKey>((TestDbContext)context));
|
||||
services.AddSingleton<IRoleStore<TRole>>(new RoleStore<TRole, TestDbContext, TKey>((TestDbContext)context));
|
||||
}
|
||||
|
||||
protected override void SetUserPasswordHash(TUser user, string hashedPassword)
|
||||
|
|
|
|||
|
|
@ -50,12 +50,12 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
|||
|
||||
protected override void AddUserStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddInstance<IUserStore<GuidUser>>(new ApplicationUserStore((TestDbContext)context));
|
||||
services.AddSingleton<IUserStore<GuidUser>>(new ApplicationUserStore((TestDbContext)context));
|
||||
}
|
||||
|
||||
protected override void AddRoleStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddInstance<IRoleStore<GuidRole>>(new ApplicationRoleStore((TestDbContext)context));
|
||||
services.AddSingleton<IRoleStore<GuidRole>>(new ApplicationRoleStore((TestDbContext)context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -85,12 +85,12 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
|||
|
||||
protected override void AddUserStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddInstance<IUserStore<IdentityUser>>(new UserStore<IdentityUser, IdentityRole, IdentityDbContext>((IdentityDbContext)context));
|
||||
services.AddSingleton<IUserStore<IdentityUser>>(new UserStore<IdentityUser, IdentityRole, IdentityDbContext>((IdentityDbContext)context));
|
||||
}
|
||||
|
||||
protected override void AddRoleStore(IServiceCollection services, object context = null)
|
||||
{
|
||||
services.AddInstance<IRoleStore<IdentityRole>>(new RoleStore<IdentityRole, IdentityDbContext>((IdentityDbContext)context));
|
||||
services.AddSingleton<IRoleStore<IdentityRole>>(new RoleStore<IdentityRole, IdentityDbContext>((IdentityDbContext)context));
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test
|
|||
contextAccessor.Setup(a => a.HttpContext).Returns(context.Object);
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
services.AddInstance(contextAccessor.Object);
|
||||
services.AddSingleton(contextAccessor.Object);
|
||||
services.AddIdentity<TestUser, TestRole>();
|
||||
services.AddSingleton<IUserStore<TestUser>, InMemoryUserStore<TestUser>>();
|
||||
services.AddSingleton<IRoleStore<TestRole>, InMemoryRoleStore<TestRole>>();
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
signInManager.Setup(s => s.ValidateSecurityStampAsync(It.IsAny<ClaimsPrincipal>(), user.Id)).ReturnsAsync(user).Verifiable();
|
||||
signInManager.Setup(s => s.CreateUserPrincipalAsync(user)).ReturnsAsync(principal).Verifiable();
|
||||
var services = new ServiceCollection();
|
||||
services.AddInstance(options.Object);
|
||||
services.AddInstance(signInManager.Object);
|
||||
services.AddInstance<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
||||
services.AddSingleton(options.Object);
|
||||
services.AddSingleton(signInManager.Object);
|
||||
services.AddSingleton<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
||||
httpContext.Setup(c => c.RequestServices).Returns(services.BuildServiceProvider());
|
||||
|
||||
var ticket = new AuthenticationTicket(principal,
|
||||
|
|
@ -89,9 +89,9 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
contextAccessor.Object, claimsManager.Object, options.Object, null);
|
||||
signInManager.Setup(s => s.ValidateSecurityStampAsync(It.IsAny<ClaimsPrincipal>(), user.Id)).ReturnsAsync(null).Verifiable();
|
||||
var services = new ServiceCollection();
|
||||
services.AddInstance(options.Object);
|
||||
services.AddInstance(signInManager.Object);
|
||||
services.AddInstance<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
||||
services.AddSingleton(options.Object);
|
||||
services.AddSingleton(signInManager.Object);
|
||||
services.AddSingleton<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
||||
httpContext.Setup(c => c.RequestServices).Returns(services.BuildServiceProvider());
|
||||
var id = new ClaimsIdentity(identityOptions.Cookies.ApplicationCookieAuthenticationScheme);
|
||||
id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));
|
||||
|
|
@ -124,9 +124,9 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
contextAccessor.Object, claimsManager.Object, options.Object, null);
|
||||
signInManager.Setup(s => s.ValidateSecurityStampAsync(It.IsAny<ClaimsPrincipal>(), user.Id)).ReturnsAsync(null).Verifiable();
|
||||
var services = new ServiceCollection();
|
||||
services.AddInstance(options.Object);
|
||||
services.AddInstance(signInManager.Object);
|
||||
services.AddInstance<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
||||
services.AddSingleton(options.Object);
|
||||
services.AddSingleton(signInManager.Object);
|
||||
services.AddSingleton<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
||||
httpContext.Setup(c => c.RequestServices).Returns(services.BuildServiceProvider());
|
||||
var id = new ClaimsIdentity(identityOptions.Cookies.ApplicationCookieAuthenticationScheme);
|
||||
id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));
|
||||
|
|
@ -160,9 +160,9 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
signInManager.Setup(s => s.ValidateSecurityStampAsync(It.IsAny<ClaimsPrincipal>(), user.Id)).Throws(new Exception("Shouldn't be called"));
|
||||
signInManager.Setup(s => s.SignInAsync(user, false, null)).Throws(new Exception("Shouldn't be called"));
|
||||
var services = new ServiceCollection();
|
||||
services.AddInstance(options.Object);
|
||||
services.AddInstance(signInManager.Object);
|
||||
services.AddInstance<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
||||
services.AddSingleton(options.Object);
|
||||
services.AddSingleton(signInManager.Object);
|
||||
services.AddSingleton<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
||||
httpContext.Setup(c => c.RequestServices).Returns(services.BuildServiceProvider());
|
||||
var id = new ClaimsIdentity(identityOptions.Cookies.ApplicationCookieAuthenticationScheme);
|
||||
id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
// contextAccessor.Setup(a => a.Value).Returns(context);
|
||||
// app.UseServices(services =>
|
||||
// {
|
||||
// services.AddInstance(contextAccessor.Object);
|
||||
// services.AddInstance<Ilogger>(new Nulllogger());
|
||||
// services.AddSingleton(contextAccessor.Object);
|
||||
// services.AddSingleton<Ilogger>(new Nulllogger());
|
||||
// services.AddIdentity<ApplicationUser, IdentityRole>(s =>
|
||||
// {
|
||||
// s.AddUserStore(() => new InMemoryUserStore<ApplicationUser>());
|
||||
|
|
|
|||
|
|
@ -1413,8 +1413,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
var services = new ServiceCollection();
|
||||
var store = new Mock<IUserEmailStore<TestUser>>();
|
||||
var describer = new TestErrorDescriber();
|
||||
services.AddInstance<IdentityErrorDescriber>(describer)
|
||||
.AddInstance<IUserStore<TestUser>>(store.Object)
|
||||
services.AddSingleton<IdentityErrorDescriber>(describer)
|
||||
.AddSingleton<IUserStore<TestUser>>(store.Object)
|
||||
.AddIdentity<TestUser, TestRole>();
|
||||
services.AddLogging();
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ namespace Microsoft.AspNet.Identity.Test
|
|||
AddUserStore(services, context);
|
||||
AddRoleStore(services, context);
|
||||
services.AddLogging();
|
||||
services.AddInstance<ILogger<UserManager<TUser>>>(new TestLogger<UserManager<TUser>>());
|
||||
services.AddInstance<ILogger<RoleManager<TRole>>>(new TestLogger<RoleManager<TRole>>());
|
||||
services.AddSingleton<ILogger<UserManager<TUser>>>(new TestLogger<UserManager<TUser>>());
|
||||
services.AddSingleton<ILogger<RoleManager<TRole>>>(new TestLogger<RoleManager<TRole>>());
|
||||
}
|
||||
|
||||
protected virtual UserManager<TUser> CreateManager(object context = null, IServiceCollection services = null, Action<IServiceCollection> configureServices = null)
|
||||
|
|
|
|||
Loading…
Reference in New Issue