Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
[2.0.1] Allow use of base identity pocos (#1385)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoK authored Aug 24, 2017
1 parent e36e681 commit b865d58
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,16 @@ private static void AddStores(IServiceCollection services, Type userType, Type r

private static TypeInfo FindGenericBaseType(Type currentType, Type genericBaseType)
{
var type = currentType.GetTypeInfo();
while (type.BaseType != null)
var type = currentType;
while (type != null)
{
type = type.BaseType.GetTypeInfo();
var typeInfo = type.GetTypeInfo();
var genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
if (genericType != null && genericType == genericBaseType)
{
return type;
return typeInfo;
}
type = type.BaseType;
}
return null;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="NotIdentityRole" xml:space="preserve">
<value>AddEntityFrameworkStores can only be called with a role that derives from IdentityRole&lt;TKey, TUserRole, TRoleClaim&gt;.</value>
<value>AddEntityFrameworkStores can only be called with a role that derives from IdentityRole&lt;TKey&gt;.</value>
<comment>error when the role does not derive from IdentityRole</comment>
</data>
<data name="NotIdentityUser" xml:space="preserve">
<value>AddEntityFrameworkStores can only be called with a user that derives from IdentityUser&lt;TKey, TUserClaim, TUserRole, TUserLogin, TUserToken&gt;.</value>
<value>AddEntityFrameworkStores can only be called with a user that derives from IdentityUser&lt;TKey&gt;.</value>
<comment>error when the user does not derive from IdentityUser</comment>
</data>
<data name="RoleNotFound" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// 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 System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder.Internal;
using Microsoft.AspNetCore.Identity.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected SqlStoreTestBase(ScratchDatabaseFixture fixture)
protected override void SetupIdentityServices(IServiceCollection services, object context)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<TestDbContext>((TestDbContext)context);
services.AddSingleton((TestDbContext)context);
services.AddLogging();
services.AddSingleton<ILogger<UserManager<TUser>>>(new TestLogger<UserManager<TUser>>());
services.AddSingleton<ILogger<RoleManager<TRole>>>(new TestLogger<RoleManager<TRole>>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,14 @@ public void AddEntityFrameworkStoresCanInferKey()
// This used to throw
var builder = services.AddIdentity<GuidUser, GuidRole>().AddEntityFrameworkStores<TestDbContext>();
}

[Fact]
public void AddEntityFrameworkStoresCanInferKeyWithGenericBase()
{
var services = new ServiceCollection();
// This used to throw
var builder = services.AddIdentity<IdentityUser<Guid>, IdentityRole<Guid>>().AddEntityFrameworkStores<TestDbContext>();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,14 @@ public void AddEntityFrameworkStoresCanInferKey()
// This used to throw
var builder = services.AddIdentity<IntUser, IntRole>().AddEntityFrameworkStores<TestDbContext>();
}

[Fact]
public void AddEntityFrameworkStoresCanInferKeyWithGenericBase()
{
var services = new ServiceCollection();
// This used to throw
var builder = services.AddIdentity<IdentityUser<int>, IdentityRole<int>>().AddEntityFrameworkStores<TestDbContext>();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,13 @@ public void AddEntityFrameworkStoresCanInferKey()
var builder = services.AddIdentity<StringUser, StringRole>().AddEntityFrameworkStores<TestDbContext>();
}

[Fact]
public void AddEntityFrameworkStoresCanInferKeyWithGenericBase()
{
var services = new ServiceCollection();
// This used to throw
var builder = services.AddIdentity<IdentityUser<string>, IdentityRole<string>>().AddEntityFrameworkStores<TestDbContext>();
}

}
}

0 comments on commit b865d58

Please sign in to comment.