Skip to content

Commit 0b63b3a

Browse files
authored
Make Identity tests use public API to configure EF. (#52910)
1 parent 304cecb commit 0b63b3a

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

src/Identity/test/Identity.FunctionalTests/Infrastructure/FunctionalTestsServiceCollectionExtensions.cs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,11 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests;
1717

1818
public static class FunctionalTestsServiceCollectionExtensions
1919
{
20-
public static IServiceCollection SetupTestDatabase<TContext>(this IServiceCollection services, DbConnection connection) where TContext : DbContext
21-
{
22-
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<TContext>));
23-
if (descriptor != null)
24-
{
25-
services.Remove(descriptor);
26-
}
27-
28-
services.AddScoped(p =>
29-
DbContextOptionsFactory<TContext>(
30-
p,
31-
(sp, options) => options
20+
public static IServiceCollection SetupTestDatabase<TContext>(this IServiceCollection services, DbConnection connection) where TContext : DbContext =>
21+
services.ConfigureDbContext<TContext>((sp, options) => options
3222
.ConfigureWarnings(b => b.Log(CoreEventId.ManyServiceProvidersCreatedWarning))
33-
.UseSqlite(connection)));
34-
35-
return services;
36-
}
37-
38-
private static DbContextOptions<TContext> DbContextOptionsFactory<TContext>(
39-
IServiceProvider applicationServiceProvider,
40-
Action<IServiceProvider, DbContextOptionsBuilder> optionsAction)
41-
where TContext : DbContext
42-
{
43-
var builder = new DbContextOptionsBuilder<TContext>(
44-
new DbContextOptions<TContext>(new Dictionary<Type, IDbContextOptionsExtension>()));
45-
46-
builder.UseApplicationServiceProvider(applicationServiceProvider);
47-
48-
optionsAction?.Invoke(applicationServiceProvider, builder);
49-
50-
return builder.Options;
51-
}
23+
.UseSqlite(connection),
24+
ServiceLifetime.Scoped);
5225

5326
public static IServiceCollection SetupTestThirdPartyLogin(this IServiceCollection services) =>
5427
services.AddAuthentication()

0 commit comments

Comments
 (0)