Skip to content

Commit a48bfd1

Browse files
authored
Add testing for ASP.NET Core Identity model (#23723)
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
1 parent 6ef7c98 commit a48bfd1

27 files changed

+2170
-1
lines changed

Diff for: All.sln

+28
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.Sqlite.sqlit
112112
EndProject
113113
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.OData.FunctionalTests", "test\EFCore.OData.FunctionalTests\EFCore.OData.FunctionalTests.csproj", "{7C0E5443-FE44-4436-8A7D-CE64D1F889BD}"
114114
EndProject
115+
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}"
116+
EndProject
117+
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}"
118+
EndProject
119+
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}"
120+
EndProject
121+
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}"
122+
EndProject
115123
Global
116124
GlobalSection(SolutionConfigurationPlatforms) = preSolution
117125
Debug|Any CPU = Debug|Any CPU
@@ -294,6 +302,22 @@ Global
294302
{7C0E5443-FE44-4436-8A7D-CE64D1F889BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
295303
{7C0E5443-FE44-4436-8A7D-CE64D1F889BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
296304
{7C0E5443-FE44-4436-8A7D-CE64D1F889BD}.Release|Any CPU.Build.0 = Release|Any CPU
305+
{80A812BF-8AB7-4197-AC1C-712BA5E818FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
306+
{80A812BF-8AB7-4197-AC1C-712BA5E818FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
307+
{80A812BF-8AB7-4197-AC1C-712BA5E818FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
308+
{80A812BF-8AB7-4197-AC1C-712BA5E818FB}.Release|Any CPU.Build.0 = Release|Any CPU
309+
{F956A344-5C8D-4015-A3BF-7A8304C58BE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
310+
{F956A344-5C8D-4015-A3BF-7A8304C58BE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
311+
{F956A344-5C8D-4015-A3BF-7A8304C58BE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
312+
{F956A344-5C8D-4015-A3BF-7A8304C58BE4}.Release|Any CPU.Build.0 = Release|Any CPU
313+
{CC93C465-F5AC-4CB9-A064-3675955962F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
314+
{CC93C465-F5AC-4CB9-A064-3675955962F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
315+
{CC93C465-F5AC-4CB9-A064-3675955962F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
316+
{CC93C465-F5AC-4CB9-A064-3675955962F4}.Release|Any CPU.Build.0 = Release|Any CPU
317+
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
318+
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
319+
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
320+
{F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.Build.0 = Release|Any CPU
297321
EndGlobalSection
298322
GlobalSection(SolutionProperties) = preSolution
299323
HideSolutionNode = FALSE
@@ -343,6 +367,10 @@ Global
343367
{B163761D-FB4A-4C80-BAB9-01905E1351EF} = {258D5057-81B9-40EC-A872-D21E27452749}
344368
{E0FF35C8-8038-4394-9C2A-AF34BE3CC61F} = {258D5057-81B9-40EC-A872-D21E27452749}
345369
{7C0E5443-FE44-4436-8A7D-CE64D1F889BD} = {258D5057-81B9-40EC-A872-D21E27452749}
370+
{80A812BF-8AB7-4197-AC1C-712BA5E818FB} = {258D5057-81B9-40EC-A872-D21E27452749}
371+
{F956A344-5C8D-4015-A3BF-7A8304C58BE4} = {258D5057-81B9-40EC-A872-D21E27452749}
372+
{CC93C465-F5AC-4CB9-A064-3675955962F4} = {258D5057-81B9-40EC-A872-D21E27452749}
373+
{F1B2E5A0-8C74-414A-B262-353FEE325E9F} = {258D5057-81B9-40EC-A872-D21E27452749}
346374
EndGlobalSection
347375
GlobalSection(ExtensibilityGlobals) = postSolution
348376
SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705}

Diff for: EFCore.Relational.slnf

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"src\\EFCore.Sqlite\\EFCore.Sqlite.csproj",
1616
"src\\EFCore\\EFCore.csproj",
1717
"test\\EFCore.Analyzers.Tests\\EFCore.Analyzers.Tests.csproj",
18+
"test\\EFCore.AspNet.Specification.Tests\\EFCore.AspNet.Specification.Tests.csproj",
19+
"test\\EFCore.AspNet.SqlServer.FunctionalTests\\EFCore.AspNet.SqlServer.FunctionalTests.csproj",
20+
"test\\EFCore.AspNet.Sqlite.FunctionalTests\\EFCore.AspNet.Sqlite.FunctionalTests.csproj",
1821
"test\\EFCore.CrossStore.FunctionalTests\\EFCore.CrossStore.FunctionalTests.csproj",
1922
"test\\EFCore.Design.Tests\\EFCore.Design.Tests.csproj",
2023
"test\\EFCore.InMemory.FunctionalTests\\EFCore.InMemory.FunctionalTests.csproj",

Diff for: EFCore.Runtime.slnf

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"src\\EFCore\\EFCore.csproj",
1818
"src\\Microsoft.Data.Sqlite.Core\\Microsoft.Data.Sqlite.Core.csproj",
1919
"test\\EFCore.Analyzers.Tests\\EFCore.Analyzers.Tests.csproj",
20+
"test\\EFCore.AspNet.Specification.Tests\\EFCore.AspNet.Specification.Tests.csproj",
21+
"test\\EFCore.AspNet.SqlServer.FunctionalTests\\EFCore.AspNet.SqlServer.FunctionalTests.csproj",
22+
"test\\EFCore.AspNet.Sqlite.FunctionalTests\\EFCore.AspNet.Sqlite.FunctionalTests.csproj",
23+
"test\\EFCore.AspNet.InMemory.FunctionalTests\\EFCore.AspNet.InMemory.FunctionalTests.csproj"
2024
"test\\EFCore.Cosmos.FunctionalTests\\EFCore.Cosmos.FunctionalTests.csproj",
2125
"test\\EFCore.Cosmos.Tests\\EFCore.Cosmos.Tests.csproj",
2226
"test\\EFCore.CrossStore.FunctionalTests\\EFCore.CrossStore.FunctionalTests.csproj",

Diff for: EFCore.slnf

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"src\\dotnet-ef\\dotnet-ef.csproj",
2525
"src\\ef\\ef.csproj",
2626
"test\\EFCore.Analyzers.Tests\\EFCore.Analyzers.Tests.csproj",
27+
"test\\EFCore.AspNet.Specification.Tests\\EFCore.AspNet.Specification.Tests.csproj",
28+
"test\\EFCore.AspNet.SqlServer.FunctionalTests\\EFCore.AspNet.SqlServer.FunctionalTests.csproj",
29+
"test\\EFCore.AspNet.Sqlite.FunctionalTests\\EFCore.AspNet.Sqlite.FunctionalTests.csproj",
30+
"test\\EFCore.AspNet.InMemory.FunctionalTests\\EFCore.AspNet.InMemory.FunctionalTests.csproj"
2731
"test\\EFCore.Cosmos.FunctionalTests\\EFCore.Cosmos.FunctionalTests.csproj",
2832
"test\\EFCore.Cosmos.Tests\\EFCore.Cosmos.Tests.csproj",
2933
"test\\EFCore.CrossStore.FunctionalTests\\EFCore.CrossStore.FunctionalTests.csproj",

Diff for: eng/helix.proj

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<FailOnTestFailure>true</FailOnTestFailure>
1515
<EnableXUnitReporter>true</EnableXUnitReporter>
1616
<FailOnMissionControlTestFailure>true</FailOnMissionControlTestFailure>
17-
<SqlServerTests>$(RepoRoot)/test/EFCore.SqlServer.FunctionalTests/*.csproj;$(RepoRoot)/test/EFCore.OData.FunctionalTests/*.csproj</SqlServerTests>
17+
<SqlServerTests>$(RepoRoot)/test/EFCore.SqlServer.FunctionalTests/*.csproj;$(RepoRoot)/test/EFCore.OData.FunctionalTests/*.csproj;$(RepoRoot)/test/EFCore.AspNet.SqlServer.FunctionalTests/*.csproj</SqlServerTests>
1818
</PropertyGroup>
1919

2020
<PropertyGroup Condition = "'$(SYSTEM_ACCESSTOKEN)' == ''">
@@ -29,6 +29,7 @@
2929
<ItemGroup>
3030
<XUnitProject Include="$(RepoRoot)/test/**/*.csproj"/>
3131
<XUnitProject Remove="$(RepoRoot)/test/EFCore.Specification.Tests/*.csproj"/>
32+
<XUnitProject Remove="$(RepoRoot)/test/EFCore.AspNet.Specification.Tests/*.csproj"/>
3233
<XUnitProject Remove="$(RepoRoot)/test/EFCore.Relational.Specification.Tests/*.csproj"/>
3334
</ItemGroup>
3435

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.EntityFrameworkCore.Diagnostics;
7+
using Microsoft.EntityFrameworkCore.Infrastructure;
8+
using Microsoft.EntityFrameworkCore.Storage;
9+
using Microsoft.EntityFrameworkCore.TestUtilities;
10+
using Microsoft.Extensions.DependencyInjection;
11+
12+
namespace Microsoft.EntityFrameworkCore
13+
{
14+
public class AspNetIdentityCustomTypesDefaultInMemoryTest
15+
: AspNetIdentityCustomTypesDefaultTestBase<
16+
AspNetIdentityCustomTypesDefaultInMemoryTest.AspNetIdentityCustomTypesDefaultInMemoryFixture>
17+
{
18+
public AspNetIdentityCustomTypesDefaultInMemoryTest(AspNetIdentityCustomTypesDefaultInMemoryFixture fixture)
19+
: base(fixture)
20+
{
21+
}
22+
23+
protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
24+
{
25+
}
26+
27+
protected override async Task ExecuteWithStrategyInTransactionAsync(
28+
Func<CustomTypesIdentityContext, Task> testOperation,
29+
Func<CustomTypesIdentityContext, Task> nestedTestOperation1 = null,
30+
Func<CustomTypesIdentityContext, Task> nestedTestOperation2 = null,
31+
Func<CustomTypesIdentityContext, Task> nestedTestOperation3 = null)
32+
{
33+
await base.ExecuteWithStrategyInTransactionAsync(
34+
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);
35+
await Fixture.ReseedAsync();
36+
}
37+
38+
public class AspNetIdentityCustomTypesDefaultInMemoryFixture : AspNetIdentityFixtureBase
39+
{
40+
protected override IServiceCollection AddServices(IServiceCollection serviceCollection)
41+
=> base.AddServices(serviceCollection).AddEntityFrameworkProxies();
42+
43+
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
44+
=> base.AddOptions(builder)
45+
.UseLazyLoadingProxies()
46+
.ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning));
47+
48+
protected override ITestStoreFactory TestStoreFactory
49+
=> InMemoryTestStoreFactory.Instance;
50+
51+
protected override string StoreName
52+
=> "AspNetCustomTypesDefaultIdentity";
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.EntityFrameworkCore.Diagnostics;
7+
using Microsoft.EntityFrameworkCore.Infrastructure;
8+
using Microsoft.EntityFrameworkCore.Storage;
9+
using Microsoft.EntityFrameworkCore.TestUtilities;
10+
11+
namespace Microsoft.EntityFrameworkCore
12+
{
13+
public class AspNetIdentityCustomTypesIntKeyInMemoryTest
14+
: AspNetIdentityCustomTypesIntKeyTestBase<AspNetIdentityCustomTypesIntKeyInMemoryTest.AspNetIdentityCustomTypesIntKeyInMemoryFixture
15+
>
16+
{
17+
public AspNetIdentityCustomTypesIntKeyInMemoryTest(AspNetIdentityCustomTypesIntKeyInMemoryFixture fixture)
18+
: base(fixture)
19+
{
20+
}
21+
22+
protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
23+
{
24+
}
25+
26+
protected override async Task ExecuteWithStrategyInTransactionAsync(
27+
Func<CustomTypesIdentityContextInt, Task> testOperation,
28+
Func<CustomTypesIdentityContextInt, Task> nestedTestOperation1 = null,
29+
Func<CustomTypesIdentityContextInt, Task> nestedTestOperation2 = null,
30+
Func<CustomTypesIdentityContextInt, Task> nestedTestOperation3 = null)
31+
{
32+
await base.ExecuteWithStrategyInTransactionAsync(
33+
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);
34+
await Fixture.ReseedAsync();
35+
}
36+
37+
public class AspNetIdentityCustomTypesIntKeyInMemoryFixture : AspNetIdentityFixtureBase
38+
{
39+
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
40+
=> base.AddOptions(builder).ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning));
41+
42+
protected override ITestStoreFactory TestStoreFactory
43+
=> InMemoryTestStoreFactory.Instance;
44+
45+
protected override string StoreName
46+
=> "AspNetCustomTypesIntKeyIdentity";
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
7+
using Microsoft.EntityFrameworkCore.Diagnostics;
8+
using Microsoft.EntityFrameworkCore.Infrastructure;
9+
using Microsoft.EntityFrameworkCore.Storage;
10+
using Microsoft.EntityFrameworkCore.TestUtilities;
11+
12+
namespace Microsoft.EntityFrameworkCore
13+
{
14+
public class AspNetIdentityDefaultInMemoryTest
15+
: AspNetIdentityDefaultTestBase<AspNetIdentityDefaultInMemoryTest.AspNetDefaultIdentityInMemoryFixture>
16+
{
17+
public AspNetIdentityDefaultInMemoryTest(AspNetDefaultIdentityInMemoryFixture fixture)
18+
: base(fixture)
19+
{
20+
}
21+
22+
protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
23+
{
24+
}
25+
26+
protected override async Task ExecuteWithStrategyInTransactionAsync(
27+
Func<IdentityDbContext, Task> testOperation,
28+
Func<IdentityDbContext, Task> nestedTestOperation1 = null,
29+
Func<IdentityDbContext, Task> nestedTestOperation2 = null,
30+
Func<IdentityDbContext, Task> nestedTestOperation3 = null)
31+
{
32+
await base.ExecuteWithStrategyInTransactionAsync(
33+
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);
34+
await Fixture.ReseedAsync();
35+
}
36+
37+
public class AspNetDefaultIdentityInMemoryFixture : AspNetIdentityFixtureBase
38+
{
39+
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
40+
=> base.AddOptions(builder).ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning));
41+
42+
protected override ITestStoreFactory TestStoreFactory
43+
=> InMemoryTestStoreFactory.Instance;
44+
45+
protected override string StoreName
46+
=> "AspNetDefaultIdentity";
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Identity;
7+
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
8+
using Microsoft.EntityFrameworkCore.Diagnostics;
9+
using Microsoft.EntityFrameworkCore.Infrastructure;
10+
using Microsoft.EntityFrameworkCore.Storage;
11+
using Microsoft.EntityFrameworkCore.TestUtilities;
12+
13+
namespace Microsoft.EntityFrameworkCore
14+
{
15+
public class AspNetIdentityIntKeyInMemoryTest
16+
: AspNetIdentityIntKeyTestBase<AspNetIdentityIntKeyInMemoryTest.AspNetIdentityIntKeyInMemoryFixture>
17+
{
18+
public AspNetIdentityIntKeyInMemoryTest(AspNetIdentityIntKeyInMemoryFixture fixture)
19+
: base(fixture)
20+
{
21+
}
22+
23+
protected override void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
24+
{
25+
}
26+
27+
protected override async Task ExecuteWithStrategyInTransactionAsync(
28+
Func<IdentityDbContext<IdentityUser<int>, IdentityRole<int>, int>, Task> testOperation,
29+
Func<IdentityDbContext<IdentityUser<int>, IdentityRole<int>, int>, Task> nestedTestOperation1 = null,
30+
Func<IdentityDbContext<IdentityUser<int>, IdentityRole<int>, int>, Task> nestedTestOperation2 = null,
31+
Func<IdentityDbContext<IdentityUser<int>, IdentityRole<int>, int>, Task> nestedTestOperation3 = null)
32+
{
33+
await base.ExecuteWithStrategyInTransactionAsync(
34+
testOperation, nestedTestOperation1, nestedTestOperation2, nestedTestOperation3);
35+
await Fixture.ReseedAsync();
36+
}
37+
38+
public class AspNetIdentityIntKeyInMemoryFixture : AspNetIdentityFixtureBase
39+
{
40+
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
41+
=> base.AddOptions(builder).ConfigureWarnings(e => e.Ignore(InMemoryEventId.TransactionIgnoredWarning));
42+
43+
protected override ITestStoreFactory TestStoreFactory
44+
=> InMemoryTestStoreFactory.Instance;
45+
46+
protected override string StoreName
47+
=> "AspNetIntKeyIdentity";
48+
}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<AssemblyName>Microsoft.EntityFrameworkCore.AspNet.InMemory.FunctionalTests</AssemblyName>
6+
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<None Update="config.json">
11+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
12+
</None>
13+
<None Include="..\xunit.runner.json">
14+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
15+
</None>
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\EFCore.InMemory.FunctionalTests\EFCore.InMemory.FunctionalTests.csproj" />
20+
<ProjectReference Include="..\EFCore.AspNet.Specification.Tests\EFCore.AspNet.Specification.Tests.csproj" />
21+
</ItemGroup>
22+
23+
</Project>

0 commit comments

Comments
 (0)