Skip to content

Commit 527b453

Browse files
committed
Revert "osmos"
This reverts commit e7d3b73.
1 parent e7d3b73 commit 527b453

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

ManagedCode.Database.Tests/TestContainers/CosmosTestContainer.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,39 @@ public string GenerateId()
6161

6262
public async Task InitializeAsync()
6363
{
64-
if(_cosmosTestContainer.State != TestcontainersStates.Running)
64+
ushort publicPort = 0;
65+
66+
try
67+
{
6568
await _cosmosTestContainer.StartAsync();
6669

70+
containerExsist = false;
71+
}
72+
catch (Exception ex) //TODO catch name already using exception
73+
{
74+
containerExsist = true;
75+
}
76+
77+
if (!containerExsist)
78+
{
79+
publicPort = _cosmosTestContainer.GetMappedPublicPort(privatePort);
80+
}
81+
else
82+
{
83+
var listContainers = await _dockerClient.Containers.ListContainersAsync(new ContainersListParameters());
84+
85+
ContainerListResponse containerListResponse = listContainers.FirstOrDefault(container => container.Names.Contains($"/{containerName}"));
86+
87+
if(containerListResponse != null)
88+
publicPort = containerListResponse.Ports.Single(port => port.PrivatePort == privatePort).PublicPort;
89+
}
90+
6791
_database = new CosmosDatabase(new CosmosOptions
6892
{
6993
ConnectionString =
70-
$"AccountEndpoint=https://localhost:8081;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
94+
$"AccountEndpoint=https://localhost:{publicPort}/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
7195
DatabaseName = "database",
72-
CollectionName = $"collection{Guid.NewGuid().ToString("N").Take(8)}",
96+
CollectionName = $"testContainers",
7397
AllowTableCreation = true,
7498
CosmosClientOptions = new CosmosClientOptions()
7599
{
@@ -92,8 +116,8 @@ public async Task InitializeAsync()
92116

93117
public async Task DisposeAsync()
94118
{
95-
///await _database.DeleteAsync();
96-
//await _database.DisposeAsync();
119+
await _database.DeleteAsync();
120+
await _database.DisposeAsync();
97121
/*
98122
await _cosmosTestContainer.StopAsync();
99123
await _cosmosTestContainer.CleanUpAsync();*/

0 commit comments

Comments
 (0)