diff --git a/.gitignore b/.gitignore
index 827bbf5..c85705e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -297,5 +297,9 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs
-sample/MongoIdentitySample.Mvc/appsettings.local.json
-test/AspNetCore.Identity.MongoDbCore.IntegrationTests/appsettings.local.json
+
+# Local app settings for development
+**/**/appsettings.local.json
+
+# Output from the code coverage analysis
+**/**/coverage.json
\ No newline at end of file
diff --git a/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj b/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj
index 278fafd..9f63488 100644
--- a/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj
+++ b/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj
@@ -8,20 +8,15 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -35,5 +30,10 @@
Always
+
+
+
+
+
diff --git a/sample/MongoIdentitySample.Mvc/Startup.cs b/sample/MongoIdentitySample.Mvc/Startup.cs
index cbf26a8..1c4fd58 100644
--- a/sample/MongoIdentitySample.Mvc/Startup.cs
+++ b/sample/MongoIdentitySample.Mvc/Startup.cs
@@ -1,15 +1,15 @@
-using AspNetCore.Identity.MongoDbCore.Infrastructure;
+using System;
+using AspNetCore.Identity.MongoDbCore.Infrastructure;
using AspNetCore.Identity.MongoDbCore.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
-using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
using MongoIdentitySample.Mvc.Models;
using MongoIdentitySample.Mvc.Services;
-using Microsoft.Extensions.Logging;
-using System;
namespace MongoIdentitySample.Mvc
{
@@ -24,7 +24,7 @@ namespace MongoIdentitySample.Mvc
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
//per user config that is not committed to repo, use this to override settings (e.g. connection string) based on your local environment.
- .AddJsonFile($"appsettings.local.json", optional: true);
+ .AddJsonFile($"appsettings.local.json", optional: true);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
@@ -48,16 +48,15 @@ namespace MongoIdentitySample.Mvc
var builder = services.AddRazorPages();
-
- #if DEBUG
- if(_env.IsDevelopment())
- {
- builder.AddRazorRuntimeCompilation();
- }
- #endif
+
+#if DEBUG
+ if (_env.IsDevelopment())
+ {
+ builder.AddRazorRuntimeCompilation();
+ }
+#endif
services.AddMvc();
-
services.AddApplicationInsightsTelemetry();
// Add application services.
diff --git a/sample/MongoIdentitySample.Mvc/appsettings.json b/sample/MongoIdentitySample.Mvc/appsettings.json
index 5c53f25..1e27be6 100644
--- a/sample/MongoIdentitySample.Mvc/appsettings.json
+++ b/sample/MongoIdentitySample.Mvc/appsettings.json
@@ -4,7 +4,7 @@
"DatabaseName": "MongoDbTests"
},
"Logging": {
- "IncludeScopes": false,
+ "IncludeScopes": {},
"LogLevel": {
"Default": "Warning"
}
diff --git a/src/AspNetCore.Identity.MongoDbCore.csproj b/src/AspNetCore.Identity.MongoDbCore.csproj
index 5bd3c4f..1b6e513 100644
--- a/src/AspNetCore.Identity.MongoDbCore.csproj
+++ b/src/AspNetCore.Identity.MongoDbCore.csproj
@@ -2,6 +2,8 @@
netcoreapp3.1;netstandard2.1
+ 3.1.0
+ 3.1.0
@@ -13,8 +15,9 @@
-
-
+
+
+
diff --git a/src/AspNetCore.Identity.MongoDbCore.nuspec b/src/AspNetCore.Identity.MongoDbCore.nuspec
index 7db6350..c88b0f4 100644
--- a/src/AspNetCore.Identity.MongoDbCore.nuspec
+++ b/src/AspNetCore.Identity.MongoDbCore.nuspec
@@ -2,29 +2,29 @@
AspNetCore.Identity.MongoDbCore
- 2.1.1
+ 3.1.0
AspNetCore.Identity.MongoDbCore
Alexandre Spieser
Alexandre Spieser
MIT
https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore
false
- A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.2.
+ A MongoDb UserStore and RoleStore adapter for Microsoft.Extensions.Identity.Core 3.1.
Release notes are at https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore/releases
Copyright 2020 (c) Alexandre Spieser. All rights reserved.
aspnetcore mongo mongodb identity membership
-
-
-
-
+
+
+
+
-
-
+
+
-
+
diff --git a/src/Extensions/ServiceCollectionExtension.cs b/src/Extensions/ServiceCollectionExtension.cs
index 8c96b20..3801a13 100644
--- a/src/Extensions/ServiceCollectionExtension.cs
+++ b/src/Extensions/ServiceCollectionExtension.cs
@@ -1,9 +1,10 @@
-using AspNetCore.Identity.MongoDbCore.Infrastructure;
+using System;
+using AspNetCore.Identity.MongoDbCore.Infrastructure;
using AspNetCore.Identity.MongoDbCore.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Identity.Core;
using MongoDbGenericRepository;
-using System;
namespace AspNetCore.Identity.MongoDbCore.Extensions
{
@@ -19,14 +20,15 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions
/// 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(
+ public static IdentityBuilder ConfigureMongoDbIdentityUserOnly(
this IServiceCollection services,
MongoDbIdentityConfiguration mongoDbIdentityConfiguration)
where TUser : MongoIdentityUser, new()
where TKey : IEquatable
{
ValidateMongoDbSettings(mongoDbIdentityConfiguration.MongoDbSettings);
- CommonMongoDbSetup, TKey>(services, mongoDbIdentityConfiguration);
+
+ return CommonMongoDbSetup, TKey>(services, mongoDbIdentityConfiguration);
}
@@ -36,11 +38,12 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions
/// 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)
+ public static IdentityBuilder ConfigureMongoDbIdentity(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration)
where TUser : MongoIdentityUser, new()
{
ValidateMongoDbSettings(mongoDbIdentityConfiguration.MongoDbSettings);
- CommonMongoDbSetup(services, mongoDbIdentityConfiguration);
+
+ return CommonMongoDbSetup(services, mongoDbIdentityConfiguration);
}
///
@@ -74,51 +77,60 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions
/// 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,
+ public static IdentityBuilder ConfigureMongoDbIdentity(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration,
IMongoDbContext mongoDbContext = null)
where TUser : MongoIdentityUser, new()
where TRole : MongoIdentityRole, new()
where TKey : IEquatable
{
+ IdentityBuilder builder;
+
ValidateMongoDbSettings(mongoDbIdentityConfiguration.MongoDbSettings);
- if(mongoDbContext == null)
+ if (mongoDbContext == null)
{
- services.AddIdentity()
+ builder = services.AddIdentityCore()
+ .AddRoles()
.AddMongoDbStores(
mongoDbIdentityConfiguration.MongoDbSettings.ConnectionString,
- mongoDbIdentityConfiguration.MongoDbSettings.DatabaseName)
- .AddDefaultTokenProviders();
+ mongoDbIdentityConfiguration.MongoDbSettings.DatabaseName);
}
else
{
- services.AddIdentity()
- .AddMongoDbStores(mongoDbContext)
- .AddDefaultTokenProviders();
+ builder = services.AddIdentityCore()
+ .AddRoles()
+ .AddMongoDbStores(mongoDbContext);
}
if (mongoDbIdentityConfiguration.IdentityOptionsAction != null)
{
services.Configure(mongoDbIdentityConfiguration.IdentityOptionsAction);
}
+
+ return builder;
}
- private static void CommonMongoDbSetup(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration)
+ private static IdentityBuilder CommonMongoDbSetup(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration)
where TUser : MongoIdentityUser, new()
where TRole : MongoIdentityRole, new()
where TKey : IEquatable
{
- services.AddIdentity()
+
+ IdentityBuilder builder;
+
+ builder = services.AddIdentityCore()
+ .AddRoles()
.AddMongoDbStores(
- mongoDbIdentityConfiguration.MongoDbSettings.ConnectionString,
- mongoDbIdentityConfiguration.MongoDbSettings.DatabaseName)
- .AddDefaultTokenProviders();
+ mongoDbIdentityConfiguration.MongoDbSettings.ConnectionString,
+ mongoDbIdentityConfiguration.MongoDbSettings.DatabaseName);
if (mongoDbIdentityConfiguration.IdentityOptionsAction != null)
{
services.Configure(mongoDbIdentityConfiguration.IdentityOptionsAction);
}
+
+ return builder;
}
}
}
diff --git a/src/pack.ps1 b/src/pack.ps1
new file mode 100644
index 0000000..fb84563
--- /dev/null
+++ b/src/pack.ps1
@@ -0,0 +1,6 @@
+
+Write-Output "Package AspNetCore.Identity.MongoDbCore"
+
+Remove-Item -Path "./bin/Release" -Force -Recurse
+
+& dotnet pack -c Release -p:NuspecFile=AspNetCore.Identity.MongoDbCore.nuspec
\ No newline at end of file
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 3c85947..78a7e6b 100644
--- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj
+++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj
@@ -7,23 +7,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
@@ -35,4 +33,8 @@
Always
+
+
+
+
diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs
index 68a7918..fa1f91e 100644
--- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs
+++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs
@@ -6,23 +6,23 @@ using System.Linq;
using System.Linq.Expressions;
using System.Security.Claims;
using System.Threading.Tasks;
+using AspNetCore.Identity.MongoDbCore.Extensions;
+using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
+using AspNetCore.Identity.MongoDbCore.Models;
using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.Test;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using Xunit;
-using AspNetCore.Identity.MongoDbCore.Models;
-using AspNetCore.Identity.MongoDbCore.Extensions;
using MongoDB.Driver;
-using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
using MongoDbGenericRepository;
-using Microsoft.AspNetCore.Identity;
+using Xunit;
namespace AspNetCore.Identity.MongoDbCore.Test
{
// TODO: Add test variation with non IdentityDbContext
- public abstract class MongoDbStoreTestBase : IdentitySpecificationTestBase,
+ public abstract class MongoDbStoreTestBase : IdentitySpecificationTestBase,
IClassFixture>
where TUser : MongoIdentityUser, new()
where TRole : MongoIdentityRole, new()
@@ -39,9 +39,12 @@ namespace AspNetCore.Identity.MongoDbCore.Test
{
services.AddSingleton();
// configure the default type name
- services.ConfigureMongoDbIdentity(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context);
+ services.ConfigureMongoDbIdentity(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context)
+ .AddDefaultTokenProviders();
+ services.AddAuthentication();
services.AddLogging();
+
services.AddSingleton>>(new TestLogger>());
services.AddSingleton>>(new TestLogger>());
}
diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreTest.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreTest.cs
index dd877af..5f8765a 100644
--- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreTest.cs
+++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreTest.cs
@@ -4,13 +4,13 @@
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
+using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
+using AspNetCore.Identity.MongoDbCore.Models;
+using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.Test;
using Microsoft.Extensions.DependencyInjection;
-using Xunit;
-using AspNetCore.Identity.MongoDbCore.Models;
-using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
using MongoDbGenericRepository;
-using Microsoft.AspNetCore.Identity;
+using Xunit;
namespace AspNetCore.Identity.MongoDbCore.Test
{
@@ -308,8 +308,8 @@ namespace AspNetCore.Identity.MongoDbCore.Test
{
// Arrange
const string originalEmail = "original@email.com";
- const string newEmail1 = "new1@email.com";
- const string newEmail2 = "new2@email.com";
+ string newEmail1 = $"new{DateTime.Now.Ticks}@email.com";
+ string newEmail2 = $"new{DateTime.Now.Ticks+1}@email.com";
var user = CreateTestUser();
user.Email = originalEmail;
var manager = CreateManager();
diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/Specification/IdentitySpecificationTestBase.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/Specification/IdentitySpecificationTestBase.cs
index 64d1078..6f15f0b 100644
--- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/Specification/IdentitySpecificationTestBase.cs
+++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/Specification/IdentitySpecificationTestBase.cs
@@ -7,14 +7,14 @@ using System.Linq;
using System.Linq.Expressions;
using System.Security.Claims;
using System.Threading.Tasks;
+using AspNetCore.Identity.MongoDbCore.Extensions;
+using AspNetCore.Identity.MongoDbCore.Infrastructure;
+using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
+using AspNetCore.Identity.MongoDbCore.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit;
-using AspNetCore.Identity.MongoDbCore.Models;
-using AspNetCore.Identity.MongoDbCore.Extensions;
-using AspNetCore.Identity.MongoDbCore.Infrastructure;
-using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
namespace Microsoft.AspNetCore.Identity.Test
{
@@ -48,7 +48,10 @@ namespace Microsoft.AspNetCore.Identity.Test
protected override void SetupIdentityServices(IServiceCollection services)
{
services.AddSingleton();
- services.ConfigureMongoDbIdentity(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context);
+ services.ConfigureMongoDbIdentity(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context)
+ .AddDefaultTokenProviders();
+ services.AddAuthentication();
+
services.AddLogging();
services.AddSingleton>>(new TestLogger>());
services.AddSingleton>>(new TestLogger>());
@@ -64,14 +67,17 @@ namespace Microsoft.AspNetCore.Identity.Test
services.AddSingleton();
if (concurrentSetup)
{
- services.ConfigureMongoDbIdentity(Container.MongoDbIdentityConfiguration, Container.MongoRepositoryConcurrent.Context);
+ services.ConfigureMongoDbIdentity(Container.MongoDbIdentityConfiguration, Container.MongoRepositoryConcurrent.Context)
+ .AddDefaultTokenProviders();
}
else
{
- services.ConfigureMongoDbIdentity(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context);
+ services.ConfigureMongoDbIdentity(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context)
+ .AddDefaultTokenProviders();
}
-
+
services.AddLogging();
+ services.AddAuthentication();
services.AddSingleton>>(new TestLogger>());
services.AddSingleton>>(new TestLogger>());
}
@@ -104,7 +110,7 @@ namespace Microsoft.AspNetCore.Identity.Test
services = new ServiceCollection();
}
- if(context == null)
+ if (context == null)
{
SetupIdentityServices(services);
}
@@ -112,7 +118,7 @@ namespace Microsoft.AspNetCore.Identity.Test
{
SetupIdentityServices(services, true);
}
-
+
return services.BuildServiceProvider().GetService>();
}
diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/appsettings.json b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/appsettings.json
index 5c53f25..1e27be6 100644
--- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/appsettings.json
+++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/appsettings.json
@@ -4,7 +4,7 @@
"DatabaseName": "MongoDbTests"
},
"Logging": {
- "IncludeScopes": false,
+ "IncludeScopes": {},
"LogLevel": {
"Default": "Warning"
}
diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/test.ps1 b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/test.ps1
new file mode 100644
index 0000000..dbc71a3
--- /dev/null
+++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/test.ps1
@@ -0,0 +1,7 @@
+
+Write-Output ""
+Write-Output "Running Tests with Code Coverage"
+Write-Output ""
+
+
+& 'dotnet' test /p:CollectCoverage=true