@@ -61,39 +61,15 @@ public string GenerateId()
61
61
62
62
public async Task InitializeAsync ( )
63
63
{
64
- ushort publicPort = 0 ;
65
-
66
- try
67
- {
64
+ if ( _cosmosTestContainer . State != TestcontainersStates . Running )
68
65
await _cosmosTestContainer . StartAsync ( ) ;
69
66
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
-
91
67
_database = new CosmosDatabase ( new CosmosOptions
92
68
{
93
69
ConnectionString =
94
- $ "AccountEndpoint=https://localhost:{ publicPort } / ;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
70
+ $ "AccountEndpoint=https://localhost:8081 ;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
95
71
DatabaseName = "database" ,
96
- CollectionName = $ "testContainers ",
72
+ CollectionName = $ "collection { Guid . NewGuid ( ) . ToString ( "N" ) . Take ( 8 ) } ",
97
73
AllowTableCreation = true ,
98
74
CosmosClientOptions = new CosmosClientOptions ( )
99
75
{
@@ -116,8 +92,8 @@ public async Task InitializeAsync()
116
92
117
93
public async Task DisposeAsync ( )
118
94
{
119
- await _database . DeleteAsync ( ) ;
120
- await _database . DisposeAsync ( ) ;
95
+ /// await _database.DeleteAsync();
96
+ // await _database.DisposeAsync();
121
97
/*
122
98
await _cosmosTestContainer.StopAsync();
123
99
await _cosmosTestContainer.CleanUpAsync();*/
0 commit comments