C
C#2mo ago
kmanjt

How to Override CosmosClient Configuration in WebApplicationFactory for Integration Testing

Hi everyone, I'm trying to override the CosmosClient configuration in my Program.cs for my integration tests using WebApplicationFactory, but I'm running into issues. Here's the relevant code from Program.cs:
clientsBuilder.AddClient<CosmosClient, CosmosClientOptions>(options =>
{
options.Serializer = new CosmosJsonSerializer();
options.ApplicationRegion = cosmosConfig.ApplicationRegion;
return new CosmosClient(cosmosConfig.ConnectionString, options);
})
clientsBuilder.AddClient<CosmosClient, CosmosClientOptions>(options =>
{
options.Serializer = new CosmosJsonSerializer();
options.ApplicationRegion = cosmosConfig.ApplicationRegion;
return new CosmosClient(cosmosConfig.ConnectionString, options);
})
I tried removing the existing CosmosClient service like this, but it doesn't seem to work:
services.RemoveAll(typeof(CosmosClient));
services.RemoveAll(typeof(CosmosClient));
0 Replies
No replies yetBe the first to reply to this messageJoin