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);
 })


I tried removing the existing CosmosClient service like this, but it doesn't seem to work:
services.RemoveAll(typeof(CosmosClient));
Was this page helpful?