1
1
namespace Testcontainers . MariaDb ;
2
2
3
- public abstract class MariaDbContainerTest : IAsyncLifetime
3
+ public abstract class MariaDbContainerTest
4
4
{
5
- private readonly MariaDbContainer _mariaDbContainer ;
5
+ private readonly MariaDbFixture _mariaDbFixture ;
6
6
7
- protected MariaDbContainerTest ( MariaDbContainer mariaDbContainer )
7
+ protected MariaDbContainerTest ( MariaDbFixture fixture )
8
8
{
9
- _mariaDbContainer = mariaDbContainer ;
10
- }
11
-
12
- public Task InitializeAsync ( )
13
- {
14
- return _mariaDbContainer . StartAsync ( ) ;
15
- }
16
-
17
- public Task DisposeAsync ( )
18
- {
19
- return _mariaDbContainer . DisposeAsync ( ) . AsTask ( ) ;
9
+ _mariaDbFixture = fixture ;
20
10
}
21
11
22
12
[ Fact ]
23
13
[ Trait ( nameof ( DockerCli . DockerPlatform ) , nameof ( DockerCli . DockerPlatform . Linux ) ) ]
24
14
public void ConnectionStateReturnsOpen ( )
25
15
{
26
16
// Given
27
- using DbConnection connection = new MySqlConnection ( _mariaDbContainer . GetConnectionString ( ) ) ;
17
+ using DbConnection connection = _mariaDbFixture . CreateDbConnection ( ) ;
28
18
29
19
// When
30
20
connection . Open ( ) ;
@@ -41,28 +31,48 @@ public async Task ExecScriptReturnsSuccessful()
41
31
const string scriptContent = "SELECT 1;" ;
42
32
43
33
// When
44
- var execResult = await _mariaDbContainer . ExecScriptAsync ( scriptContent )
34
+ var execResult = await _mariaDbFixture . Container . ExecScriptAsync ( scriptContent )
45
35
. ConfigureAwait ( false ) ;
46
36
47
37
// When
48
38
Assert . True ( 0L . Equals ( execResult . ExitCode ) , execResult . Stderr ) ;
49
39
}
50
40
51
41
[ UsedImplicitly ]
52
- public sealed class MariaDbUserConfiguration : MariaDbContainerTest
42
+ public sealed class MariaDbUserConfiguration : MariaDbContainerTest , IClassFixture < MariaDbFixture >
53
43
{
54
- public MariaDbUserConfiguration ( )
55
- : base ( new MariaDbBuilder ( ) . Build ( ) )
44
+ public MariaDbUserConfiguration ( MariaDbFixture fixture )
45
+ : base ( fixture )
56
46
{
57
47
}
58
48
}
59
49
60
50
[ UsedImplicitly ]
61
- public sealed class MariaDbRootConfiguration : MariaDbContainerTest
51
+ public sealed class MariaDbRootConfiguration : MariaDbContainerTest , IClassFixture < MariaDbRootUserFixture >
52
+ {
53
+ public MariaDbRootConfiguration ( MariaDbRootUserFixture fixture )
54
+ : base ( fixture )
55
+ {
56
+ }
57
+ }
58
+
59
+ public class MariaDbFixture : DbContainerFixture < MariaDbBuilder , MariaDbContainer >
62
60
{
63
- public MariaDbRootConfiguration ( )
64
- : base ( new MariaDbBuilder ( ) . WithUsername ( "root" ) . Build ( ) )
61
+ public MariaDbFixture ( IMessageSink messageSink )
62
+ : base ( messageSink )
65
63
{
66
64
}
65
+
66
+ public override DbProviderFactory DbProviderFactory => MySqlConnectorFactory . Instance ;
67
+ }
68
+
69
+ public class MariaDbRootUserFixture : MariaDbFixture
70
+ {
71
+ public MariaDbRootUserFixture ( IMessageSink messageSink )
72
+ : base ( messageSink )
73
+ {
74
+ }
75
+
76
+ protected override MariaDbBuilder Configure ( MariaDbBuilder builder ) => builder . WithUsername ( "root" ) ;
67
77
}
68
78
}
0 commit comments