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/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/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..60479ce 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,15 @@ 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 +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>(); } 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