Skip to content

Commit 97cfbc8

Browse files
author
Oleksii Sokol
committed
mongo test
1 parent 9ae4f57 commit 97cfbc8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ManagedCode.Database.Tests/TestContainers/MongoDBTestContainer.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class MongoDBTestContainer : ITestContainer<ObjectId, TestMongoDBItem>
1919
private readonly TestcontainersContainer _mongoDBTestContainer;
2020
private MongoDBDatabase _dbDatabase;
2121
private DockerClient _dockerClient;
22-
private const string containerName = "mongoContainer";
22+
private string containerName = $"mongoContainer{Guid.NewGuid().ToString("N")}";
2323
private const ushort privatePort = 27017;
2424
private bool containerExsist = false;
2525

@@ -36,7 +36,7 @@ public MongoDBTestContainer()
3636
.UntilPortIsAvailable(privatePort))
3737
.Build();
3838

39-
_dockerClient = new DockerClientConfiguration().CreateClient();
39+
// _dockerClient = new DockerClientConfiguration().CreateClient();
4040
}
4141

4242
public IDatabaseCollection<ObjectId, TestMongoDBItem> Collection =>
@@ -51,9 +51,10 @@ public async Task InitializeAsync()
5151
{
5252
ushort publicPort = 0;
5353

54+
await _mongoDBTestContainer.StartAsync();
55+
/*
5456
try
5557
{
56-
await _mongoDBTestContainer.StartAsync();
5758
5859
containerExsist = false;
5960
}
@@ -73,11 +74,11 @@ public async Task InitializeAsync()
7374
ContainerListResponse containerListResponse = listContainers.Single(container => container.Names.Contains($"/{containerName}"));
7475
7576
publicPort = containerListResponse.Ports.Single(port => port.PrivatePort == privatePort).PublicPort;
76-
}
77+
}*/
7778

7879
_dbDatabase = new MongoDBDatabase(new MongoDBOptions()
7980
{
80-
ConnectionString = $"mongodb://localhost:{publicPort}",
81+
ConnectionString = $"mongodb://localhost:{_mongoDBTestContainer.GetMappedPublicPort(privatePort)}",
8182
DataBaseName = $"db{Guid.NewGuid().ToString("N")}",
8283
});
8384

@@ -90,8 +91,8 @@ public async Task InitializeAsync()
9091
public async Task DisposeAsync()
9192
{
9293
await _dbDatabase.DisposeAsync();
93-
// await _mongoDBContainer.StopAsync();
94-
//await _mongoDBContainer.CleanUpAsync();
94+
await _mongoDBTestContainer.StopAsync();
95+
await _mongoDBTestContainer.CleanUpAsync();
9596

9697
// _testOutputHelper.WriteLine($"Mongo container State:{_mongoDBContainer.State}");
9798
//_testOutputHelper.WriteLine("=STOP=");

0 commit comments

Comments
 (0)