@@ -38,28 +38,28 @@ protected virtual void ConfigureOptions(HttpClientOptions options)
3838
3939 protected Task InvokeApi < TService > ( HttpTestContext context , Expression < Func < TService , Task < HttpResponseMessage > > > methodSelector ) => CreateServiceAndInvokeApi ( context , methodSelector ) ;
4040 protected Task InvokeApi < TService > ( TService service , Expression < Func < TService , Task < HttpResponseMessage > > > methodSelector ) => InvokeApiCore ( service , methodSelector ) ;
41- protected async Task < TResponseContent > InvokeApi < TService , TResponseContent > ( HttpTestContext context , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector )
41+ protected async Task < TResponseContent > InvokeApi < TService , TResponseContent > ( HttpTestContext context , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector , Action < HttpResponse < TResponseContent > > responseHandler = null )
4242 {
43- HttpResponse < TResponseContent > response = await CreateServiceAndInvokeApi ( context , methodSelector ) . ConfigureAwait ( false ) ;
44- return response . ResponseContent ;
43+ TResponseContent responseContent = await CreateServiceAndInvokeApiContent ( context , methodSelector , responseHandler ) . ConfigureAwait ( false ) ;
44+ return responseContent ;
4545 }
46- protected async Task < TResponseContent > InvokeApi < TService , TResponseContent > ( TService service , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector )
46+ protected async Task < TResponseContent > InvokeApi < TService , TResponseContent > ( TService service , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector , Action < HttpResponse < TResponseContent > > responseHandler = null )
4747 {
48- HttpResponse < TResponseContent > response = await InvokeApiCore ( service , methodSelector ) . ConfigureAwait ( false ) ;
49- return response . ResponseContent ;
48+ TResponseContent responseContent = await InvokeApiCoreContent ( service , methodSelector , responseHandler ) . ConfigureAwait ( false ) ;
49+ return responseContent ;
5050 }
5151
52- protected async Task < TResponseContent > InvokeApiAndAssertResponse < TService , TResponseContent > ( TService service , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector , string expectedText = null , string outputName = null , Action < JsonSerializerSettings > configureSerializer = null )
52+ protected async Task < TResponseContent > InvokeApiAndAssertResponse < TService , TResponseContent > ( TService service , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector , string expectedText = null , string outputName = null , Action < JsonSerializerSettings > configureSerializer = null , Action < HttpResponse < TResponseContent > > responseHandler = null )
5353 {
54- HttpResponse < TResponseContent > response = await InvokeApiCore ( service , methodSelector ) . ConfigureAwait ( false ) ;
55- AssertJsonResponse ( response . ResponseContent , configureSerializer , outputName , expectedText ) ;
56- return response . ResponseContent ;
54+ TResponseContent responseContent = await InvokeApiCoreContent ( service , methodSelector , responseHandler ) . ConfigureAwait ( false ) ;
55+ AssertJsonResponse ( responseContent , configureSerializer , outputName , expectedText ) ;
56+ return responseContent ;
5757 }
58- protected async Task < TResponseContent > InvokeApiAndAssertResponse < TService , TResponseContent > ( HttpTestContext context , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector , string expectedText = null , string outputName = null , Action < JsonSerializerSettings > configureSerializer = null )
58+ protected async Task < TResponseContent > InvokeApiAndAssertResponse < TService , TResponseContent > ( HttpTestContext context , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector , string expectedText = null , string outputName = null , Action < JsonSerializerSettings > configureSerializer = null , Action < HttpResponse < TResponseContent > > responseHandler = null )
5959 {
60- HttpResponse < TResponseContent > response = await CreateServiceAndInvokeApi ( context , methodSelector ) . ConfigureAwait ( false ) ;
61- AssertJsonResponse ( response . ResponseContent , configureSerializer , outputName , expectedText ) ;
62- return response . ResponseContent ;
60+ TResponseContent responseContent = await CreateServiceAndInvokeApiContent ( context , methodSelector , responseHandler ) . ConfigureAwait ( false ) ;
61+ AssertJsonResponse ( responseContent , configureSerializer , outputName , expectedText ) ;
62+ return responseContent ;
6363 }
6464
6565 protected virtual void ConfigureClient ( TConfiguration configuration , IHttpClientBuilder builder ) { }
@@ -68,6 +68,13 @@ protected virtual void ConfigureClient(TConfiguration configuration, IHttpClient
6868 #endregion
6969
7070 #region Private Methods
71+ private static async Task < TResponseContent > InvokeApiCoreContent < TService , TResponseContent > ( TService service , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector , Action < HttpResponse < TResponseContent > > responseHandler )
72+ {
73+ HttpResponse < TResponseContent > response = await InvokeApiCore ( service , methodSelector ) . ConfigureAwait ( false ) ;
74+ responseHandler ? . Invoke ( response ) ;
75+ return response . ResponseContent ;
76+ }
77+
7178 private static async Task < TResponse > InvokeApiCore < TService , TResponse > ( TService service , Expression < Func < TService , Task < TResponse > > > methodSelector )
7279 {
7380 Func < TService , Task < TResponse > > compiled = methodSelector . Compile ( ) ;
@@ -76,10 +83,18 @@ private static async Task<TResponse> InvokeApiCore<TService, TResponse>(TService
7683 return response ;
7784 }
7885
79- private static Task < TResponse > CreateServiceAndInvokeApi < TService , TResponse > ( HttpTestContext context , Expression < Func < TService , Task < TResponse > > > methodSelector )
86+ private static async Task < TResponseContent > CreateServiceAndInvokeApiContent < TService , TResponseContent > ( HttpTestContext context , Expression < Func < TService , Task < HttpResponse < TResponseContent > > > > methodSelector , Action < HttpResponse < TResponseContent > > responseHandler )
87+ {
88+ TService service = HttpServiceFactory . CreateServiceInstance < TService > ( context . HttpClientFactory , context . HttpClientOptions , context . HttpAuthorizationProvider ) ;
89+ TResponseContent responseContent = await InvokeApiCoreContent ( service , methodSelector , responseHandler ) . ConfigureAwait ( false ) ;
90+ return responseContent ;
91+ }
92+
93+ private static async Task < TResponse > CreateServiceAndInvokeApi < TService , TResponse > ( HttpTestContext context , Expression < Func < TService , Task < TResponse > > > methodSelector )
8094 {
8195 TService service = HttpServiceFactory . CreateServiceInstance < TService > ( context . HttpClientFactory , context . HttpClientOptions , context . HttpAuthorizationProvider ) ;
82- return InvokeApiCore ( service , methodSelector ) ;
96+ TResponse response = await InvokeApiCore ( service , methodSelector ) . ConfigureAwait ( false ) ;
97+ return response ;
8398 }
8499
85100 private static HttpTestContext CreateTestContext ( IHttpClientFactory httpClientFactory , HttpClientOptions httpClientOptions , IHttpAuthorizationProvider authorizationProvider )
0 commit comments