1
1
using System ;
2
- using System . Collections . Generic ;
3
- using System . Data . SqlClient ;
4
- using Docker . Testify ;
2
+ using System . Threading . Tasks ;
3
+ using Squadron ;
5
4
using Xunit ;
6
5
7
6
namespace WorkflowCore . Tests . SqlServer
8
7
{
9
- public class SqlDockerSetup : DockerSetup
8
+ public class SqlDockerSetup : IAsyncLifetime
10
9
{
10
+ private readonly SqlServerResource _sqlServerResource ;
11
11
public static string ConnectionString { get ; set ; }
12
12
public static string ScenarioConnectionString { get ; set ; }
13
13
14
- public override string ImageName => "mcr.microsoft.com/mssql/server" ;
15
- public override int InternalPort => 1433 ;
16
- public override TimeSpan TimeOut => TimeSpan . FromSeconds ( 120 ) ;
17
-
18
- public const string SqlPassword = "I@mJustT3st1ing" ;
19
-
20
- public override IList < string > EnvironmentVariables => new List < string > { "ACCEPT_EULA=Y" , $ "SA_PASSWORD={ SqlPassword } "} ;
21
-
22
- public override void PublishConnectionInfo ( )
14
+ public SqlDockerSetup ( )
23
15
{
24
- ConnectionString = $ "Server=127.0.0.1,{ ExternalPort } ;Database=workflowcore-tests;User Id=sa;Password={ SqlPassword } ;";
25
- ScenarioConnectionString = $ "Server=127.0.0.1,{ ExternalPort } ;Database=workflowcore-scenario-tests;User Id=sa;Password={ SqlPassword } ;";
16
+ _sqlServerResource = new SqlServerResource ( ) ;
26
17
}
27
18
28
- public override bool TestReady ( )
19
+ public async Task InitializeAsync ( )
29
20
{
30
- try
31
- {
32
- var client = new SqlConnection ( $ "Server=127.0.0.1,{ ExternalPort } ;Database=master;User Id=sa;Password={ SqlPassword } ;") ;
33
- client . Open ( ) ;
34
- client . Close ( ) ;
35
- return true ;
36
- }
37
- catch
38
- {
39
- return false ;
40
- }
21
+ await _sqlServerResource . InitializeAsync ( ) ;
22
+ ConnectionString = _sqlServerResource . CreateConnectionString ( "workflowcore-tests" ) ;
23
+ ScenarioConnectionString = _sqlServerResource . CreateConnectionString ( "workflowcore-scenario-tests" ) ;
24
+ }
41
25
26
+ public Task DisposeAsync ( )
27
+ {
28
+ return _sqlServerResource . DisposeAsync ( ) ;
42
29
}
43
30
}
44
31
45
32
[ CollectionDefinition ( "SqlServer collection" ) ]
46
33
public class SqlServerCollection : ICollectionFixture < SqlDockerSetup >
47
34
{
48
35
}
49
-
50
36
}
0 commit comments