88using Newtonsoft . Json ;
99using Newtonsoft . Json . Linq ;
1010using Newtonsoft . Json . Serialization ;
11+ using IHttpClientBuilder = Microsoft . Extensions . DependencyInjection . IHttpClientBuilder ;
12+ using IHttpClientFactory = System . Net . Http . IHttpClientFactory ;
1113
1214namespace Dibix . Testing . Http
1315{
1416 public abstract class WebApiTestBase < TConfiguration > : DatabaseTestBase < TConfiguration > where TConfiguration : DatabaseConfigurationBase , new ( )
1517 {
1618 #region Protected Methods
17- protected virtual Task ExecuteTest ( Func < HttpTestContext , Task > testFlow ) => this . ExecuteTest ( testFlow , CreateTestContext ) ;
19+ protected virtual Task ExecuteTest ( Func < HttpTestContext , Task > testFlow ) => ExecuteTest ( testFlow , CreateTestContext ) ;
1820
1921 private protected async Task ExecuteTest < TTestContext > ( Func < TTestContext , Task > testFlow , Func < IHttpClientFactory , IHttpAuthorizationProvider , TTestContext > contextCreator ) where TTestContext : HttpTestContext
2022 {
21- HttpClientConfiguration clientSetup = new TestHttpClientConfiguration ( base . TestContext , base . Out , x => this . ConfigureClient ( base . Configuration , x ) ) ;
22- IHttpClientFactory httpClientFactory = new DefaultHttpClientFactory ( clientSetup ) ;
23+ IHttpClientFactory httpClientFactory = TestHttpClientFactoryBuilder . Create ( TestContext , Out )
24+ . Configure ( x => ConfigureClient ( Configuration , x ) )
25+ . Build ( ) ;
2326 ITestAuthorizationContext authorizationContext = new TestAuthorizationContext ( httpClientFactory ) ;
24- IHttpAuthorizationProvider authorizationProvider = await this . Authorize ( authorizationContext , base . Configuration ) . ConfigureAwait ( false ) ;
27+ IHttpAuthorizationProvider authorizationProvider = await Authorize ( authorizationContext , Configuration ) . ConfigureAwait ( false ) ;
2528 TTestContext testContext = contextCreator ( httpClientFactory , authorizationProvider ) ;
2629 await testFlow ( testContext ) . ConfigureAwait ( false ) ;
2730 }
@@ -30,7 +33,7 @@ private protected async Task ExecuteTest<TTestContext>(Func<TTestContext, Task>
3033 protected async Task < TContent > InvokeApi < TService , TContent > ( TService service , Expression < Func < TService , Task < HttpResponse < TContent > > > > methodSelector , string expectedText )
3134 {
3235 HttpResponse < TContent > response = await InvokeApi ( service , methodSelector ) . ConfigureAwait ( false ) ;
33- this . Assert ( response , expectedText ) ;
36+ Assert ( response , expectedText ) ;
3437 return response . ResponseContent ;
3538 }
3639 protected Task InvokeApi < TService > ( HttpTestContext context , Expression < Func < TService , Task < HttpResponseMessage > > > methodSelector ) => InvokeApiCore < TService , HttpResponseMessage > ( context , methodSelector ) ;
@@ -42,7 +45,7 @@ protected async Task<TContent> InvokeApi<TService, TContent>(HttpTestContext con
4245 protected async Task < TContent > InvokeApi < TService , TContent > ( HttpTestContext context , Expression < Func < TService , Task < HttpResponse < TContent > > > > methodSelector , string expectedText )
4346 {
4447 HttpResponse < TContent > response = await InvokeApiCore ( context , methodSelector ) . ConfigureAwait ( false ) ;
45- this . Assert ( response , expectedText ) ;
48+ Assert ( response , expectedText ) ;
4649 return response . ResponseContent ;
4750 }
4851
@@ -82,7 +85,7 @@ private void Assert<TContent>(HttpResponse<TContent> response, string expectedTe
8285
8386 return value . Value . ToString ( ) ;
8487 } ) ;
85- base . AssertEqual ( expectedTextReplaced , actualText , extension : "json" ) ;
88+ AssertEqual ( expectedTextReplaced , actualText , extension : "json" ) ;
8689 }
8790
8891 private static HttpTestContext CreateTestContext ( IHttpClientFactory httpClientFactory , IHttpAuthorizationProvider authorizationProvider )
@@ -96,10 +99,10 @@ private sealed class TestAuthorizationContext : ITestAuthorizationContext
9699 {
97100 private readonly IHttpClientFactory _httpClientFactory ;
98101
99- public TestAuthorizationContext ( IHttpClientFactory httpClientFactory ) => this . _httpClientFactory = httpClientFactory ;
102+ public TestAuthorizationContext ( IHttpClientFactory httpClientFactory ) => _httpClientFactory = httpClientFactory ;
100103
101- public TService CreateService < TService > ( ) => HttpServiceFactory . CreateServiceInstance < TService > ( this . _httpClientFactory ) ;
102- public TService CreateService < TService > ( IHttpAuthorizationProvider authorizationProvider ) => HttpServiceFactory . CreateServiceInstance < TService > ( this . _httpClientFactory , authorizationProvider ) ;
104+ public TService CreateService < TService > ( ) => HttpServiceFactory . CreateServiceInstance < TService > ( _httpClientFactory ) ;
105+ public TService CreateService < TService > ( IHttpAuthorizationProvider authorizationProvider ) => HttpServiceFactory . CreateServiceInstance < TService > ( _httpClientFactory , authorizationProvider ) ;
103106 }
104107 #endregion
105108 }
0 commit comments