diff --git a/src/AspNetCore.Identity.MongoDbCore.nuspec b/src/AspNetCore.Identity.MongoDbCore.nuspec index 73f1da2..b8633a4 100644 --- a/src/AspNetCore.Identity.MongoDbCore.nuspec +++ b/src/AspNetCore.Identity.MongoDbCore.nuspec @@ -2,7 +2,7 @@ AspNetCore.Identity.MongoDbCore - 1.0.4 + 1.0.5 AspNetCore.Identity.MongoDbCore Alexandre Spieser Alexandre Spieser @@ -10,7 +10,7 @@ https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore false A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0. - Target both netstandard2.0 and netcoreapp2 + Added .AddMongoDbStores IdentityBuilder extensions. Copyright 2017 (c) Alexandre Spieser. All rights reserved. aspnetcore mongo mongodb identity membership diff --git a/src/Extensions/ClaimHolderExtensions.cs b/src/Extensions/ClaimHolderExtensions.cs index 9decc35..ea890d6 100644 --- a/src/Extensions/ClaimHolderExtensions.cs +++ b/src/Extensions/ClaimHolderExtensions.cs @@ -12,6 +12,11 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions /// public static class ClaimHolderExtensions { + /// + /// Creates a object from a + /// + /// The . + /// A . public static MongoClaim ToMongoClaim(this Claim claim) { return new MongoClaim @@ -22,9 +27,14 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions }; } - public static Claim ToClaim(this MongoClaim claim) + /// + /// Creates a object from a + /// + /// A . + /// A . + public static Claim ToClaim(this MongoClaim mongoClaim) { - return new Claim(claim.Type, claim.Value, null, claim.Issuer); + return new Claim(mongoClaim.Type, mongoClaim.Value, null, mongoClaim.Issuer); } /// @@ -85,6 +95,12 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions return claimHolder.Claims.Any(e => e.Value == claim.Value && e.Type == claim.Type); } + /// + /// Removes a from the . + /// + /// The holder of the claim. + /// The to remove. + /// True is the claim was successfully removed. public static bool RemoveClaim(this IClaimHolder claimHolder, Claim claim) { if (claim == null) @@ -102,6 +118,12 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions return false; } + /// + /// Removes an IEnumerable of s from the . + /// + /// The holder of the claims. + /// The s to remove. + /// True is the claims were successfully removed. public static bool RemoveClaims(this IClaimHolder claimHolder, IEnumerable claims) { var someClaimsRemoved = false; diff --git a/src/Extensions/MongoDbIdentityBuilderExtensions.cs b/src/Extensions/MongoDbIdentityBuilderExtensions.cs new file mode 100644 index 0000000..342c359 --- /dev/null +++ b/src/Extensions/MongoDbIdentityBuilderExtensions.cs @@ -0,0 +1,160 @@ +// 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.Reflection; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection.Extensions; +using MongoDbGenericRepository; +using AspNetCore.Identity.MongoDbCore; +using AspNetCore.Identity.MongoDbCore.Models; +using AspNetCore.Identity.MongoDbCore.Infrastructure; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Contains extension methods to for adding MongoDb stores. + /// + public static class MongoDbIdentityBuilderExtensions + { + /// + /// Adds an MongoDb implementation of identity information stores. + /// + /// The MongoDb database context to use. + /// The instance this method extends. + /// A mongoDbContext + /// The instance this method extends. + public static IdentityBuilder AddMongoDbStores(this IdentityBuilder builder, IMongoDbContext mongoDbContext) + where TContext : IMongoDbContext + { + if(mongoDbContext == null) + { + throw new ArgumentNullException(nameof(mongoDbContext)); + } + + builder.Services.TryAddSingleton(mongoDbContext); + builder.Services.TryAddSingleton(new MongoRepository(mongoDbContext)); + + AddStores(builder.Services, builder.UserType, builder.RoleType, typeof(TContext)); + return builder; + } + + /// + /// Adds an MongoDb implementation of identity information stores. + /// + /// The type representing a user. + /// The type representing a role. + /// The type of the primary key of the identity document. + /// The instance this method extends. + /// + /// + public static IdentityBuilder AddMongoDbStores(this IdentityBuilder builder, string connectionString, string databaseName) + where TUser : MongoIdentityUser, new() + where TRole : MongoIdentityRole, new() + where TKey : IEquatable + { + if (string.IsNullOrEmpty(connectionString)) + { + throw new ArgumentNullException(nameof(connectionString)); + } + + if (string.IsNullOrEmpty(databaseName)) + { + throw new ArgumentNullException(nameof(databaseName)); + } + builder.Services.TryAddSingleton(new MongoDbSettings + { + ConnectionString = connectionString, + DatabaseName = databaseName + }); + builder.AddMongoDbStores(new MongoDbContext(connectionString, databaseName)); + return builder; + } + + /// + /// Adds an MongoDb implementation of identity information stores. + /// + /// The type representing a user. + /// The type representing a role. + /// The type of the primary key of the identity document. + /// The instance this method extends. + /// + public static IdentityBuilder AddMongoDbStores(this IdentityBuilder builder, IMongoDbContext mongoDbContext) + where TUser : MongoIdentityUser, new() + where TRole : MongoIdentityRole, new() + where TKey : IEquatable + { + if (mongoDbContext == null) + { + throw new ArgumentNullException(nameof(mongoDbContext)); + } + + builder.Services.TryAddSingleton(mongoDbContext); + builder.Services.TryAddSingleton(new MongoRepository(mongoDbContext)); + builder.Services.TryAddScoped>(provider => + { + return new MongoUserStore(provider.GetService()); + }); + + builder.Services.TryAddScoped>(provider => + { + return new MongoRoleStore(provider.GetService()); + }); + return builder; + } + + private static void AddStores(IServiceCollection services, Type userType, Type roleType, Type contextType) + { + var identityUserType = FindGenericBaseType(userType, typeof(MongoIdentityUser<>)); + if (identityUserType == null) + { + throw new InvalidOperationException(Resources.NotIdentityUser); + } + + var keyType = identityUserType.GenericTypeArguments[0]; + + if (roleType != null) + { + var identityRoleType = FindGenericBaseType(roleType, typeof(MongoIdentityRole<>)); + if (identityRoleType == null) + { + throw new InvalidOperationException(Resources.NotIdentityRole); + } + + Type userStoreType = null; + Type roleStoreType = null; + + // If its a custom DbContext, we can only add the default POCOs + userStoreType = typeof(MongoUserStore<,,,>).MakeGenericType(userType, roleType, contextType, keyType); + roleStoreType = typeof(MongoRoleStore<,,>).MakeGenericType(roleType, contextType, keyType); + + services.TryAddSingleton(typeof(IUserStore<>).MakeGenericType(userType), userStoreType); + services.TryAddSingleton(typeof(IRoleStore<>).MakeGenericType(roleType), roleStoreType); + } + else + { // No Roles + Type userStoreType = null; + // If its a custom DbContext, we can only add the default POCOs + userStoreType = typeof(MongoUserStore<,,,>).MakeGenericType(userType, roleType, contextType, keyType); + services.TryAddSingleton(typeof(IUserStore<>).MakeGenericType(userType), userStoreType); + } + + } + + private static TypeInfo FindGenericBaseType(Type currentType, Type genericBaseType) + { + var type = currentType; + while (type != null) + { + var typeInfo = type.GetTypeInfo(); + var genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null; + if (genericType != null && genericType == genericBaseType) + { + return typeInfo; + } + type = type.BaseType; + } + return null; + } + } +} \ No newline at end of file diff --git a/src/Extensions/ServiceCollectionExtension.cs b/src/Extensions/ServiceCollectionExtension.cs index 10b3a52..8c96b20 100644 --- a/src/Extensions/ServiceCollectionExtension.cs +++ b/src/Extensions/ServiceCollectionExtension.cs @@ -7,88 +7,118 @@ using System; namespace AspNetCore.Identity.MongoDbCore.Extensions { - public class MongoDbSettings - { - public string ConnectionString { get; set; } - public string DatabaseName { get; set; } - } - - public class MongoDbIdentityConfiguration - { - public MongoDbSettings MongoDbSettings { get; set; } - public Action IdentityOptionsAction { get; set; } - } - + /// + /// Contains extension methods to for adding mongoDb Identity. + /// public static class ServiceCollectionExtension { - public static void ConfigureMongoDbIdentity( - this IServiceCollection services, - MongoDbIdentityConfiguration mongoDbIdentityConfiguration, - IMongoRepository mongoRepository = null) + /// + /// Configures the MongoDb Identity store adapters for the types of TUser only from . + /// + /// The type representing a user. + /// The type of the primary key of the identity document. + /// The collection of service descriptors. + /// A configuration object of the AspNetCore.Identity.MongoDbCore package. + public static void ConfigureMongoDbIdentityUserOnly( + this IServiceCollection services, + MongoDbIdentityConfiguration mongoDbIdentityConfiguration) where TUser : MongoIdentityUser, new() where TKey : IEquatable { - services.AddSingleton(mongoDbIdentityConfiguration.MongoDbSettings); - services.AddSingleton(provider => - { - var options = provider.GetService(); - return mongoRepository ?? new MongoRepository(options.ConnectionString, options.DatabaseName); - }); - + ValidateMongoDbSettings(mongoDbIdentityConfiguration.MongoDbSettings); CommonMongoDbSetup, TKey>(services, mongoDbIdentityConfiguration); } + + /// + /// Configures the MongoDb Identity store adapters for the types of TUser only inheriting from . + /// + /// The type representing a user. + /// The collection of service descriptors. + /// A configuration object of the AspNetCore.Identity.MongoDbCore package. public static void ConfigureMongoDbIdentity(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration) where TUser : MongoIdentityUser, new() { - services.AddSingleton(mongoDbIdentityConfiguration.MongoDbSettings); - services.AddSingleton(provider => - { - var options = provider.GetService(); - return new MongoRepository(options.ConnectionString, options.DatabaseName); - }); - + ValidateMongoDbSettings(mongoDbIdentityConfiguration.MongoDbSettings); CommonMongoDbSetup(services, mongoDbIdentityConfiguration); } + /// + /// Validates the MongoDbSettings + /// + /// + private static void ValidateMongoDbSettings(MongoDbSettings mongoDbSettings) + { + if (mongoDbSettings == null) + { + throw new ArgumentNullException(nameof(mongoDbSettings)); + } + if (string.IsNullOrEmpty(mongoDbSettings.ConnectionString)) + { + throw new ArgumentNullException(nameof(mongoDbSettings.ConnectionString)); + } + + if (string.IsNullOrEmpty(mongoDbSettings.DatabaseName)) + { + throw new ArgumentNullException(nameof(mongoDbSettings.DatabaseName)); + } + } + + /// + /// Configures the MongoDb Identity store adapters for the types of TUser and TRole. + /// + /// The type representing a user. + /// The type representing a role. + /// The type of the primary key of the identity document. + /// The collection of service descriptors. + /// A configuration object of the AspNetCore.Identity.MongoDbCore package. + /// An object representing a MongoDb connection. public static void ConfigureMongoDbIdentity(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration, IMongoDbContext mongoDbContext = null) where TUser : MongoIdentityUser, new() where TRole : MongoIdentityRole, new() where TKey : IEquatable { - services.AddSingleton(mongoDbIdentityConfiguration.MongoDbSettings); - services.AddSingleton(provider => - { - var options = provider.GetService(); - return mongoDbContext == null ? new MongoRepository(options.ConnectionString, options.DatabaseName) : new MongoRepository(mongoDbContext); - }); + ValidateMongoDbSettings(mongoDbIdentityConfiguration.MongoDbSettings); - CommonMongoDbSetup(services, mongoDbIdentityConfiguration); + if(mongoDbContext == null) + { + services.AddIdentity() + .AddMongoDbStores( + mongoDbIdentityConfiguration.MongoDbSettings.ConnectionString, + mongoDbIdentityConfiguration.MongoDbSettings.DatabaseName) + .AddDefaultTokenProviders(); + } + else + { + services.AddIdentity() + .AddMongoDbStores(mongoDbContext) + .AddDefaultTokenProviders(); + } + + if (mongoDbIdentityConfiguration.IdentityOptionsAction != null) + { + services.Configure(mongoDbIdentityConfiguration.IdentityOptionsAction); + } } + private static void CommonMongoDbSetup(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration) where TUser : MongoIdentityUser, new() where TRole : MongoIdentityRole, new() where TKey : IEquatable { - services.AddScoped>(provider => - { - var userStore = new MongoUserStore(provider.GetService().Context); - return userStore; - }); - - services.AddScoped>(provider => - { - return new MongoRoleStore(provider.GetService().Context); - }); - services.AddIdentity() + .AddMongoDbStores( + mongoDbIdentityConfiguration.MongoDbSettings.ConnectionString, + mongoDbIdentityConfiguration.MongoDbSettings.DatabaseName) .AddDefaultTokenProviders(); - services.Configure(mongoDbIdentityConfiguration.IdentityOptionsAction); + if (mongoDbIdentityConfiguration.IdentityOptionsAction != null) + { + services.Configure(mongoDbIdentityConfiguration.IdentityOptionsAction); + } } - } } diff --git a/src/GlobalVariables.cs b/src/GlobalVariables.cs index 83f619d..0d91c46 100644 --- a/src/GlobalVariables.cs +++ b/src/GlobalVariables.cs @@ -2,8 +2,14 @@ namespace AspNetCore.Identity.MongoDbCore { + /// + /// A class holding global variables. + /// public static class GlobalVariables { + /// + /// A random number generator. + /// public static Random Random = new Random(); } } diff --git a/src/Infrastructure/MongoDbIdentityConfigurationcs.cs b/src/Infrastructure/MongoDbIdentityConfigurationcs.cs new file mode 100644 index 0000000..1d6803e --- /dev/null +++ b/src/Infrastructure/MongoDbIdentityConfigurationcs.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Identity; +using System; + +namespace AspNetCore.Identity.MongoDbCore.Infrastructure +{ + /// + /// A class used to perform a full configuration of the AspNetCore.Identity.MongoDbCore package. + /// + public class MongoDbIdentityConfiguration + { + /// + /// The settings for the MongoDb server. + /// + public MongoDbSettings MongoDbSettings { get; set; } + /// + /// An action against an to change the default identity settings. + /// + public Action IdentityOptionsAction { get; set; } + } +} diff --git a/src/Infrastructure/MongoDbSettings.cs b/src/Infrastructure/MongoDbSettings.cs new file mode 100644 index 0000000..3330db6 --- /dev/null +++ b/src/Infrastructure/MongoDbSettings.cs @@ -0,0 +1,17 @@ +namespace AspNetCore.Identity.MongoDbCore.Infrastructure +{ + /// + /// A class representing the settings for the MongoDb server. + /// + public class MongoDbSettings + { + /// + /// The connection string for the MongoDb server. + /// + public string ConnectionString { get; set; } + /// + /// The name of the MongoDb database where the identity data will be stored. + /// + public string DatabaseName { get; set; } + } +} diff --git a/src/Infrastructure/MongoRepository.cs b/src/Infrastructure/MongoRepository.cs index a510851..f9481a0 100644 --- a/src/Infrastructure/MongoRepository.cs +++ b/src/Infrastructure/MongoRepository.cs @@ -2,34 +2,74 @@ namespace AspNetCore.Identity.MongoDbCore.Infrastructure { + /// + /// The repository used in the MongoDb identity stores. + /// public interface IMongoRepository : IBaseMongoRepository { + /// + /// Drops a collections. + /// + /// The type of the document used to define the collection name. void DropCollection(); + + /// + /// Drops a partitioned collection. + /// + /// The type of the document used to define the collection name. + /// The partition key of the collection. void DropCollection(string partitionKey); + + /// + /// The MongoDb context. + /// IMongoDbContext Context { get; } } - + /// + /// The repository used in the MongoDb identity stores. + /// public class MongoRepository : BaseMongoRepository, IMongoRepository { + /// + /// The constructor for requiring a connection string and a database name. + /// + /// The connection string. + /// The database name. public MongoRepository(string connectionString, string databaseName) : base(connectionString, databaseName) { } + /// + /// The constructor for requiring a . + /// + /// A . public MongoRepository(IMongoDbContext mongoDbContext) : base(mongoDbContext) { } + /// + /// Drops a collections. + /// + /// The type of the document used to define the collection name. public void DropCollection() { MongoDbContext.DropCollection(); } + /// + /// Drops a partitioned collection. + /// + /// The type of the document used to define the collection name. + /// The partition key of the collection. public void DropCollection(string partitionKey) { MongoDbContext.DropCollection(partitionKey); } + /// + /// The MongoDb context. + /// public IMongoDbContext Context => MongoDbContext; } } diff --git a/src/Interfaces/IClaimHolder.cs b/src/Interfaces/IClaimHolder.cs index dce1f8e..134a8a7 100644 --- a/src/Interfaces/IClaimHolder.cs +++ b/src/Interfaces/IClaimHolder.cs @@ -8,6 +8,9 @@ namespace AspNetCore.Identity.MongoDbCore.Interfaces /// public interface IClaimHolder { + /// + /// The claims the has. + /// List Claims { get; set; } } } diff --git a/src/Models/MongoClaim.cs b/src/Models/MongoClaim.cs new file mode 100644 index 0000000..245b306 --- /dev/null +++ b/src/Models/MongoClaim.cs @@ -0,0 +1,21 @@ +namespace AspNetCore.Identity.MongoDbCore.Models +{ + /// + /// A class representing the claims a can have. + /// + public class MongoClaim + { + /// + /// The type of the claim. + /// + public string Type { get; set; } + /// + /// The value of the claim. + /// + public string Value { get; set; } + /// + /// The issuer of the claim. + /// + public string Issuer { get; set; } + } +} diff --git a/src/Models/MongoIdentityRole.cs b/src/Models/MongoIdentityRole.cs index 380c160..9769bfc 100644 --- a/src/Models/MongoIdentityRole.cs +++ b/src/Models/MongoIdentityRole.cs @@ -3,32 +3,55 @@ using Microsoft.AspNetCore.Identity; using MongoDbGenericRepository.Models; using System; using System.Collections.Generic; -using System.Security.Claims; namespace AspNetCore.Identity.MongoDbCore.Models { + /// + /// A where TKey is a + /// public class MongoDbIdentityRole : MongoIdentityRole { + /// + /// The constructor for a + /// public MongoDbIdentityRole() : base() { } + /// + /// The constructor for a , taking a role name. + /// + /// The name of the role. public MongoDbIdentityRole(string roleName) : base(roleName) { } } + /// + /// A where TKey is a + /// public class MongoIdentityRole : MongoIdentityRole { + /// + /// The constructor for a + /// public MongoIdentityRole() : base() { } + /// + /// The constructor for a , taking a role name. + /// + /// The name of the role. public MongoIdentityRole(string roleName) : base(roleName) { } } + /// + /// A document representing an document. + /// + /// The type of the primary key. public class MongoIdentityRole : IdentityRole, IDocument, IClaimHolder where TKey : IEquatable { @@ -53,17 +76,29 @@ namespace AspNetCore.Identity.MongoDbCore.Models } } + /// + /// The constructor for a + /// public MongoIdentityRole() { InitializeFields(); } + /// + /// The constructor for a , taking a role name. + /// + /// The name of the role. public MongoIdentityRole(string roleName) { Name = roleName; InitializeFields(); } + /// + /// The constructor for a , taking a role name and a primary key value. + /// + /// The name of the role. + /// The value of the primary key public MongoIdentityRole(string name, TKey key) { InitializeFields(); diff --git a/src/Models/MongoIdentityUser.cs b/src/Models/MongoIdentityUser.cs index 2490875..4043eac 100644 --- a/src/Models/MongoIdentityUser.cs +++ b/src/Models/MongoIdentityUser.cs @@ -8,58 +8,62 @@ using Microsoft.AspNetCore.Identity; namespace AspNetCore.Identity.MongoDbCore.Models { - public class Token - { - /// - /// Gets or sets the LoginProvider this token is from. - /// - public string LoginProvider { get; set; } - /// - /// Gets or sets the name of the token. - public string Name { get; set; } - /// - /// Gets or sets the token value. - /// - public string Value { get; set; } - } - - public class MongoClaim { - public string Type { get; set; } - public string Value { get; set; } - public string Issuer { get; set; } - } - - public class UserRole - { - public object UserId { get; set; } - public object RoleId { get; set; } - } + /// + /// A where TKey is a + /// public class MongoDbIdentityUser : MongoIdentityUser { + /// + /// The constructor for a + /// public MongoDbIdentityUser() : base() { } + /// + /// The constructor for a , taking a username. + /// + /// The name of the user. public MongoDbIdentityUser(string userName) : base(userName) { } + /// + /// The constructor for a , taking a username and an email address. + /// + /// The name of the user. + /// The email address of the user. public MongoDbIdentityUser(string userName, string email) : base(userName, email) { } } + /// + /// A where TKey is a + /// public class MongoIdentityUser : MongoIdentityUser { + /// + /// The constructor for a + /// public MongoIdentityUser() : base() { } + /// + /// The constructor for a , taking a username. + /// + /// The name of the user. public MongoIdentityUser(string userName) : base(userName) { } + /// + /// The constructor for a , taking a username and an email address. + /// + /// The name of the user. + /// The email address of the user. public MongoIdentityUser(string userName, string email) : base(userName, email) { } diff --git a/src/Models/Token.cs b/src/Models/Token.cs new file mode 100644 index 0000000..729981c --- /dev/null +++ b/src/Models/Token.cs @@ -0,0 +1,20 @@ +namespace AspNetCore.Identity.MongoDbCore.Models +{ + /// + /// A class representing the tokens a can have. + /// + public class Token + { + /// + /// Gets or sets the LoginProvider this token is from. + /// + public string LoginProvider { get; set; } + /// + /// Gets or sets the name of the token. + public string Name { get; set; } + /// + /// Gets or sets the token value. + /// + public string Value { get; set; } + } +} diff --git a/src/MongoIdentityServiceCollectionExensions.cs b/src/MongoIdentityServiceCollectionExensions.cs deleted file mode 100644 index 1690382..0000000 --- a/src/MongoIdentityServiceCollectionExensions.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Options; -using Microsoft.AspNetCore.Identity; - -namespace AspNetCore.Identity.MongoDbCore -{ - /// - /// Represents the password hashing options - /// - public sealed class PasswordHasherOptionsAccessor : IOptions - { - /// - /// Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations - /// (roughly 200ms of work) - /// - public PasswordHasherOptions Value { get; } = new PasswordHasherOptions - { - CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3, - IterationCount = 200000 - }; - } - - public static class MongoIdentityServiceCollectionExtensions - { - public static IdentityBuilder AddIdentity(this IServiceCollection services) - where TUser : class => services.AddIdentity(null); - - public static IdentityBuilder AddIdentity(this IServiceCollection services, Action setupAction) - where TUser : class - { - // Hosting doesn't add IHttpContextAccessor by default - services.TryAddSingleton(); - - // Identity services - services.TryAddScoped, UserValidator>(); - services.TryAddScoped, PasswordValidator>(); - - services.TryAddScoped, PasswordHasher>(); - services.TryAddScoped(); - - // No interface for the error describer so we can add errors without rev'ing the interface - services.TryAddScoped(); - services.TryAddScoped>(); - services.TryAddScoped, UserClaimsPrincipalFactory>(); - services.TryAddScoped, AspNetUserManager>(); - services.TryAddScoped, SignInManager>(); - - if (setupAction != null) - { - services.Configure(setupAction); - } - - return new IdentityBuilder(typeof(TUser), services); - } - } -} diff --git a/src/MongoUserOnlyStore.cs b/src/MongoUserOnlyStore.cs index f235cc2..6f0ef23 100644 --- a/src/MongoUserOnlyStore.cs +++ b/src/MongoUserOnlyStore.cs @@ -24,9 +24,9 @@ namespace AspNetCore.Identity.MongoDbCore where TUser : MongoIdentityUser, new() { /// - /// Constructs a new instance of . + /// Constructs a new instance of . /// - /// The . + /// The . /// The . public MongoUserOnlyStore(IMongoDbContext context, IdentityErrorDescriber describer = null) : base(context, describer) { } } @@ -41,9 +41,9 @@ namespace AspNetCore.Identity.MongoDbCore where TContext : IMongoDbContext { /// - /// Constructs a new instance of . + /// Constructs a new instance of . /// - /// The . + /// The . /// The . public MongoUserOnlyStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { } } @@ -60,9 +60,9 @@ namespace AspNetCore.Identity.MongoDbCore where TKey : IEquatable { /// - /// Constructs a new instance of . + /// Constructs a new instance of . /// - /// The . + /// The . /// The . public MongoUserOnlyStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { } } @@ -74,10 +74,8 @@ namespace AspNetCore.Identity.MongoDbCore /// The type of the data context class used to access the store. /// The type of the primary key for a role. /// The type representing a claim. - /// The type representing a user role. /// The type representing a user external login. /// The type representing a user token. - /// The type representing a role claim. public class MongoUserOnlyStore : UserStoreBase, IUserAuthenticationTokenStore @@ -543,10 +541,6 @@ namespace AspNetCore.Identity.MongoDbCore #region Token Management - public class TokenProjection - { - public List Tokens { get; set; } - } /// /// Find a user token if it exists. /// diff --git a/src/PasswordHasherOptionsAccessor.cs b/src/PasswordHasherOptionsAccessor.cs new file mode 100644 index 0000000..26fd35f --- /dev/null +++ b/src/PasswordHasherOptionsAccessor.cs @@ -0,0 +1,21 @@ +using Microsoft.Extensions.Options; +using Microsoft.AspNetCore.Identity; + +namespace AspNetCore.Identity.MongoDbCore +{ + /// + /// Represents the password hashing options + /// + public sealed class PasswordHasherOptionsAccessor : IOptions + { + /// + /// Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations + /// (roughly 200ms of work) + /// + public PasswordHasherOptions Value { get; } = new PasswordHasherOptions + { + CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3, + IterationCount = 200000 + }; + } +} \ No newline at end of file diff --git a/src/Resources.Designer.cs b/src/Resources.Designer.cs index c31033d..9b276df 100644 --- a/src/Resources.Designer.cs +++ b/src/Resources.Designer.cs @@ -61,7 +61,7 @@ namespace AspNetCore.Identity.MongoDbCore { } /// - /// Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.. + /// Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>.. /// internal static string NotIdentityRole { get { @@ -70,7 +70,7 @@ namespace AspNetCore.Identity.MongoDbCore { } /// - /// Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.. + /// Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.. /// internal static string NotIdentityUser { get { diff --git a/src/Resources.resx b/src/Resources.resx index eb19639..bf5a4ec 100644 --- a/src/Resources.resx +++ b/src/Resources.resx @@ -118,12 +118,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>. - error when the role does not derive from IdentityRole + AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>. + error when the role does not derive from MongoIdentityRole - AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>. - error when the user does not derive from IdentityUser + AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>. + error when the user does not derive from MongoIdentityUser Role {0} does not exist. diff --git a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.dll b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.dll index 0940ed2..ad80e86 100644 Binary files a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.dll and b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.dll differ diff --git a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.xml b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.xml index 8eea8d6..d913c2e 100644 --- a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.xml +++ b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.xml @@ -34,6 +34,53 @@ The claim you want to replace. Returns true if the claim is present, false otherwise. + + + Validates the MongoDbSettings + + + + + + Configures the MongoDb Identity store adapters for + + + + + + + + + + + A class used to perform a full configuration of the AspNetCore.Identity.MongoDbCore package. + + + + + The settings for the MongoDb server. + + + + + An action against an to change the default identity settings. + + + + + A class representing the settings for the MongoDb server. + + + + + The connection string for the MongoDb server. + + + + + The name of the MongoDb database where the identity data will be stored. + + The interface for an object that holds claims. @@ -69,17 +116,6 @@ The new claim you want to set. Returns true if the claim was replaced. - - - Represents the password hashing options - - - - - Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations - (roughly 200ms of work) - - Creates a new instance of a persistence store for roles. @@ -1335,6 +1371,17 @@ The used to propagate notifications that the operation should be canceled. True if the recovery code was found for the user. + + + Represents the password hashing options + + + + + Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations + (roughly 200ms of work) + + Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. @@ -1353,12 +1400,12 @@ - Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.. + Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>.. - Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.. + Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.. @@ -1371,5 +1418,40 @@ Recherche une chaîne localisée semblable à Value cannot be null or empty.. + + + Contains extension methods to for adding MongoDb stores. + + + + + Adds an MongoDb implementation of identity information stores. + + The MongoDb database context to use. + The instance this method extends. + A mongoDbContext + The instance this method extends. + + + + Adds an MongoDb implementation of identity information stores. + + + + + The instance this method extends. + + + + + + Adds an MongoDb implementation of identity information stores. + + + + + The instance this method extends. + + diff --git a/src/lib/netcoreapp2.0/Resources.resx b/src/lib/netcoreapp2.0/Resources.resx index eb19639..bf5a4ec 100644 --- a/src/lib/netcoreapp2.0/Resources.resx +++ b/src/lib/netcoreapp2.0/Resources.resx @@ -118,12 +118,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>. - error when the role does not derive from IdentityRole + AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>. + error when the role does not derive from MongoIdentityRole - AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>. - error when the user does not derive from IdentityUser + AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>. + error when the user does not derive from MongoIdentityUser Role {0} does not exist. diff --git a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.dll b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.dll index 0f63b71..a7de6d4 100644 Binary files a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.dll and b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.dll differ diff --git a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.xml b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.xml index 8eea8d6..d913c2e 100644 --- a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.xml +++ b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.xml @@ -34,6 +34,53 @@ The claim you want to replace. Returns true if the claim is present, false otherwise. + + + Validates the MongoDbSettings + + + + + + Configures the MongoDb Identity store adapters for + + + + + + + + + + + A class used to perform a full configuration of the AspNetCore.Identity.MongoDbCore package. + + + + + The settings for the MongoDb server. + + + + + An action against an to change the default identity settings. + + + + + A class representing the settings for the MongoDb server. + + + + + The connection string for the MongoDb server. + + + + + The name of the MongoDb database where the identity data will be stored. + + The interface for an object that holds claims. @@ -69,17 +116,6 @@ The new claim you want to set. Returns true if the claim was replaced. - - - Represents the password hashing options - - - - - Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations - (roughly 200ms of work) - - Creates a new instance of a persistence store for roles. @@ -1335,6 +1371,17 @@ The used to propagate notifications that the operation should be canceled. True if the recovery code was found for the user. + + + Represents the password hashing options + + + + + Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations + (roughly 200ms of work) + + Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées. @@ -1353,12 +1400,12 @@ - Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.. + Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>.. - Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.. + Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.. @@ -1371,5 +1418,40 @@ Recherche une chaîne localisée semblable à Value cannot be null or empty.. + + + Contains extension methods to for adding MongoDb stores. + + + + + Adds an MongoDb implementation of identity information stores. + + The MongoDb database context to use. + The instance this method extends. + A mongoDbContext + The instance this method extends. + + + + Adds an MongoDb implementation of identity information stores. + + + + + The instance this method extends. + + + + + + Adds an MongoDb implementation of identity information stores. + + + + + The instance this method extends. + + diff --git a/src/lib/netstandard2.0/Resources.resx b/src/lib/netstandard2.0/Resources.resx index eb19639..bf5a4ec 100644 --- a/src/lib/netstandard2.0/Resources.resx +++ b/src/lib/netstandard2.0/Resources.resx @@ -118,12 +118,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>. - error when the role does not derive from IdentityRole + AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>. + error when the role does not derive from MongoIdentityRole - AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>. - error when the user does not derive from IdentityUser + AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>. + error when the user does not derive from MongoIdentityUser Role {0} does not exist. diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj index 2744b09..7820f4c 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj @@ -7,7 +7,7 @@ - + diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/CustomPocoTest.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/CustomPocoTest.cs deleted file mode 100644 index 21efa8a..0000000 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/CustomPocoTest.cs +++ /dev/null @@ -1,150 +0,0 @@ -// 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.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Identity.MongoDbCore.Test -{ - //public class CustomPocoTest : IClassFixture - //{ - // private readonly MongoDatabaseFixture _fixture; - - // public CustomPocoTest(MongoDatabaseFixture fixture) - // { - // _fixture = fixture; - // } - - // public class User where TKey : IEquatable - // { - // public TKey Id { get; set; } - // public string UserName { get; set; } - // } - - // public class CustomDbContext : DbContext where TKey : IEquatable - // { - // public CustomDbContext(DbContextOptions options) : base(options) - // { } - - // public DbSet> Users { get; set; } - - // } - - // public CustomDbContext GetContext() where TKey : IEquatable - // { - // return DbUtil.Create>(_fixture.ConnectionString); - // } - - // public CustomDbContext CreateContext(bool delete = false) where TKey : IEquatable - // { - // var db = GetContext(); - // if (delete) - // { - // db.Database.EnsureDeleted(); - // } - // db.Database.EnsureCreated(); - // return db; - // } - - // [Fact] - // public async Task CanUpdateNameGuid() - // { - // using (var db = CreateContext(true)) - // { - // var oldName = Guid.NewGuid().ToString(); - // var user = new User { UserName = oldName, Id = Guid.NewGuid() }; - // db.Users.Add(user); - // await db.SaveChangesAsync(); - // var newName = Guid.NewGuid().ToString(); - // user.UserName = newName; - // await db.SaveChangesAsync(); - // Assert.Null(db.Users.SingleOrDefault(u => u.UserName == oldName)); - // Assert.Equal(user, db.Users.Single(u => u.UserName == newName)); - // } - // } - - // [Fact] - // public async Task CanUpdateNameString() - // { - // using (var db = CreateContext(true)) - // { - // var oldName = Guid.NewGuid().ToString(); - // var user = new User { UserName = oldName, Id = Guid.NewGuid().ToString() }; - // db.Users.Add(user); - // await db.SaveChangesAsync(); - // var newName = Guid.NewGuid().ToString(); - // user.UserName = newName; - // await db.SaveChangesAsync(); - // Assert.Null(db.Users.SingleOrDefault(u => u.UserName == oldName)); - // Assert.Equal(user, db.Users.Single(u => u.UserName == newName)); - // } - // } - - // [Fact] - // public async Task CanCreateUserInt() - // { - // using (var db = CreateContext(true)) - // { - // var user = new User(); - // db.Users.Add(user); - // await db.SaveChangesAsync(); - // user.UserName = "Boo"; - // await db.SaveChangesAsync(); - // var fetch = db.Users.First(u => u.UserName == "Boo"); - // Assert.Equal(user, fetch); - // } - // } - - // [Fact] - // public async Task CanCreateUserIntViaSet() - // { - // using (var db = CreateContext(true)) - // { - // var user = new User(); - // var users = db.Set>(); - // users.Add(user); - // await db.SaveChangesAsync(); - // user.UserName = "Boo"; - // await db.SaveChangesAsync(); - // var fetch = users.First(u => u.UserName == "Boo"); - // Assert.Equal(user, fetch); - // } - // } - - // [Fact] - // public async Task CanUpdateNameInt() - // { - // using (var db = CreateContext(true)) - // { - // var oldName = Guid.NewGuid().ToString(); - // var user = new User { UserName = oldName }; - // db.Users.Add(user); - // await db.SaveChangesAsync(); - // var newName = Guid.NewGuid().ToString(); - // user.UserName = newName; - // await db.SaveChangesAsync(); - // Assert.Null(db.Users.SingleOrDefault(u => u.UserName == oldName)); - // Assert.Equal(user, db.Users.Single(u => u.UserName == newName)); - // } - // } - - // [Fact] - // public async Task CanUpdateNameIntWithSet() - // { - // using (var db = CreateContext(true)) - // { - // var oldName = Guid.NewGuid().ToString(); - // var user = new User { UserName = oldName }; - // db.Set>().Add(user); - // await db.SaveChangesAsync(); - // var newName = Guid.NewGuid().ToString(); - // user.UserName = newName; - // await db.SaveChangesAsync(); - // Assert.Null(db.Set>().SingleOrDefault(u => u.UserName == oldName)); - // Assert.Equal(user, db.Set>().Single(u => u.UserName == newName)); - // } - // } - //} -} \ No newline at end of file diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/SqlStoreTestBase.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs similarity index 97% rename from test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/SqlStoreTestBase.cs rename to test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs index ec145f2..68a7918 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/SqlStoreTestBase.cs +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Data.SqlClient; using System.Linq; using System.Linq.Expressions; using System.Security.Claims; @@ -14,7 +13,6 @@ using Microsoft.Extensions.Logging; using Xunit; using AspNetCore.Identity.MongoDbCore.Models; using AspNetCore.Identity.MongoDbCore.Extensions; -using AspNetCore.Identity.MongoDbCore; using MongoDB.Driver; using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure; using MongoDbGenericRepository; @@ -24,7 +22,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test { // TODO: Add test variation with non IdentityDbContext - public abstract class SqlStoreTestBase : IdentitySpecificationTestBase, + public abstract class MongoDbStoreTestBase : IdentitySpecificationTestBase, IClassFixture> where TUser : MongoIdentityUser, new() where TRole : MongoIdentityRole, new() @@ -32,7 +30,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test { private readonly MongoDatabaseFixture _fixture; - protected SqlStoreTestBase(MongoDatabaseFixture fixture) + protected MongoDbStoreTestBase(MongoDatabaseFixture fixture) { _fixture = fixture; } diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreGuidKeyTest.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreGuidKeyTest.cs index 565f7ed..2807434 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreGuidKeyTest.cs +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreGuidKeyTest.cs @@ -3,9 +3,7 @@ using System; using Microsoft.Extensions.DependencyInjection; -using Xunit; using AspNetCore.Identity.MongoDbCore.Models; -using AspNetCore.Identity.MongoDbCore; using MongoDbGenericRepository; using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure; using Microsoft.AspNetCore.Identity; @@ -26,7 +24,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test } } - public class UserStoreGuidTest : SqlStoreTestBase + public class UserStoreGuidTest : MongoDbStoreTestBase { public UserStoreGuidTest(MongoDatabaseFixture fixture) : base(fixture) diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreIntKeyTest.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreIntKeyTest.cs index f9ba8fe..795bc09 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreIntKeyTest.cs +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreIntKeyTest.cs @@ -2,8 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.Extensions.DependencyInjection; -using Xunit; using AspNetCore.Identity.MongoDbCore.Models; namespace AspNetCore.Identity.MongoDbCore.Test @@ -23,7 +21,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test } } - public class UserStoreIntTest : SqlStoreTestBase + public class UserStoreIntTest : MongoDbStoreTestBase { public UserStoreIntTest(MongoDatabaseFixture fixture) : base(fixture) diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreStringKeyTest.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreStringKeyTest.cs index 5571bf4..d715a1b 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreStringKeyTest.cs +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreStringKeyTest.cs @@ -22,7 +22,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test } } - public class UserStoreStringKeyTest : SqlStoreTestBase + public class UserStoreStringKeyTest : MongoDbStoreTestBase { public UserStoreStringKeyTest(MongoDatabaseFixture fixture) : base(fixture) diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreWithGenericsTest.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreWithGenericsTest.cs index 3f2e2a1..f526e70 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreWithGenericsTest.cs +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreWithGenericsTest.cs @@ -222,7 +222,6 @@ namespace AspNetCore.Identity.MongoDbCore.Test { public IdentityUserWithGenerics() : base() { - } } diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/Utilities/SqlServerTestStore.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/Utilities/SqlServerTestStore.cs deleted file mode 100644 index 897f7a8..0000000 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/Utilities/SqlServerTestStore.cs +++ /dev/null @@ -1,165 +0,0 @@ -// 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.Data.Common; -using System.Data.SqlClient; -using System.IO; -using System.Threading; - -namespace AspNetCore.Identity.MongoDbCore.Test.Utilities -{ - //public class SqlServerTestStore : IDisposable - //{ - // public const int CommandTimeout = 90; - - // public static string CreateConnectionString(string name) - // { - // var connStrBuilder = new SqlConnectionStringBuilder(TestEnvironment.Config["Test:SqlServer:DefaultConnectionString"]) - // { - // InitialCatalog = name - // }; - - // return connStrBuilder.ConnectionString; - // } - - // public static SqlServerTestStore CreateScratch(bool createDatabase = true) - // => new SqlServerTestStore(GetScratchDbName()).CreateTransient(createDatabase); - - // private SqlConnection _connection; - // private readonly string _name; - // private bool _deleteDatabase; - - // private SqlServerTestStore(string name) - // { - // _name = name; - // } - - // private static string GetScratchDbName() - // { - // string name; - // do - // { - // name = "Scratch_" + Guid.NewGuid(); - // } while (DatabaseExists(name) - // || DatabaseFilesExist(name)); - - // return name; - // } - - // private static void WaitForExists(SqlConnection connection) - // { - // var retryCount = 0; - // while (true) - // { - // try - // { - // connection.Open(); - - // connection.Close(); - - // return; - // } - // catch (SqlException e) - // { - // if (++retryCount >= 30 - // || (e.Number != 233 && e.Number != -2 && e.Number != 4060)) - // { - // throw; - // } - - // SqlConnection.ClearPool(connection); - - // Thread.Sleep(100); - // } - // } - // } - - // private SqlServerTestStore CreateTransient(bool createDatabase) - // { - // _connection = new SqlConnection(CreateConnectionString(_name)); - - // if (createDatabase) - // { - // using (var master = new SqlConnection(CreateConnectionString("master"))) - // { - // master.Open(); - // using (var command = master.CreateCommand()) - // { - // command.CommandTimeout = CommandTimeout; - // command.CommandText = $"{Environment.NewLine}CREATE DATABASE [{_name}]"; - - // command.ExecuteNonQuery(); - - // WaitForExists(_connection); - // } - // } - // _connection.Open(); - // } - - // _deleteDatabase = true; - // return this; - // } - - // private static bool DatabaseExists(string name) - // { - // using (var master = new SqlConnection(CreateConnectionString("master"))) - // { - // master.Open(); - - // using (var command = master.CreateCommand()) - // { - // command.CommandTimeout = CommandTimeout; - // command.CommandText = $@"SELECT COUNT(*) FROM sys.databases WHERE name = N'{name}'"; - - // return (int) command.ExecuteScalar() > 0; - // } - // } - // } - - // private static bool DatabaseFilesExist(string name) - // { - // var userFolder = Environment.GetEnvironmentVariable("USERPROFILE") ?? - // Environment.GetEnvironmentVariable("HOME"); - // return userFolder != null - // && (File.Exists(Path.Combine(userFolder, name + ".mdf")) - // || File.Exists(Path.Combine(userFolder, name + "_log.ldf"))); - // } - - // private void DeleteDatabase(string name) - // { - // using (var master = new SqlConnection(CreateConnectionString("master"))) - // { - // master.Open(); - - // using (var command = master.CreateCommand()) - // { - // command.CommandTimeout = CommandTimeout; - // // Query will take a few seconds if (and only if) there are active connections - - // // SET SINGLE_USER will close any open connections that would prevent the drop - // command.CommandText - // = string.Format(@"IF EXISTS (SELECT * FROM sys.databases WHERE name = N'{0}') - // BEGIN - // ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; - // DROP DATABASE [{0}]; - // END", name); - - // command.ExecuteNonQuery(); - // } - // } - // } - - // public DbConnection Connection => _connection; - - // public void Dispose() - // { - // _connection.Dispose(); - - // if (_deleteDatabase) - // { - // DeleteDatabase(_name); - // } - // } - //} -}