Repository: microsoft/semantic-kernel
File: dotnet/src/Connectors/Connectors.OpenAI.UnitTests/Extensions/KernelBuilderExtensionsTests.cs (C#)

Code before:
            .Build()
            .GetRequiredService<IAudioToTextService>();

        // Assert
        Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]);
    }

    [Fact]
    public void ItCanAddEmbeddingGeneratorWithHttpClient()
    {
        // Arrange
        var customEndpoint = new Uri("https://custom.proxy.url/openai/v1/");
        var httpClient = new System.Net.Http.HttpClient
        {
            BaseAddress = customEndpoint
        };
        var sut = Kernel.CreateBuilder();

        // Act
        var kernel = sut.AddOpenAIEmbeddingGenerator("model", "key", httpClient: httpClient)
            .Build();
        var service = kernel.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();

        // Assert
        Assert.NotNull(service);
        Assert.Equal("model", service.GetService<EmbeddingGeneratorMetadata>()!.DefaultModelId);
    }

    [Fact]
    [Obsolete(ObsoleteMessage)]
    public void ItCanAddFileService()
    {
        // Arrange
        var sut = Kernel.CreateBuilder();

        // Act
        var service = sut.AddOpenAIFiles("key").Build()
            .GetRequiredService<OpenAIFileService>();
    }

    #region Chat completion

    [Theory]
    [InlineData(InitializationType.ApiKey)]
    [InlineData(InitializationType.OpenAIClientInline)]
    [InlineData(InitializationType.OpenAIClientInServiceProvider)]
    public void KernelBuilderAddOpenAIChatCompletionAddsValidService(InitializationType type)
    {
        // Arrange
        var client = new OpenAIClient(new ApiKeyCredential("key"));
        var builder = Kernel.CreateBuilder();

Review comment (bug):
If you want this test to validate the issue in this bug, you need to assert that the base address got through.  In the debugger, I can see that `service` will actually have a member, `_endpoint`, but this is not part of the interface and is private.  Still, you could do would be something like:

```cs
var endpointAddressField = service.GetType().GetField("_endpointAddress", BindingFlags.Instance | BindingFlags.NonPublic);

Assert.NotNull(endpointAddressField);
var endpointAddressValue = endpointAddressField.GetValue(_embeddingService).ToString();
Assert.Equal(endpointAddressValue, customEndpoint); // Probably need to make this case insensitive.
```

This is easy and works, but is not futureproof.  I am not sure of what is and is not allowed/required of tests here, so this may not be appropriate.

Another option would be to give `httpClient` a custom `HttpClientHandler` that overrides `SendAsync()` to record the request URI in a member variable, then swallow the call and reply with a fake response.  (You do not need to actually send the request, just see where it is being sent.)  You could then call `service.GenerateAsync()` to trigger the call to `SendAsync()`.  After the call to `service.GenerateAsync()` finishes, you can check the stored value of the request URI in your custom handler.

This all may not be worth it.  I just wanted to share that I think the test as-is will pass without the fix.  (The way I debugged the original issue was using a custom `HttpClient` with a custom handler.)  If this is overkill for the current situation, fair enough.

Code after:
            .Build()
            .GetRequiredService<IAudioToTextService>();

        // Assert
        Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]);
    }

    [Fact]
    public void ItCanAddEmbeddingGeneratorWithHttpClient()
    {
        // Arrange
        var customEndpoint = new Uri("https://custom.proxy.url/openai/v1/");
        using var httpClient = new System.Net.Http.HttpClient { BaseAddress = customEndpoint };
        var sut = Kernel.CreateBuilder();

        // Act
        var kernel = sut.AddOpenAIEmbeddingGenerator("model", "key", httpClient: httpClient)
            .Build();
        var service = kernel.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();

        // Assert
        Assert.NotNull(service);
        Assert.Equal(customEndpoint, service.GetService<EmbeddingGeneratorMetadata>()!.ProviderUri);
    }

    [Fact]
    [Obsolete(ObsoleteMessage)]
    public void ItCanAddFileService()
    {
        // Arrange
        var sut = Kernel.CreateBuilder();

        // Act
        var service = sut.AddOpenAIFiles("key").Build()
            .GetRequiredService<OpenAIFileService>();
    }

    #region Chat completion

    [Theory]
    [InlineData(InitializationType.ApiKey)]
    [InlineData(InitializationType.OpenAIClientInline)]
    [InlineData(InitializationType.OpenAIClientInServiceProvider)]
    public void KernelBuilderAddOpenAIChatCompletionAddsValidService(InitializationType type)
    {
        // Arrange
        var client = new OpenAIClient(new ApiKeyCredential("key"));
        var builder = Kernel.CreateBuilder();

        builder.Services.AddSingleton(client);