1
1
namespace Testcontainers . MongoDb ;
2
2
3
- public abstract class MongoDbContainerTest : IAsyncLifetime
3
+ public abstract class MongoDbContainerTest : ContainerTest < MongoDbBuilder , MongoDbContainer >
4
4
{
5
- private readonly MongoDbContainer _mongoDbContainer ;
6
-
7
- private MongoDbContainerTest ( MongoDbContainer mongoDbContainer )
8
- {
9
- _mongoDbContainer = mongoDbContainer ;
10
- }
11
-
12
- public Task InitializeAsync ( )
13
- {
14
- return _mongoDbContainer . StartAsync ( ) ;
15
- }
16
-
17
- public Task DisposeAsync ( )
5
+ protected MongoDbContainerTest ( ITestOutputHelper testOutputHelper , Func < MongoDbBuilder , MongoDbBuilder > configure = null )
6
+ : base ( testOutputHelper , configure )
18
7
{
19
- return _mongoDbContainer . DisposeAsync ( ) . AsTask ( ) ;
20
8
}
21
9
22
10
[ Fact ]
23
11
[ Trait ( nameof ( DockerCli . DockerPlatform ) , nameof ( DockerCli . DockerPlatform . Linux ) ) ]
24
12
public void ConnectionStateReturnsOpen ( )
25
13
{
26
14
// Given
27
- var client = new MongoClient ( _mongoDbContainer . GetConnectionString ( ) ) ;
15
+ var client = new MongoClient ( Container . GetConnectionString ( ) ) ;
28
16
29
17
// When
30
18
using var databases = client . ListDatabases ( ) ;
@@ -41,7 +29,7 @@ public async Task ExecScriptReturnsSuccessful()
41
29
const string scriptContent = "printjson(db.adminCommand({listDatabases:1,nameOnly:true,filter:{\" name\" :/^admin/}}));" ;
42
30
43
31
// When
44
- var execResult = await _mongoDbContainer . ExecScriptAsync ( scriptContent )
32
+ var execResult = await Container . ExecScriptAsync ( scriptContent )
45
33
. ConfigureAwait ( false ) ;
46
34
47
35
// When
@@ -51,35 +39,35 @@ public async Task ExecScriptReturnsSuccessful()
51
39
[ UsedImplicitly ]
52
40
public sealed class MongoDbDefaultConfiguration : MongoDbContainerTest
53
41
{
54
- public MongoDbDefaultConfiguration ( )
55
- : base ( new MongoDbBuilder ( ) . Build ( ) )
42
+ public MongoDbDefaultConfiguration ( ITestOutputHelper testOutputHelper )
43
+ : base ( testOutputHelper )
56
44
{
57
45
}
58
46
}
59
47
60
48
[ UsedImplicitly ]
61
49
public sealed class MongoDbNoAuthConfiguration : MongoDbContainerTest
62
50
{
63
- public MongoDbNoAuthConfiguration ( )
64
- : base ( new MongoDbBuilder ( ) . WithUsername ( string . Empty ) . WithPassword ( string . Empty ) . Build ( ) )
51
+ public MongoDbNoAuthConfiguration ( ITestOutputHelper testOutputHelper )
52
+ : base ( testOutputHelper , builder => builder . WithUsername ( string . Empty ) . WithPassword ( string . Empty ) )
65
53
{
66
54
}
67
55
}
68
56
69
57
[ UsedImplicitly ]
70
58
public sealed class MongoDbV5Configuration : MongoDbContainerTest
71
59
{
72
- public MongoDbV5Configuration ( )
73
- : base ( new MongoDbBuilder ( ) . WithImage ( "mongo:5.0" ) . Build ( ) )
60
+ public MongoDbV5Configuration ( ITestOutputHelper testOutputHelper )
61
+ : base ( testOutputHelper , builder => builder . WithImage ( "mongo:5.0" ) )
74
62
{
75
63
}
76
64
}
77
65
78
66
[ UsedImplicitly ]
79
67
public sealed class MongoDbV4Configuration : MongoDbContainerTest
80
68
{
81
- public MongoDbV4Configuration ( )
82
- : base ( new MongoDbBuilder ( ) . WithImage ( "mongo:4.4" ) . Build ( ) )
69
+ public MongoDbV4Configuration ( ITestOutputHelper testOutputHelper )
70
+ : base ( testOutputHelper , builder => builder . WithImage ( "mongo:4.4" ) )
83
71
{
84
72
}
85
73
}
0 commit comments