From e6e1ed34e1c3553139c8ca9efe32e1ad184c4c79 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Tue, 9 Sep 2025 14:28:45 +0700 Subject: [PATCH 01/11] feat: support-passing-HttpClient --- Client.Test/InfluxDBClientWriteTest.cs | 23 ++++++++++++ Client.Test/Internal/FlightSqlClientTest.cs | 10 +++--- Client.Test/Internal/RestClientTest.cs | 2 +- Client/Config/ClientConfig.cs | 8 +++++ Client/InfluxDBClient.cs | 40 ++++++++++++++++++--- 5 files changed, 72 insertions(+), 11 deletions(-) diff --git a/Client.Test/InfluxDBClientWriteTest.cs b/Client.Test/InfluxDBClientWriteTest.cs index 80ccd14..579d9a0 100644 --- a/Client.Test/InfluxDBClientWriteTest.cs +++ b/Client.Test/InfluxDBClientWriteTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; +using System.Net.Http; using System.Threading.Tasks; using InfluxDB3.Client.Config; using InfluxDB3.Client.Write; @@ -490,4 +491,26 @@ public void WriteNoSyncTrueNotSupported() "Server doesn't support write with NoSync=true (supported by InfluxDB 3 Core/Enterprise servers only).")); }); } + + [Test] + public void TestSetHttpClient() + { + + MockServer + .Given(Request.Create().WithPath("/api/v3/write").UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + + var httpClient = new HttpClient(new HttpClientHandler()); + _client = new InfluxDBClient(new ClientConfig + { + Host = MockServerUrl, + Token = "my-token", + Database = "my-database", + HttpClient = httpClient + }); + + httpClient.PostAsync("", new StringContent("")).Wait(); + Assert.That(httpClient.BaseAddress, Is.EqualTo(new Uri(MockServerUrl)));; + Assert.Pass(); + } } \ No newline at end of file diff --git a/Client.Test/Internal/FlightSqlClientTest.cs b/Client.Test/Internal/FlightSqlClientTest.cs index 653b01a..e58cb61 100644 --- a/Client.Test/Internal/FlightSqlClientTest.cs +++ b/Client.Test/Internal/FlightSqlClientTest.cs @@ -22,7 +22,7 @@ public void SetUp() Timeout = TimeSpan.FromSeconds(45) }; - _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateAndConfigureHttpClient(config)); + _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateOrGetHttpClient(config)); } [TearDown] @@ -108,7 +108,7 @@ public void HeadersMetadataFromConfig() } }; - _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateAndConfigureHttpClient(config)); + _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateOrGetHttpClient(config)); var prepareHeadersMetadata = _flightSqlClient.PrepareHeadersMetadata(new Dictionary()); @@ -139,7 +139,7 @@ public void HeadersMetadataFromRequestArePreferred() } }; - _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateAndConfigureHttpClient(config)); + _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateOrGetHttpClient(config)); var prepareHeadersMetadata = _flightSqlClient.PrepareHeadersMetadata(new Dictionary { { "X-Tracing-Id", "258" } }); @@ -170,7 +170,7 @@ public void UserAgentHeaderNotChanged() } }; - _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateAndConfigureHttpClient(config)); + _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateOrGetHttpClient(config)); var prepareHeadersMetadata = _flightSqlClient.PrepareHeadersMetadata(new Dictionary { { "user-agent", "another/user-agent" } }); @@ -199,7 +199,7 @@ public void TestGrpcCallOptions() }; Assert.DoesNotThrow(() => - _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateAndConfigureHttpClient(config))); + _flightSqlClient = new FlightSqlClient(config, InfluxDBClient.CreateOrGetHttpClient(config))); } } \ No newline at end of file diff --git a/Client.Test/Internal/RestClientTest.cs b/Client.Test/Internal/RestClientTest.cs index 21bdd5a..07a02bb 100644 --- a/Client.Test/Internal/RestClientTest.cs +++ b/Client.Test/Internal/RestClientTest.cs @@ -294,7 +294,7 @@ public void Timeout() private void CreateAndConfigureRestClient(ClientConfig config) { - _httpClient = InfluxDBClient.CreateAndConfigureHttpClient(config); + _httpClient = InfluxDBClient.CreateOrGetHttpClient(config); _client = new RestClient(config, _httpClient); } diff --git a/Client/Config/ClientConfig.cs b/Client/Config/ClientConfig.cs index 3c208f6..f196a36 100644 --- a/Client/Config/ClientConfig.cs +++ b/Client/Config/ClientConfig.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Net; +using System.Net.Http; using System.Web; using InfluxDB3.Client.Write; @@ -200,6 +201,13 @@ public string Host /// public QueryOptions QueryOptions { get; set; } + /// + /// User-defined HttpClient. + /// Influxdb client will add an authentication header and base url to HttpClient. The rest is up to the user. + /// User will be responsible for closing the HttpClient. + /// + public HttpClient? HttpClient { get; set; } + internal void Validate() { if (string.IsNullOrEmpty(Host)) diff --git a/Client/InfluxDBClient.cs b/Client/InfluxDBClient.cs index 4fed219..89317ac 100644 --- a/Client/InfluxDBClient.cs +++ b/Client/InfluxDBClient.cs @@ -343,7 +343,7 @@ public InfluxDBClient(ClientConfig config) config.Validate(); _config = config; - _httpClient = CreateAndConfigureHttpClient(_config); + _httpClient = CreateOrGetHttpClient(_config); FlightSqlClient = new FlightSqlClient(config: _config, httpClient: _httpClient); _restClient = new RestClient(config: _config, httpClient: _httpClient); _gzipHandler = new GzipHandler(config.WriteOptions != null ? config.WriteOptions.GzipThreshold : 0); @@ -840,7 +840,12 @@ await _restClient public void Dispose() { - _httpClient.Dispose(); + // _config.HttpClient == null means HttpClient is created by the library, not from the user. + // so the client will be responsible for disposing of the HttpClient. + if (_config.HttpClient == null) + { + _httpClient.Dispose(); + } FlightSqlClient.Dispose(); _disposed = true; } @@ -876,7 +881,26 @@ private static StringBuilder ToLineProtocolBody(IEnumerable data, Write return sb; } - internal static HttpClient CreateAndConfigureHttpClient(ClientConfig config) + internal static HttpClient CreateOrGetHttpClient(ClientConfig config) + { + if (config.HttpClient == null) + { + return CreateHttpClient(config); + } + + var httpClient = config.HttpClient; + if (httpClient.BaseAddress == null) + { + httpClient.BaseAddress = new Uri(config.Host); + } + if (!string.IsNullOrEmpty(config.AuthScheme)) + { + _setDefaultHeader(httpClient, config); + } + return config.HttpClient; + } + + private static HttpClient CreateHttpClient(ClientConfig config) { var handler = new HttpClientHandler(); if (handler.SupportsRedirectConfiguration) @@ -920,13 +944,19 @@ internal static HttpClient CreateAndConfigureHttpClient(ClientConfig config) client.DefaultRequestHeaders.UserAgent.ParseAdd(AssemblyHelper.GetUserAgent()); if (!string.IsNullOrEmpty(config.Token)) { - string authScheme = string.IsNullOrEmpty(config.AuthScheme) ? "Token" : config.AuthScheme!; - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, config.Token); + _setDefaultHeader(client, config); } return client; } + private static void _setDefaultHeader(HttpClient httpClient, ClientConfig config) + { + httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(AssemblyHelper.GetUserAgent()); + var authScheme = string.IsNullOrEmpty(config.AuthScheme) ? "Token" : config.AuthScheme!; + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, config.Token); + } + private static string OptionMessage(string property) { return $"Please specify the '{property}' as a method parameter or use default configuration " + From 866b91ad3cd0db2c7a360bc50e0708df87075a55 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Tue, 9 Sep 2025 14:36:54 +0700 Subject: [PATCH 02/11] chore: dotnet format --- Client.Test/InfluxDBClientWriteTest.cs | 2 +- Client.Test/MockHttpsServerTest.cs | 2 +- Client.Test/MockServerTest.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Client.Test/InfluxDBClientWriteTest.cs b/Client.Test/InfluxDBClientWriteTest.cs index 579d9a0..4e897e8 100644 --- a/Client.Test/InfluxDBClientWriteTest.cs +++ b/Client.Test/InfluxDBClientWriteTest.cs @@ -510,7 +510,7 @@ public void TestSetHttpClient() }); httpClient.PostAsync("", new StringContent("")).Wait(); - Assert.That(httpClient.BaseAddress, Is.EqualTo(new Uri(MockServerUrl)));; + Assert.That(httpClient.BaseAddress, Is.EqualTo(new Uri(MockServerUrl))); ; Assert.Pass(); } } \ No newline at end of file diff --git a/Client.Test/MockHttpsServerTest.cs b/Client.Test/MockHttpsServerTest.cs index 2f3ec9c..92a3426 100644 --- a/Client.Test/MockHttpsServerTest.cs +++ b/Client.Test/MockHttpsServerTest.cs @@ -4,7 +4,7 @@ namespace InfluxDB3.Client.Test; -public class MockHttpsServerTest +public abstract class MockHttpsServerTest { internal WireMockServer MockHttpsServer; internal string MockHttpsServerUrl; diff --git a/Client.Test/MockServerTest.cs b/Client.Test/MockServerTest.cs index 99fcec0..a19faa7 100644 --- a/Client.Test/MockServerTest.cs +++ b/Client.Test/MockServerTest.cs @@ -3,7 +3,7 @@ namespace InfluxDB3.Client.Test; -public class MockServerTest +public abstract class MockServerTest { internal WireMockServer MockServer, MockProxy; internal string MockServerUrl, MockProxyUrl; From 68c2c675f45e25eb3d90d8e0f2478e9a5cd655ac Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Tue, 9 Sep 2025 14:58:50 +0700 Subject: [PATCH 03/11] refactor: function name --- Client.Test/InfluxDBClientWriteTest.cs | 1 + Client/InfluxDBClient.cs | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Client.Test/InfluxDBClientWriteTest.cs b/Client.Test/InfluxDBClientWriteTest.cs index 4e897e8..9a282dd 100644 --- a/Client.Test/InfluxDBClientWriteTest.cs +++ b/Client.Test/InfluxDBClientWriteTest.cs @@ -505,6 +505,7 @@ public void TestSetHttpClient() { Host = MockServerUrl, Token = "my-token", + AuthScheme = "", Database = "my-database", HttpClient = httpClient }); diff --git a/Client/InfluxDBClient.cs b/Client/InfluxDBClient.cs index 89317ac..3d06e14 100644 --- a/Client/InfluxDBClient.cs +++ b/Client/InfluxDBClient.cs @@ -895,7 +895,7 @@ internal static HttpClient CreateOrGetHttpClient(ClientConfig config) } if (!string.IsNullOrEmpty(config.AuthScheme)) { - _setDefaultHeader(httpClient, config); + _setAuthenticationHeader(httpClient, config); } return config.HttpClient; } @@ -944,15 +944,14 @@ private static HttpClient CreateHttpClient(ClientConfig config) client.DefaultRequestHeaders.UserAgent.ParseAdd(AssemblyHelper.GetUserAgent()); if (!string.IsNullOrEmpty(config.Token)) { - _setDefaultHeader(client, config); + _setAuthenticationHeader(client, config); } return client; } - private static void _setDefaultHeader(HttpClient httpClient, ClientConfig config) + private static void _setAuthenticationHeader(HttpClient httpClient, ClientConfig config) { - httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(AssemblyHelper.GetUserAgent()); var authScheme = string.IsNullOrEmpty(config.AuthScheme) ? "Token" : config.AuthScheme!; httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, config.Token); } From b97a32f9f197383a310c5fee5c783a5972982788 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Tue, 9 Sep 2025 15:07:12 +0700 Subject: [PATCH 04/11] chore: add test --- Client.Test/InfluxDBClientWriteTest.cs | 1 - Client/InfluxDBClient.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Client.Test/InfluxDBClientWriteTest.cs b/Client.Test/InfluxDBClientWriteTest.cs index 9a282dd..4e897e8 100644 --- a/Client.Test/InfluxDBClientWriteTest.cs +++ b/Client.Test/InfluxDBClientWriteTest.cs @@ -505,7 +505,6 @@ public void TestSetHttpClient() { Host = MockServerUrl, Token = "my-token", - AuthScheme = "", Database = "my-database", HttpClient = httpClient }); diff --git a/Client/InfluxDBClient.cs b/Client/InfluxDBClient.cs index 3d06e14..0353382 100644 --- a/Client/InfluxDBClient.cs +++ b/Client/InfluxDBClient.cs @@ -893,7 +893,7 @@ internal static HttpClient CreateOrGetHttpClient(ClientConfig config) { httpClient.BaseAddress = new Uri(config.Host); } - if (!string.IsNullOrEmpty(config.AuthScheme)) + if (!string.IsNullOrEmpty(config.Token)) { _setAuthenticationHeader(httpClient, config); } From c287eb17f8d899934a49138cebfc9de7793d95d3 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Tue, 9 Sep 2025 15:13:07 +0700 Subject: [PATCH 05/11] chore: CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c010f..3776d69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## 1.4.0 [unreleased] +### Features + +1. [#174](https://github.com/InfluxCommunity/influxdb3-csharp/pull/174): Support passing HttpClient to InfluxDBClient. + ## 1.3.0 [2025-08-12] ### Features From 62ac577014ea13734accc683fb7e990feddae32e Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Wed, 10 Sep 2025 07:58:19 +0700 Subject: [PATCH 06/11] chore: update doc --- Client/Config/ClientConfig.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Client/Config/ClientConfig.cs b/Client/Config/ClientConfig.cs index f196a36..7d318af 100644 --- a/Client/Config/ClientConfig.cs +++ b/Client/Config/ClientConfig.cs @@ -27,6 +27,7 @@ namespace InfluxDB3.Client.Config; /// - Proxy: The HTTP proxy URL. Default is not set. /// - WriteOptions: Write options. /// - QueryOptions Query options. +/// - HttpClient: The HttpClient will be used for Write and Query apis. /// /// /// If you want create client with custom options, you can use the following code: @@ -203,8 +204,8 @@ public string Host /// /// User-defined HttpClient. - /// Influxdb client will add an authentication header and base url to HttpClient. The rest is up to the user. - /// User will be responsible for closing the HttpClient. + /// Influxdb client will add an authentication header and base url to HttpClient. The rest is up to the users. + /// Users will be responsible for closing the HttpClient. /// public HttpClient? HttpClient { get; set; } From 39d5c82c1be1b64e14d5cdf9ba6ab03586cbe83d Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Wed, 10 Sep 2025 09:03:21 +0700 Subject: [PATCH 07/11] chore: add more test --- Client.Test/InfluxDBClientWriteTest.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Client.Test/InfluxDBClientWriteTest.cs b/Client.Test/InfluxDBClientWriteTest.cs index 4e897e8..5a768e0 100644 --- a/Client.Test/InfluxDBClientWriteTest.cs +++ b/Client.Test/InfluxDBClientWriteTest.cs @@ -513,4 +513,28 @@ public void TestSetHttpClient() Assert.That(httpClient.BaseAddress, Is.EqualTo(new Uri(MockServerUrl))); ; Assert.Pass(); } + + [Test] + public void TestCheckHttpClientStillOpen() + { + MockServer + .Given(Request.Create().WithPath("/test").UsingGet()) + .RespondWith( + Response.Create() + .WithStatusCode(HttpStatusCode.OK) + .WithBody("Still ok")); + + var httpClient = new HttpClient(new HttpClientHandler()); + _client = new InfluxDBClient(new ClientConfig + { + Host = MockServerUrl, + Token = "my-token", + Database = "my-database", + HttpClient = httpClient + }); + _client.Dispose(); + + var httpResponseMessage = httpClient.Send(new HttpRequestMessage(HttpMethod.Get, "test")); + Assert.That(httpResponseMessage.Content.ReadAsStringAsync().Result, Is.EqualTo("Still ok")); + } } \ No newline at end of file From 2718499d77e37755f98af9e40a74e446ae6f5a99 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Wed, 10 Sep 2025 20:07:43 +0700 Subject: [PATCH 08/11] fix: refactor CreateOrGetHttpClient function --- Client/InfluxDBClient.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Client/InfluxDBClient.cs b/Client/InfluxDBClient.cs index 0353382..90b1e1e 100644 --- a/Client/InfluxDBClient.cs +++ b/Client/InfluxDBClient.cs @@ -883,21 +883,23 @@ private static StringBuilder ToLineProtocolBody(IEnumerable data, Write internal static HttpClient CreateOrGetHttpClient(ClientConfig config) { - if (config.HttpClient == null) + var httpClient = config.HttpClient; + if (httpClient == null) { - return CreateHttpClient(config); + httpClient = CreateHttpClient(config); } - var httpClient = config.HttpClient; if (httpClient.BaseAddress == null) { httpClient.BaseAddress = new Uri(config.Host); } + if (!string.IsNullOrEmpty(config.Token)) { _setAuthenticationHeader(httpClient, config); } - return config.HttpClient; + + return httpClient; } private static HttpClient CreateHttpClient(ClientConfig config) @@ -940,12 +942,7 @@ private static HttpClient CreateHttpClient(ClientConfig config) { Timeout = config.Timeout }; - client.DefaultRequestHeaders.UserAgent.ParseAdd(AssemblyHelper.GetUserAgent()); - if (!string.IsNullOrEmpty(config.Token)) - { - _setAuthenticationHeader(client, config); - } return client; } From d3f0acc3e7e4636589768d6e9ab27de4ffe256ca Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Wed, 10 Sep 2025 20:22:36 +0700 Subject: [PATCH 09/11] feat: improve test case --- Client.Test/InfluxDBClientWriteTest.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Client.Test/InfluxDBClientWriteTest.cs b/Client.Test/InfluxDBClientWriteTest.cs index 5a768e0..bbc98f9 100644 --- a/Client.Test/InfluxDBClientWriteTest.cs +++ b/Client.Test/InfluxDBClientWriteTest.cs @@ -500,7 +500,10 @@ public void TestSetHttpClient() .Given(Request.Create().WithPath("/api/v3/write").UsingPost()) .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); - var httpClient = new HttpClient(new HttpClientHandler()); + var httpClient = new HttpClient(); + httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("my-user-agent"); + httpClient.DefaultRequestHeaders.Add("X-Client-ID", "123"); + _client = new InfluxDBClient(new ClientConfig { Host = MockServerUrl, @@ -510,7 +513,12 @@ public void TestSetHttpClient() }); httpClient.PostAsync("", new StringContent("")).Wait(); - Assert.That(httpClient.BaseAddress, Is.EqualTo(new Uri(MockServerUrl))); ; + using (Assert.EnterMultipleScope()) + { + Assert.That(httpClient.BaseAddress, Is.EqualTo(new Uri(MockServerUrl))); ; + Assert.That(httpClient.DefaultRequestHeaders.UserAgent.ToString(), Is.EqualTo("my-user-agent")); + Assert.That(httpClient.DefaultRequestHeaders.GetValues("X-Client-ID").First(), Is.EqualTo("123")); + } Assert.Pass(); } From dfe897050de29319c559d3f121aaa51feb9aac72 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Wed, 10 Sep 2025 21:55:17 +0700 Subject: [PATCH 10/11] fix: correct test case --- Client.Test/InfluxDBClientWriteTest.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Client.Test/InfluxDBClientWriteTest.cs b/Client.Test/InfluxDBClientWriteTest.cs index bbc98f9..61d92d7 100644 --- a/Client.Test/InfluxDBClientWriteTest.cs +++ b/Client.Test/InfluxDBClientWriteTest.cs @@ -495,7 +495,6 @@ public void WriteNoSyncTrueNotSupported() [Test] public void TestSetHttpClient() { - MockServer .Given(Request.Create().WithPath("/api/v3/write").UsingPost()) .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); @@ -512,7 +511,7 @@ public void TestSetHttpClient() HttpClient = httpClient }); - httpClient.PostAsync("", new StringContent("")).Wait(); + _client.WriteRecordAsync("mem,tag=a field=1"); using (Assert.EnterMultipleScope()) { Assert.That(httpClient.BaseAddress, Is.EqualTo(new Uri(MockServerUrl))); ; From 302c9dcd416a5bbb86e41cf433681f728ec21c58 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Wed, 10 Sep 2025 22:19:23 +0700 Subject: [PATCH 11/11] fix: refactor test case --- Client.Test/InfluxDBClientWriteTest.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Client.Test/InfluxDBClientWriteTest.cs b/Client.Test/InfluxDBClientWriteTest.cs index 61d92d7..c97c09a 100644 --- a/Client.Test/InfluxDBClientWriteTest.cs +++ b/Client.Test/InfluxDBClientWriteTest.cs @@ -493,10 +493,10 @@ public void WriteNoSyncTrueNotSupported() } [Test] - public void TestSetHttpClient() + public async Task TestSetHttpClient() { MockServer - .Given(Request.Create().WithPath("/api/v3/write").UsingPost()) + .Given(Request.Create().WithPath("/api/v2/write").UsingPost()) .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); var httpClient = new HttpClient(); @@ -511,12 +511,12 @@ public void TestSetHttpClient() HttpClient = httpClient }); - _client.WriteRecordAsync("mem,tag=a field=1"); + await _client.WriteRecordAsync("mem,tag=a field=1"); + var requests = MockServer.LogEntries.ToList(); using (Assert.EnterMultipleScope()) { - Assert.That(httpClient.BaseAddress, Is.EqualTo(new Uri(MockServerUrl))); ; - Assert.That(httpClient.DefaultRequestHeaders.UserAgent.ToString(), Is.EqualTo("my-user-agent")); - Assert.That(httpClient.DefaultRequestHeaders.GetValues("X-Client-ID").First(), Is.EqualTo("123")); + Assert.That(requests[0].RequestMessage.Headers?["User-Agent"].First(), Is.EqualTo("my-user-agent")); + Assert.That(requests[0].RequestMessage.Headers["X-Client-ID"].First(), Is.EqualTo("123")); } Assert.Pass(); }