Unit test services.AddHttpClient(): dotnet core V2.2

I am working on a .NET Core Web API project with version 2.2. I need to do unit testing with NSubstitute, in order to achieve complete code coverage for the following method:

public void ConfigureServices(IServiceCollection services) {
    services.AddHttpClient("myapi", (serviceProvider, client) = >{
    var config = serviceProvider.GetService < IConfiguration > ();
    client.BaseAddress = new URI(config["mybaseURL"]);


Can someone provide me with guidance on how to accomplish this? Thank you in advance.

Here’s an example of how to unit test this method using NSubstitute:

public void ConfigureServices_AddHttpClient_AddsHttpClientToServices()
    // Arrange
    var services = Substitute.For<IServiceCollection>();
    var serviceProvider = Substitute.For<IServiceProvider>();
    var config = Substitute.For<IConfiguration>();

    // Act

    // Assert
    services.Received().AddHttpClient("myapi", Arg.Any<Action<IServiceProvider, HttpClient>>());

Note that MyClass should be replaced with the actual name of the class containing the ConfigureServices method. This test verifies that the AddHttpClient method is called with the expected arguments when ConfigureServices is called.