Updated tests based on changes to AspNet Identity Core

Added .AddDefaultTokenProviders() after the call to ConfigureMongoDbIdentity
Note: There are four places in the test project
Added .AddAuthentication() to register all the authentication types
Fixed aspnetsettings.json IncludeScopes to empty object, not false
Updated unit test packages to latest version
Added project reference for unit test rather than package reference
Removed all references to AspNet framework assemblies as these are now part of the netcoreapp3.1
This commit is contained in:
David Barker
2021-03-03 16:04:49 +08:00
parent c39a8b3109
commit 91329b8653
8 changed files with 59 additions and 39 deletions
+6 -2
View File
@@ -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
@@ -4,7 +4,7 @@
"DatabaseName": "MongoDbTests"
},
"Logging": {
"IncludeScopes": false,
"IncludeScopes": {},
"LogLevel": {
"Default": "Warning"
}
@@ -7,23 +7,21 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.12" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="3.1.12" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="3.1.12" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.12" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
<PackageReference Include="MongoDbGenericRepository" Version="1.4.3" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="coverlet.msbuild" Version="2.9.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="dotnet-reportgenerator-cli" Version="4.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -35,4 +33,8 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\AspNetCore.Identity.MongoDbCore.csproj" />
</ItemGroup>
</Project>
@@ -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<TUser, TRole, TKey> : IdentitySpecificationTestBase<TUser, TRole, TKey>,
public abstract class MongoDbStoreTestBase<TUser, TRole, TKey> : IdentitySpecificationTestBase<TUser, TRole, TKey>,
IClassFixture<MongoDatabaseFixture<TUser, TRole, TKey>>
where TUser : MongoIdentityUser<TKey>, new()
where TRole : MongoIdentityRole<TKey>, new()
@@ -39,9 +39,12 @@ namespace AspNetCore.Identity.MongoDbCore.Test
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
// configure the default type name
services.ConfigureMongoDbIdentity<TUser, TRole, TKey>(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context);
services.ConfigureMongoDbIdentity<TUser, TRole, TKey>(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context)
.AddDefaultTokenProviders();
services.AddAuthentication();
services.AddLogging();
services.AddSingleton<ILogger<UserManager<TUser>>>(new TestLogger<UserManager<TUser>>());
services.AddSingleton<ILogger<RoleManager<TRole>>>(new TestLogger<RoleManager<TRole>>());
}
@@ -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();
@@ -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<IHttpContextAccessor, HttpContextAccessor>();
services.ConfigureMongoDbIdentity<TUser, TRole, TKey>(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context);
services.ConfigureMongoDbIdentity<TUser, TRole, TKey>(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context)
.AddDefaultTokenProviders();
services.AddAuthentication();
services.AddLogging();
services.AddSingleton<ILogger<UserManager<TUser>>>(new TestLogger<UserManager<TUser>>());
services.AddSingleton<ILogger<RoleManager<TRole>>>(new TestLogger<RoleManager<TRole>>());
@@ -64,14 +67,15 @@ namespace Microsoft.AspNetCore.Identity.Test
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
if (concurrentSetup)
{
services.ConfigureMongoDbIdentity<TUser, TRole, TKey>(Container.MongoDbIdentityConfiguration, Container.MongoRepositoryConcurrent.Context);
services.ConfigureMongoDbIdentity<TUser, TRole, TKey>(Container.MongoDbIdentityConfiguration, Container.MongoRepositoryConcurrent.Context).AddDefaultTokenProviders();
}
else
{
services.ConfigureMongoDbIdentity<TUser, TRole, TKey>(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context);
services.ConfigureMongoDbIdentity<TUser, TRole, TKey>(Container.MongoDbIdentityConfiguration, Container.MongoRepository.Context).AddDefaultTokenProviders();
}
services.AddLogging();
services.AddAuthentication();
services.AddSingleton<ILogger<UserManager<TUser>>>(new TestLogger<UserManager<TUser>>());
services.AddSingleton<ILogger<RoleManager<TRole>>>(new TestLogger<RoleManager<TRole>>());
}
@@ -104,7 +108,7 @@ namespace Microsoft.AspNetCore.Identity.Test
services = new ServiceCollection();
}
if(context == null)
if (context == null)
{
SetupIdentityServices(services);
}
@@ -112,7 +116,7 @@ namespace Microsoft.AspNetCore.Identity.Test
{
SetupIdentityServices(services, true);
}
return services.BuildServiceProvider().GetService<RoleManager<TRole>>();
}
@@ -4,7 +4,7 @@
"DatabaseName": "MongoDbTests"
},
"Logging": {
"IncludeScopes": false,
"IncludeScopes": {},
"LogLevel": {
"Default": "Warning"
}
@@ -0,0 +1,7 @@
Write-Output ""
Write-Output "Running Tests with Code Coverage"
Write-Output ""
& 'dotnet' test /p:CollectCoverage=true