Testcontainers CosmosDB / WebApplication Factory ConnectionString Not Working
anyone familiar with WebApplicationFactory / Testcontainers?
The below is giving me
someone mentioned ports earlier?
The below is giving me
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.public abstract class IntegrationTest
{
protected readonly HttpClient TestClient;
protected CosmosDbContainer cosmosDbContainer;
protected IntegrationTest()
{
cosmosDbContainer = new CosmosDbBuilder()
.WithImage("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest")
.Build();
cosmosDbContainer.StartAsync().GetAwaiter().GetResult();
var appFactory = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureServices(services =>
{
var connectionString = cosmosDbContainer.GetConnectionString();
var cosmosOptions = new CosmosClientOptions()
{
Serializer = new CosmosJsonSerializer()
};
services.RemoveAll(typeof(CosmosClient));
services.AddSingleton(new CosmosClient(connectionString, cosmosOptions));
});
builder.UseEnvironment("Development");
});
TestClient = appFactory.CreateClient();
}
public void Dispose()
{
cosmosDbContainer.DisposeAsync();
}
}public abstract class IntegrationTest
{
protected readonly HttpClient TestClient;
protected CosmosDbContainer cosmosDbContainer;
protected IntegrationTest()
{
cosmosDbContainer = new CosmosDbBuilder()
.WithImage("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest")
.Build();
cosmosDbContainer.StartAsync().GetAwaiter().GetResult();
var appFactory = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureServices(services =>
{
var connectionString = cosmosDbContainer.GetConnectionString();
var cosmosOptions = new CosmosClientOptions()
{
Serializer = new CosmosJsonSerializer()
};
services.RemoveAll(typeof(CosmosClient));
services.AddSingleton(new CosmosClient(connectionString, cosmosOptions));
});
builder.UseEnvironment("Development");
});
TestClient = appFactory.CreateClient();
}
public void Dispose()
{
cosmosDbContainer.DisposeAsync();
}
}someone mentioned ports earlier?