Skip to content

Commit a649673

Browse files
author
Oleksii Sokol
committed
test
1 parent 72289af commit a649673

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

.github/workflows/dotnet.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ jobs:
1414

1515
build-and-test:
1616
runs-on: ubuntu-latest
17+
services:
18+
cosmos:
19+
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
20+
container_name: cosmos
21+
ports:
22+
- 8081:8081
23+
- 10251:10251
24+
- 10252:10252
25+
- 10253:10253
26+
- 10254:10254
27+
expose:
28+
- "8081"
29+
- "10251-10255"
30+
environment:
31+
- AZURE_COSMOS_EMULATOR_PARTITION_COUNT=6
32+
- AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=false
33+
- AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1
1734
steps:
1835
- uses: actions/checkout@v3
1936
- name: Setup .NET

ManagedCode.Database.Tests/TestContainers/CosmosTestContainer.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public class CosmosTestContainer : ITestContainer<string, TestCosmosItem>,
2222
private CosmosDatabase _database;
2323
private DockerClient _dockerClient;
2424
private const string containerName = "cosmosContainer";
25-
private ushort privatePort = 8081;
25+
private const ushort privatePort = 8081;
2626
private bool containerExsist = false;
2727
private string containerId;
2828

2929
public CosmosTestContainer()
3030
{
31-
_cosmosTestContainer = new TestcontainersBuilder<TestcontainersContainer>()
31+
/*_cosmosTestContainer = new TestcontainersBuilder<TestcontainersContainer>()
3232
.WithImage("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator")
3333
.WithName(containerName)
3434
.WithExposedPort(8081)
@@ -50,7 +50,7 @@ public CosmosTestContainer()
5050
.UntilPortIsAvailable(privatePort))
5151
.Build();
5252
53-
_dockerClient = new DockerClientConfiguration().CreateClient();
53+
_dockerClient = new DockerClientConfiguration().CreateClient();*/
5454
}
5555

5656
public IDatabaseCollection<string, TestCosmosItem> Collection =>
@@ -63,7 +63,7 @@ public string GenerateId()
6363

6464
public async Task InitializeAsync()
6565
{
66-
ushort publicPort = privatePort;
66+
/*ushort publicPort = privatePort;
6767
6868
try
6969
{
@@ -76,25 +76,24 @@ public async Task InitializeAsync()
7676
containerExsist = true;
7777
}
7878
79-
/*if (!containerExsist)
79+
if (!containerExsist)
8080
{
8181
publicPort = _cosmosTestContainer.GetMappedPublicPort(privatePort);
8282
containerId = _cosmosTestContainer.Id;
8383
}
8484
else
85-
{*/
85+
{
8686
var listContainers = await _dockerClient.Containers.ListContainersAsync(new ContainersListParameters());
8787
8888
ContainerListResponse containerListResponse = listContainers.FirstOrDefault(container => container.Names.Contains($"/{containerName}"));
8989
9090
if (containerListResponse != null)
9191
{
92-
privatePort = containerListResponse.Ports.LastOrDefault().PrivatePort;
9392
publicPort = containerListResponse.Ports.Single(port => port.PrivatePort == privatePort).PublicPort;
9493
9594
containerId = containerListResponse.ID;
9695
}
97-
// }
96+
}*/
9897

9998
var httpMessageHandler = new HttpClientHandler()
10099
{
@@ -105,7 +104,7 @@ public async Task InitializeAsync()
105104
_database = new CosmosDatabase(new CosmosOptions
106105
{
107106
ConnectionString =
108-
$"AccountEndpoint=https://localhost:{publicPort}/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
107+
$"AccountEndpoint=https://localhost:8081;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
109108
DatabaseName = "database",
110109
CollectionName = $"testContainer",
111110
AllowTableCreation = true,

0 commit comments

Comments
 (0)