22using Microsoft . AspNetCore . Mvc . Testing ;
33using Microsoft . Kiota . Abstractions . Authentication ;
44using Microsoft . Kiota . Http . HttpClientLibrary ;
5+ using Microsoft . Kiota . Http . HttpClientLibrary . Middleware ;
56using TestBuildingBlocks ;
67using Xunit . Abstractions ;
78
89namespace OpenApiKiotaEndToEndTests ;
910
1011internal sealed class TestableHttpClientRequestAdapterFactory : IDisposable
1112{
12- private readonly XUnitLogHttpMessageHandler _logHttpMessageHandler ;
13+ private readonly HeadersInspectionHandler _headersInspectionHandler = new ( ) ;
1314 private readonly SetQueryStringHttpMessageHandler _queryStringMessageHandler = new ( ) ;
15+ private readonly XUnitLogHttpMessageHandler _logHttpMessageHandler ;
1416
1517 public TestableHttpClientRequestAdapterFactory ( ITestOutputHelper testOutputHelper )
1618 {
@@ -24,11 +26,14 @@ public HttpClientRequestAdapter CreateAdapter<TStartup>(WebApplicationFactory<TS
2426 {
2527 ArgumentNullException . ThrowIfNull ( webApplicationFactory ) ;
2628
27- IList < DelegatingHandler > delegatingHandlers = KiotaClientFactory . CreateDefaultHandlers ( ) ;
28- delegatingHandlers . Add ( _queryStringMessageHandler ) ;
29- delegatingHandlers . Add ( _logHttpMessageHandler ) ;
30- HttpClient httpClient = webApplicationFactory . CreateDefaultClient ( delegatingHandlers . ToArray ( ) ) ;
29+ DelegatingHandler [ ] handlers =
30+ [
31+ _headersInspectionHandler ,
32+ _queryStringMessageHandler ,
33+ _logHttpMessageHandler
34+ ] ;
3135
36+ HttpClient httpClient = webApplicationFactory . CreateDefaultClient ( handlers ) ;
3237 return new HttpClientRequestAdapter ( new AnonymousAuthenticationProvider ( ) , httpClient : httpClient ) ;
3338 }
3439
0 commit comments