Skip to content

Commit e7d3b73

Browse files
committed
osmos
1 parent 810d118 commit e7d3b73

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

ManagedCode.Database.Tests/TestContainers/CosmosTestContainer.cs

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

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

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-
9167
_database = new CosmosDatabase(new CosmosOptions
9268
{
9369
ConnectionString =
94-
$"AccountEndpoint=https://localhost:{publicPort}/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
70+
$"AccountEndpoint=https://localhost:8081;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
9571
DatabaseName = "database",
96-
CollectionName = $"testContainers",
72+
CollectionName = $"collection{Guid.NewGuid().ToString("N").Take(8)}",
9773
AllowTableCreation = true,
9874
CosmosClientOptions = new CosmosClientOptions()
9975
{
@@ -116,8 +92,8 @@ public async Task InitializeAsync()
11692

11793
public async Task DisposeAsync()
11894
{
119-
await _database.DeleteAsync();
120-
await _database.DisposeAsync();
95+
///await _database.DeleteAsync();
96+
//await _database.DisposeAsync();
12197
/*
12298
await _cosmosTestContainer.StopAsync();
12399
await _cosmosTestContainer.CleanUpAsync();*/

0 commit comments

Comments
 (0)