@@ -17,38 +17,11 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests;
17
17
18
18
public static class FunctionalTestsServiceCollectionExtensions
19
19
{
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
32
22
. 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 ) ;
52
25
53
26
public static IServiceCollection SetupTestThirdPartyLogin ( this IServiceCollection services ) =>
54
27
services . AddAuthentication ( )
0 commit comments