Add additional test assertions (#1801)
This commit is contained in:
parent
262f2403c1
commit
54c43ac2fc
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
|
||||
protected virtual void SetupAddIdentity(IServiceCollection services)
|
||||
{
|
||||
services.AddIdentity<TUser, TRole>(options =>
|
||||
services.AddIdentityCore<TUser>(options =>
|
||||
{
|
||||
options.Password.RequireDigit = false;
|
||||
options.Password.RequireLowercase = false;
|
||||
|
|
@ -41,8 +41,11 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
options.Password.RequireUppercase = false;
|
||||
options.User.AllowedUserNameCharacters = null;
|
||||
})
|
||||
.AddRoles<TRole>()
|
||||
.AddDefaultTokenProviders()
|
||||
.AddEntityFrameworkStores<TestDbContext>();
|
||||
|
||||
services.AddAuthentication(IdentityConstants.ApplicationScheme).AddIdentityCookies();
|
||||
}
|
||||
|
||||
protected override void SetupIdentityServices(IServiceCollection services, object context)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -56,17 +57,34 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
public void AddEntityFrameworkStoresCanInferKey()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging()
|
||||
.AddSingleton(new TestDbContext(new DbContextOptionsBuilder<TestDbContext>().Options));
|
||||
// This used to throw
|
||||
var builder = services.AddIdentity<GuidUser, GuidRole>().AddEntityFrameworkStores<TestDbContext>();
|
||||
|
||||
var sp = services.BuildServiceProvider();
|
||||
using (var csope = sp.CreateScope())
|
||||
{
|
||||
Assert.NotNull(sp.GetRequiredService<UserManager<GuidUser>>());
|
||||
Assert.NotNull(sp.GetRequiredService<RoleManager<GuidRole>>());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddEntityFrameworkStoresCanInferKeyWithGenericBase()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging()
|
||||
.AddSingleton(new TestDbContext(new DbContextOptionsBuilder<TestDbContext>().Options));
|
||||
// This used to throw
|
||||
var builder = services.AddIdentity<IdentityUser<Guid>, IdentityRole<Guid>>().AddEntityFrameworkStores<TestDbContext>();
|
||||
}
|
||||
var builder = services.AddIdentityCore<IdentityUser<Guid>>().AddRoles<IdentityRole<Guid>>().AddEntityFrameworkStores<TestDbContext>();
|
||||
|
||||
var sp = services.BuildServiceProvider();
|
||||
using (var csope = sp.CreateScope())
|
||||
{
|
||||
Assert.NotNull(sp.GetRequiredService<UserManager<IdentityUser<Guid>>>());
|
||||
Assert.NotNull(sp.GetRequiredService<RoleManager<IdentityRole<Guid>>>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -34,16 +35,34 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
public void AddEntityFrameworkStoresCanInferKey()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging()
|
||||
.AddSingleton(new TestDbContext(new DbContextOptionsBuilder<TestDbContext>().Options));
|
||||
// This used to throw
|
||||
var builder = services.AddIdentity<IntUser, IntRole>().AddEntityFrameworkStores<TestDbContext>();
|
||||
|
||||
var sp = services.BuildServiceProvider();
|
||||
using (var csope = sp.CreateScope())
|
||||
{
|
||||
Assert.NotNull(sp.GetRequiredService<UserManager<IntUser>>());
|
||||
Assert.NotNull(sp.GetRequiredService<RoleManager<IntRole>>());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddEntityFrameworkStoresCanInferKeyWithGenericBase()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging()
|
||||
.AddSingleton(new TestDbContext(new DbContextOptionsBuilder<TestDbContext>().Options));
|
||||
// This used to throw
|
||||
var builder = services.AddIdentity<IdentityUser<int>, IdentityRole<int>>().AddEntityFrameworkStores<TestDbContext>();
|
||||
var builder = services.AddIdentityCore<IdentityUser<int>>().AddRoles<IdentityRole<int>>().AddEntityFrameworkStores<TestDbContext>();
|
||||
|
||||
var sp = services.BuildServiceProvider();
|
||||
using (var csope = sp.CreateScope())
|
||||
{
|
||||
Assert.NotNull(sp.GetRequiredService<UserManager<IdentityUser<int>>>());
|
||||
Assert.NotNull(sp.GetRequiredService<RoleManager<IdentityRole<int>>>());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -35,16 +36,34 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
|
|||
public void AddEntityFrameworkStoresCanInferKey()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging()
|
||||
.AddSingleton(new TestDbContext(new DbContextOptionsBuilder<TestDbContext>().Options));
|
||||
// This used to throw
|
||||
var builder = services.AddIdentity<StringUser, StringRole>().AddEntityFrameworkStores<TestDbContext>();
|
||||
|
||||
var sp = services.BuildServiceProvider();
|
||||
using (var csope = sp.CreateScope())
|
||||
{
|
||||
Assert.NotNull(sp.GetRequiredService<UserManager<StringUser>>());
|
||||
Assert.NotNull(sp.GetRequiredService<RoleManager<StringRole>>());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddEntityFrameworkStoresCanInferKeyWithGenericBase()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging()
|
||||
.AddSingleton(new TestDbContext(new DbContextOptionsBuilder<TestDbContext>().Options));
|
||||
// This used to throw
|
||||
var builder = services.AddIdentity<IdentityUser<string>, IdentityRole<string>>().AddEntityFrameworkStores<TestDbContext>();
|
||||
var builder = services.AddIdentityCore<IdentityUser<string>>().AddRoles<IdentityRole<string>>().AddEntityFrameworkStores<TestDbContext>();
|
||||
|
||||
var sp = services.BuildServiceProvider();
|
||||
using (var csope = sp.CreateScope())
|
||||
{
|
||||
Assert.NotNull(sp.GetRequiredService<UserManager<IdentityUser<string>>>());
|
||||
Assert.NotNull(sp.GetRequiredService<RoleManager<IdentityRole<string>>>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue