@@ -19,7 +19,7 @@ public class MongoDBTestContainer : ITestContainer<ObjectId, TestMongoDBItem>
19
19
private readonly TestcontainersContainer _mongoDBTestContainer ;
20
20
private MongoDBDatabase _dbDatabase ;
21
21
private DockerClient _dockerClient ;
22
- private const string containerName = "mongoContainer" ;
22
+ private string containerName = $ "mongoContainer{ Guid . NewGuid ( ) . ToString ( "N" ) } ";
23
23
private const ushort privatePort = 27017 ;
24
24
private bool containerExsist = false ;
25
25
@@ -36,7 +36,7 @@ public MongoDBTestContainer()
36
36
. UntilPortIsAvailable ( privatePort ) )
37
37
. Build ( ) ;
38
38
39
- _dockerClient = new DockerClientConfiguration ( ) . CreateClient ( ) ;
39
+ // _dockerClient = new DockerClientConfiguration().CreateClient();
40
40
}
41
41
42
42
public IDatabaseCollection < ObjectId , TestMongoDBItem > Collection =>
@@ -51,9 +51,10 @@ public async Task InitializeAsync()
51
51
{
52
52
ushort publicPort = 0 ;
53
53
54
+ await _mongoDBTestContainer . StartAsync ( ) ;
55
+ /*
54
56
try
55
57
{
56
- await _mongoDBTestContainer . StartAsync ( ) ;
57
58
58
59
containerExsist = false;
59
60
}
@@ -73,11 +74,11 @@ public async Task InitializeAsync()
73
74
ContainerListResponse containerListResponse = listContainers.Single(container => container.Names.Contains($"/{containerName}"));
74
75
75
76
publicPort = containerListResponse.Ports.Single(port => port.PrivatePort == privatePort).PublicPort;
76
- }
77
+ }*/
77
78
78
79
_dbDatabase = new MongoDBDatabase ( new MongoDBOptions ( )
79
80
{
80
- ConnectionString = $ "mongodb://localhost:{ publicPort } ",
81
+ ConnectionString = $ "mongodb://localhost:{ _mongoDBTestContainer . GetMappedPublicPort ( privatePort ) } ",
81
82
DataBaseName = $ "db{ Guid . NewGuid ( ) . ToString ( "N" ) } ",
82
83
} ) ;
83
84
@@ -90,8 +91,8 @@ public async Task InitializeAsync()
90
91
public async Task DisposeAsync ( )
91
92
{
92
93
await _dbDatabase . DisposeAsync ( ) ;
93
- // await _mongoDBContainer .StopAsync();
94
- // await _mongoDBContainer .CleanUpAsync();
94
+ await _mongoDBTestContainer . StopAsync ( ) ;
95
+ await _mongoDBTestContainer . CleanUpAsync ( ) ;
95
96
96
97
// _testOutputHelper.WriteLine($"Mongo container State:{_mongoDBContainer.State}");
97
98
//_testOutputHelper.WriteLine("=STOP=");
0 commit comments