33using Microsoft . EntityFrameworkCore . TestUtilities ;
44using Npgsql ;
55using System . Collections . Concurrent ;
6- using System . Data . Common ;
6+ using System . Data ;
77
88namespace CmdScale . EntityFrameworkCore . TimescaleDB . FunctionalTests . Utils ;
99
1010public class TimescaleTestStore : RelationalTestStore
1111{
1212 private static readonly ConcurrentDictionary < string , TimescaleTestStore > _sharedStores = new ( ) ;
1313
14- protected override DbConnection Connection { get => base . Connection ; set => base . Connection = value ; }
15- public override string ConnectionString { get => base . ConnectionString ; protected set => base . ConnectionString = value ; }
16-
1714 private TimescaleTestStore ( string name , bool shared , string connectionString )
18- : base ( name , shared )
15+ : base ( name , shared , new NpgsqlConnection ( connectionString ) )
1916 {
20- ConnectionString = connectionString ;
21- Connection = new NpgsqlConnection ( ConnectionString ) ;
2217 }
2318
2419 public static TimescaleTestStore Create ( string name , string connectionString )
@@ -29,19 +24,33 @@ public static TimescaleTestStore GetOrCreateShared(string name, string connectio
2924 {
3025 TimescaleTestStore store = new ( name , shared : true , connectionString ) ;
3126
32- DbContextOptions < MigrationsInfrastructureFixtureBase . MigrationsContext > options = new DbContextOptionsBuilder < MigrationsInfrastructureFixtureBase . MigrationsContext > ( )
33- . UseNpgsql ( connectionString ) . UseTimescaleDb ( ) . Options ;
34- store . Initialize ( null , ( ) => new MigrationsInfrastructureFixtureBase . MigrationsContext ( options ) , null ) ;
27+ DbContextOptions < MigrationsInfrastructureFixtureBase . MigrationsContext > options =
28+ new DbContextOptionsBuilder < MigrationsInfrastructureFixtureBase . MigrationsContext > ( )
29+ . UseNpgsql ( connectionString ) . UseTimescaleDb ( ) . Options ;
30+ var __ = store . InitializeAsync ( null ,
31+ ( ) => new MigrationsInfrastructureFixtureBase . MigrationsContext ( options ) , null ) . Result ;
3532 return store ;
3633 } ) ;
3734
3835 public override DbContextOptionsBuilder AddProviderOptions ( DbContextOptionsBuilder builder )
39- => builder . AddInterceptors ( new TimescaleMigrationsTestInterceptor ( ) ) . UseNpgsql ( ConnectionString , options =>
40- {
41- } ) . UseTimescaleDb ( ) . EnableSensitiveDataLogging ( ) ;
36+ => builder . AddInterceptors ( new TimescaleMigrationsTestInterceptor ( ) ) . UseNpgsql ( ConnectionString , options => { } )
37+ . UseTimescaleDb ( ) . EnableSensitiveDataLogging ( ) ;
4238
43- public override void Clean ( DbContext context )
39+ public override Task CleanAsync ( DbContext context )
4440 {
4541 context . Database . EnsureClean ( ) ;
42+ return Task . CompletedTask ;
43+ }
44+
45+ public void ExecuteScript ( string script )
46+ {
47+ if ( ConnectionState != ConnectionState . Open )
48+ Connection . Open ( ) ;
49+
50+ using ( var cmd = Connection . CreateCommand ( ) )
51+ {
52+ cmd . CommandText = script ;
53+ cmd . ExecuteNonQuery ( ) ;
54+ }
4655 }
47- }
56+ }
0 commit comments