C#C
C#3y ago
1 reply
Elykx

❔ How to implement integration test asp.net with .net 7 using client certificates ?

When i try to create an httpclient custom in a WebApplicationFactory, the test server is not running
builder.ConfigureTestServices(services =>
        {
            services
                .AddHttpClient("client-with-certificate", client =>
                {
                    client.BaseAddress = new Uri("https://localhost");      
                })
                .ConfigurePrimaryHttpMessageHandler(() =>
                {
                    var handler = new HttpClientHandler(); 
                    handler.ClientCertificates.Add(clientCertificate); 
                    return handler;
                });
        });
Was this page helpful?