Skip to content

Commit

Permalink
Add testing for ASP.NET Core Identity model (#23723)
Browse files Browse the repository at this point in the history
Fixes #11838

The intention here is not to test ASP.NET Core Identity. It is instead to test that:
* The Identity model continues to build correctly with new versions of EF Core and across multipler providers, including external providers once they adopt these tests
* The queries issues by Identity continue to work in new versions and across providers
* The common (documented) customizations of the Identity model continue to work
  • Loading branch information
ajcvickers committed Dec 19, 2020
1 parent 6ef7c98 commit a48bfd1
Show file tree
Hide file tree
Showing 27 changed files with 2,170 additions and 1 deletion.
28 changes: 28 additions & 0 deletions All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.Sqlite.sqlit
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.OData.FunctionalTests", "test\EFCore.OData.FunctionalTests\EFCore.OData.FunctionalTests.csproj", "{7C0E5443-FE44-4436-8A7D-CE64D1F889BD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.AspNet.Specification.Tests", "test\EFCore.AspNet.Specification.Tests\EFCore.AspNet.Specification.Tests.csproj", "{80A812BF-8AB7-4197-AC1C-712BA5E818FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.AspNet.SqlServer.FunctionalTests", "test\EFCore.AspNet.SqlServer.FunctionalTests\EFCore.AspNet.SqlServer.FunctionalTests.csproj", "{F956A344-5C8D-4015-A3BF-7A8304C58BE4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.AspNet.Sqlite.FunctionalTests", "test\EFCore.AspNet.Sqlite.FunctionalTests\EFCore.AspNet.Sqlite.FunctionalTests.csproj", "{CC93C465-F5AC-4CB9-A064-3675955962F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.AspNet.InMemory.FunctionalTests", "test\EFCore.AspNet.InMemory.FunctionalTests\EFCore.AspNet.InMemory.FunctionalTests.csproj", "{F1B2E5A0-8C74-414A-B262-353FEE325E9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -294,6 +302,22 @@ Global
{7C0E5443-FE44-4436-8A7D-CE64D1F889BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C0E5443-FE44-4436-8A7D-CE64D1F889BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C0E5443-FE44-4436-8A7D-CE64D1F889BD}.Release|Any CPU.Build.0 = Release|Any CPU
{80A812BF-8AB7-4197-AC1C-712BA5E818FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80A812BF-8AB7-4197-AC1C-712BA5E818FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80A812BF-8AB7-4197-AC1C-712BA5E818FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80A812BF-8AB7-4197-AC1C-712BA5E818FB}.Release|Any CPU.Build.0 = Release|Any CPU
{F956A344-5C8D-4015-A3BF-7A8304C58BE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F956A344-5C8D-4015-A3BF-7A8304C58BE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F956A344-5C8D-4015-A3BF-7A8304C58BE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F956A344-5C8D-4015-A3BF-7A8304C58BE4}.Release|Any CPU.Build.0 = Release|Any CPU
{CC93C465-F5AC-4CB9-A064-3675955962F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC93C465-F5AC-4CB9-A064-3675955962F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC93C465-F5AC-4CB9-A064-3675955962F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC93C465-F5AC-4CB9-A064-3675955962F4}.Release|Any CPU.Build.0 = Release|Any CPU
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -343,6 +367,10 @@ Global
{B163761D-FB4A-4C80-BAB9-01905E1351EF} = {258D5057-81B9-40EC-A872-D21E27452749}
{E0FF35C8-8038-4394-9C2A-AF34BE3CC61F} = {258D5057-81B9-40EC-A872-D21E27452749}
{7C0E5443-FE44-4436-8A7D-CE64D1F889BD} = {258D5057-81B9-40EC-A872-D21E27452749}
{80A812BF-8AB7-4197-AC1C-712BA5E818FB} = {258D5057-81B9-40EC-A872-D21E27452749}
{F956A344-5C8D-4015-A3BF-7A8304C58BE4} = {258D5057-81B9-40EC-A872-D21E27452749}
{CC93C465-F5AC-4CB9-A064-3675955962F4} = {258D5057-81B9-40EC-A872-D21E27452749}
{F1B2E5A0-8C74-414A-B262-353FEE325E9F} = {258D5057-81B9-40EC-A872-D21E27452749}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705}
Expand Down
3 changes: 3 additions & 0 deletions EFCore.Relational.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"src\\EFCore.Sqlite\\EFCore.Sqlite.csproj",
"src\\EFCore\\EFCore.csproj",
"test\\EFCore.Analyzers.Tests\\EFCore.Analyzers.Tests.csproj",
"test\\EFCore.AspNet.Specification.Tests\\EFCore.AspNet.Specification.Tests.csproj",
"test\\EFCore.AspNet.SqlServer.FunctionalTests\\EFCore.AspNet.SqlServer.FunctionalTests.csproj",
"test\\EFCore.AspNet.Sqlite.FunctionalTests\\EFCore.AspNet.Sqlite.FunctionalTests.csproj",
"test\\EFCore.CrossStore.FunctionalTests\\EFCore.CrossStore.FunctionalTests.csproj",
"test\\EFCore.Design.Tests\\EFCore.Design.Tests.csproj",
"test\\EFCore.InMemory.FunctionalTests\\EFCore.InMemory.FunctionalTests.csproj",
Expand Down
4 changes: 4 additions & 0 deletions EFCore.Runtime.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"src\\EFCore\\EFCore.csproj",
"src\\Microsoft.Data.Sqlite.Core\\Microsoft.Data.Sqlite.Core.csproj",
"test\\EFCore.Analyzers.Tests\\EFCore.Analyzers.Tests.csproj",
"test\\EFCore.AspNet.Specification.Tests\\EFCore.AspNet.Specification.Tests.csproj",
"test\\EFCore.AspNet.SqlServer.FunctionalTests\\EFCore.AspNet.SqlServer.FunctionalTests.csproj",
"test\\EFCore.AspNet.Sqlite.FunctionalTests\\EFCore.AspNet.Sqlite.FunctionalTests.csproj",
"test\\EFCore.AspNet.InMemory.FunctionalTests\\EFCore.AspNet.InMemory.FunctionalTests.csproj"
"test\\EFCore.Cosmos.FunctionalTests\\EFCore.Cosmos.FunctionalTests.csproj",
"test\\EFCore.Cosmos.Tests\\EFCore.Cosmos.Tests.csproj",
"test\\EFCore.CrossStore.FunctionalTests\\EFCore.CrossStore.FunctionalTests.csproj",
Expand Down
4 changes: 4 additions & 0 deletions EFCore.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"src\\dotnet-ef\\dotnet-ef.csproj",
"src\\ef\\ef.csproj",
"test\\EFCore.Analyzers.Tests\\EFCore.Analyzers.Tests.csproj",
"test\\EFCore.AspNet.Specification.Tests\\EFCore.AspNet.Specification.Tests.csproj",
"test\\EFCore.AspNet.SqlServer.FunctionalTests\\EFCore.AspNet.SqlServer.FunctionalTests.csproj",
"test\\EFCore.AspNet.Sqlite.FunctionalTests\\EFCore.AspNet.Sqlite.FunctionalTests.csproj",
"test\\EFCore.AspNet.InMemory.FunctionalTests\\EFCore.AspNet.InMemory.FunctionalTests.csproj"
"test\\EFCore.Cosmos.FunctionalTests\\EFCore.Cosmos.FunctionalTests.csproj",
"test\\EFCore.Cosmos.Tests\\EFCore.Cosmos.Tests.csproj",
"test\\EFCore.CrossStore.FunctionalTests\\EFCore.CrossStore.FunctionalTests.csproj",
Expand Down
3 changes: 2 additions & 1 deletion eng/helix.proj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<FailOnTestFailure>true</FailOnTestFailure>
<EnableXUnitReporter>true</EnableXUnitReporter>
<FailOnMissionControlTestFailure>true</FailOnMissionControlTestFailure>
<SqlServerTests>$(RepoRoot)/test/EFCore.SqlServer.FunctionalTests/*.csproj;$(RepoRoot)/test/EFCore.OData.FunctionalTests/*.csproj</SqlServerTests>
<SqlServerTests>$(RepoRoot)/test/EFCore.SqlServer.FunctionalTests/*.csproj;$(RepoRoot)/test/EFCore.OData.FunctionalTests/*.csproj;$(RepoRoot)/test/EFCore.AspNet.SqlServer.FunctionalTests/*.csproj</SqlServerTests>
</PropertyGroup>

<PropertyGroup Condition = "'$(SYSTEM_ACCESSTOKEN)' == ''">
Expand All @@ -29,6 +29,7 @@
<ItemGroup>
<XUnitProject Include="$(RepoRoot)/test/**/*.csproj"/>
<XUnitProject Remove="$(RepoRoot)/test/EFCore.Specification.Tests/*.csproj"/>
<XUnitProject Remove="$(RepoRoot)/test/EFCore.AspNet.Specification.Tests/*.csproj"/>
<XUnitProject Remove="$(RepoRoot)/test/EFCore.Relational.Specification.Tests/*.csproj"/>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.EntityFrameworkCore
{
public class AspNetIdentityCustomTypesDefaultInMemoryTest
: AspNetIdentityCustomTypesDefaultTestBase<
AspNetIdentityCustomTypesDefaultInMemoryTest.AspNetIdentityCustomTypesDefaultInMemoryFixture>
{
public AspNetIdentityCustomTypesDefaultInMemoryTest(AspNetIdentityCustomTypesDefaultInMemoryFixture fixture)
: base(fixture)
{
}

protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
{
}

protected override async Task ExecuteWithStrategyInTransactionAsync(
Func<CustomTypesIdentityContext, Task> testOperation,
Func<CustomTypesIdentityContext, Task> nestedTestOperation1 = null,
Func<CustomTypesIdentityContext, Task> nestedTestOperation2 = null,
Func<CustomTypesIdentityContext, Task> nestedTestOperation3 = null)
{
await base.ExecuteWithStrategyInTransactionAsync(
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);
await Fixture.ReseedAsync();
}

public class AspNetIdentityCustomTypesDefaultInMemoryFixture : AspNetIdentityFixtureBase
{
protected override IServiceCollection AddServices(IServiceCollection serviceCollection)
=> base.AddServices(serviceCollection).AddEntityFrameworkProxies();

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder)
.UseLazyLoadingProxies()
.ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning));

protected override ITestStoreFactory TestStoreFactory
=> InMemoryTestStoreFactory.Instance;

protected override string StoreName
=> "AspNetCustomTypesDefaultIdentity";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore
{
public class AspNetIdentityCustomTypesIntKeyInMemoryTest
: AspNetIdentityCustomTypesIntKeyTestBase<AspNetIdentityCustomTypesIntKeyInMemoryTest.AspNetIdentityCustomTypesIntKeyInMemoryFixture
>
{
public AspNetIdentityCustomTypesIntKeyInMemoryTest(AspNetIdentityCustomTypesIntKeyInMemoryFixture fixture)
: base(fixture)
{
}

protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
{
}

protected override async Task ExecuteWithStrategyInTransactionAsync(
Func<CustomTypesIdentityContextInt, Task> testOperation,
Func<CustomTypesIdentityContextInt, Task> nestedTestOperation1 = null,
Func<CustomTypesIdentityContextInt, Task> nestedTestOperation2 = null,
Func<CustomTypesIdentityContextInt, Task> nestedTestOperation3 = null)
{
await base.ExecuteWithStrategyInTransactionAsync(
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);
await Fixture.ReseedAsync();
}

public class AspNetIdentityCustomTypesIntKeyInMemoryFixture : AspNetIdentityFixtureBase
{
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning));

protected override ITestStoreFactory TestStoreFactory
=> InMemoryTestStoreFactory.Instance;

protected override string StoreName
=> "AspNetCustomTypesIntKeyIdentity";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.Threading.Tasks;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore
{
public class AspNetIdentityDefaultInMemoryTest
: AspNetIdentityDefaultTestBase<AspNetIdentityDefaultInMemoryTest.AspNetDefaultIdentityInMemoryFixture>
{
public AspNetIdentityDefaultInMemoryTest(AspNetDefaultIdentityInMemoryFixture fixture)
: base(fixture)
{
}

protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
{
}

protected override async Task ExecuteWithStrategyInTransactionAsync(
Func<IdentityDbContext, Task> testOperation,
Func<IdentityDbContext, Task> nestedTestOperation1 = null,
Func<IdentityDbContext, Task> nestedTestOperation2 = null,
Func<IdentityDbContext, Task> nestedTestOperation3 = null)
{
await base.ExecuteWithStrategyInTransactionAsync(
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);
await Fixture.ReseedAsync();
}

public class AspNetDefaultIdentityInMemoryFixture : AspNetIdentityFixtureBase
{
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning));

protected override ITestStoreFactory TestStoreFactory
=> InMemoryTestStoreFactory.Instance;

protected override string StoreName
=> "AspNetDefaultIdentity";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore
{
public class AspNetIdentityIntKeyInMemoryTest
: AspNetIdentityIntKeyTestBase<AspNetIdentityIntKeyInMemoryTest.AspNetIdentityIntKeyInMemoryFixture>
{
public AspNetIdentityIntKeyInMemoryTest(AspNetIdentityIntKeyInMemoryFixture fixture)
: base(fixture)
{
}

protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
{
}

protected override async Task ExecuteWithStrategyInTransactionAsync(
Func<IdentityDbContext<IdentityUser<int>, IdentityRole<int>, int>, Task> testOperation,
Func<IdentityDbContext<IdentityUser<int>, IdentityRole<int>, int>, Task> nestedTestOperation1 = null,
Func<IdentityDbContext<IdentityUser<int>, IdentityRole<int>, int>, Task> nestedTestOperation2 = null,
Func<IdentityDbContext<IdentityUser<int>, IdentityRole<int>, int>, Task> nestedTestOperation3 = null)
{
await base.ExecuteWithStrategyInTransactionAsync(
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);
await Fixture.ReseedAsync();
}

public class AspNetIdentityIntKeyInMemoryFixture : AspNetIdentityFixtureBase
{
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder).ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning));

protected override ITestStoreFactory TestStoreFactory
=> InMemoryTestStoreFactory.Instance;

protected override string StoreName
=> "AspNetIntKeyIdentity";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Microsoft.EntityFrameworkCore.AspNet.InMemory.FunctionalTests</AssemblyName>
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EFCore.InMemory.FunctionalTests\EFCore.InMemory.FunctionalTests.csproj" />
<ProjectReference Include="..\EFCore.AspNet.Specification.Tests\EFCore.AspNet.Specification.Tests.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit a48bfd1

Please sign in to comment.