From 805064ed7d92db9d2913fa87867f40dbbe5dd4f4 Mon Sep 17 00:00:00 2001 From: Ilya Chudin Date: Thu, 6 Jul 2017 15:28:25 +0500 Subject: [PATCH] Stores now not abstract version 1.2.0 --- .../LinqToDB.Identity.csproj | 5 +- .../Properties/AssemblyInfo.cs | 2 +- src/LinqToDB.Identity/RoleStore.cs | 23 ++++----- src/LinqToDB.Identity/UserStore.cs | 48 +++++++++++++++---- .../ProvideConfigutayionTest.cs | 15 ++++++ 5 files changed, 66 insertions(+), 27 deletions(-) diff --git a/src/LinqToDB.Identity/LinqToDB.Identity.csproj b/src/LinqToDB.Identity/LinqToDB.Identity.csproj index eb6779336..3dad96317 100644 --- a/src/LinqToDB.Identity/LinqToDB.Identity.csproj +++ b/src/LinqToDB.Identity/LinqToDB.Identity.csproj @@ -14,15 +14,16 @@ linq2db.Identity aspnetcore;linq2db;identity;membership;LinqToDB http://www.gravatar.com/avatar/fc2e509b6ed116b9aa29a7988fdb8990?s=320 - https://github.com/ili/LinqToDB.Identity + https://github.com/linq2db/LinqToDB.Identity https://opensource.org/licenses/MIT git - git://github.com/ili/LinqToDB.Identity + git://github.com/linq2db/LinqToDB.Identity 1.6.1 false false false false + 1.2.0 diff --git a/src/LinqToDB.Identity/Properties/AssemblyInfo.cs b/src/LinqToDB.Identity/Properties/AssemblyInfo.cs index 432823c9b..bed11dd72 100644 --- a/src/LinqToDB.Identity/Properties/AssemblyInfo.cs +++ b/src/LinqToDB.Identity/Properties/AssemblyInfo.cs @@ -7,5 +7,5 @@ [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] [assembly: AssemblyCompany("blog.linq2db.com")] -[assembly: AssemblyCopyright("\xA9 2011-2016 blog.linq2db.com")] +[assembly: AssemblyCopyright("© 2011-2017 blog.linq2db.com")] [assembly: AssemblyProduct("Linq to DB")] \ No newline at end of file diff --git a/src/LinqToDB.Identity/RoleStore.cs b/src/LinqToDB.Identity/RoleStore.cs index 89cd5373b..e6c47a103 100644 --- a/src/LinqToDB.Identity/RoleStore.cs +++ b/src/LinqToDB.Identity/RoleStore.cs @@ -55,18 +55,6 @@ public RoleStore(IConnectionFactory factory, IdentityErrorDescriber describer = { } - /// - /// Creates a entity representing a role claim. - /// - /// The associated role. - /// The associated claim. - /// The role claim entity. - protected override IdentityRoleClaim CreateRoleClaim(TRole role, Claim claim) - { - var roleClaim = new IdentityRoleClaim {RoleId = role.Id}; - roleClaim.InitializeFromClaim(claim); - return roleClaim; - } } /// @@ -75,12 +63,12 @@ protected override IdentityRoleClaim CreateRoleClaim(TRole role, Claim cla /// The type of the class representing a role. /// The type of the primary key for a role. /// The type of the class representing a role claim. - public abstract class RoleStore : + public class RoleStore : IQueryableRoleStore, IRoleClaimStore where TRole : class, IIdentityRole where TKey : IEquatable - where TRoleClaim : class, IIdentityRoleClaim + where TRoleClaim : class, IIdentityRoleClaim, new() { private readonly IConnectionFactory _factory; @@ -509,6 +497,11 @@ protected void ThrowIfDisposed() /// The associated role. /// The associated claim. /// The role claim entity. - protected abstract TRoleClaim CreateRoleClaim(TRole role, Claim claim); + protected virtual TRoleClaim CreateRoleClaim(TRole role, Claim claim) + { + var roleClaim = new TRoleClaim(){ RoleId = role.Id }; + roleClaim.InitializeFromClaim(claim); + return roleClaim; + } } } \ No newline at end of file diff --git a/src/LinqToDB.Identity/UserStore.cs b/src/LinqToDB.Identity/UserStore.cs index 78cd5ec92..8a45705b8 100644 --- a/src/LinqToDB.Identity/UserStore.cs +++ b/src/LinqToDB.Identity/UserStore.cs @@ -160,7 +160,7 @@ protected override IdentityUserToken CreateUserToken(TUser user, string lo /// The type representing a user role. /// The type representing a user external login. /// The type representing a user token. - public abstract class UserStore : + public class UserStore : IUserLoginStore, IUserRoleStore, IUserClaimStore, @@ -174,10 +174,10 @@ public abstract class UserStore where TUser : class, IIdentityUser where TRole : class, IIdentityRole - where TUserClaim : class, IIdentityUserClaim - where TUserRole : class, IIdentityUserRole - where TUserLogin : class, IIdentityUserLogin - where TUserToken : class, IIdentityUserToken + where TUserClaim : class, IIdentityUserClaim, new() + where TUserRole : class, IIdentityUserRole, new() + where TUserLogin : class, IIdentityUserLogin, new() + where TUserToken : class, IIdentityUserToken, new () where TKey : IEquatable { private readonly IConnectionFactory _factory; @@ -1754,7 +1754,14 @@ public virtual Task GetTwoFactorEnabledAsync(TUser user, /// /// /// - protected abstract TUserRole CreateUserRole(TUser user, TRole role); + protected virtual TUserRole CreateUserRole(TUser user, TRole role) + { + return new TUserRole() + { + UserId = user.Id, + RoleId = role.Id + }; + } /// /// Create a new entity representing a user claim. @@ -1762,7 +1769,12 @@ public virtual Task GetTwoFactorEnabledAsync(TUser user, /// /// /// - protected abstract TUserClaim CreateUserClaim(TUser user, Claim claim); + protected virtual TUserClaim CreateUserClaim(TUser user, Claim claim) + { + var res = new TUserClaim() {UserId = user.Id}; + res.InitializeFromClaim(claim); + return res; + } /// /// Create a new entity representing a user login. @@ -1770,7 +1782,16 @@ public virtual Task GetTwoFactorEnabledAsync(TUser user, /// /// /// - protected abstract TUserLogin CreateUserLogin(TUser user, UserLoginInfo login); + protected virtual TUserLogin CreateUserLogin(TUser user, UserLoginInfo login) + { + return new TUserLogin() + { + UserId = user.Id, + LoginProvider = login.LoginProvider, + ProviderDisplayName = login.ProviderDisplayName, + ProviderKey = login.ProviderKey + }; + } /// /// Create a new entity representing a user token. @@ -1780,7 +1801,16 @@ public virtual Task GetTwoFactorEnabledAsync(TUser user, /// /// /// - protected abstract TUserToken CreateUserToken(TUser user, string loginProvider, string name, string value); + protected virtual TUserToken CreateUserToken(TUser user, string loginProvider, string name, string value) + { + return new TUserToken() + { + UserId = user.Id, + LoginProvider = loginProvider, + Name = name, + Value = value + }; + } /// /// Converts the provided to a strongly typed key object. diff --git a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/ProvideConfigutayionTest.cs b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/ProvideConfigutayionTest.cs index 4970b60cd..21dd328d3 100644 --- a/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/ProvideConfigutayionTest.cs +++ b/test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/ProvideConfigutayionTest.cs @@ -14,6 +14,11 @@ public void AddLinqToDBStores0() services .AddIdentity() .AddLinqToDBStores(new DefaultConnectionFactory()); + + var sp = services.BuildServiceProvider(); + + Assert.NotNull(sp.GetService>()); + Assert.NotNull(sp.GetService>()); } [Fact] @@ -23,6 +28,11 @@ public void AddLinqToDBStores1() services .AddIdentity, IdentityRole>() .AddLinqToDBStores(new DefaultConnectionFactory()); + + var sp = services.BuildServiceProvider(); + + Assert.NotNull(sp.GetService>>()); + Assert.NotNull(sp.GetService>>()); } [Fact] @@ -38,6 +48,11 @@ public void AddLinqToDBStores6() IdentityUserLogin, IdentityUserToken, IdentityRoleClaim>(new DefaultConnectionFactory()); + + var sp = services.BuildServiceProvider(); + + Assert.NotNull(sp.GetService>>()); + Assert.NotNull(sp.GetService>>()); } }