@@ -12,16 +12,33 @@ public class EndToEndBenchmark
1212 private const string Host = "https://github.com" ;
1313 private SystemTextJsonContentSerializer systemTextJsonContentSerializer ;
1414 private NewtonsoftJsonContentSerializer newtonsoftJsonContentSerializer ;
15- private readonly IDictionary < int , IEnumerable < User > > users = new Dictionary < int , IEnumerable < User > > ( ) ;
16- private readonly IDictionary < SerializationStrategy , IDictionary < HttpStatusCode , IGitHubService > > refitClient = new Dictionary < SerializationStrategy , IDictionary < HttpStatusCode , IGitHubService > >
15+ private readonly IDictionary < int , IEnumerable < User > > users =
16+ new Dictionary < int , IEnumerable < User > > ( ) ;
17+ private readonly IDictionary <
18+ SerializationStrategy ,
19+ IDictionary < HttpStatusCode , IGitHubService >
20+ > refitClient = new Dictionary <
21+ SerializationStrategy ,
22+ IDictionary < HttpStatusCode , IGitHubService >
23+ >
1724 {
18- { SerializationStrategy . SystemTextJson , new Dictionary < HttpStatusCode , IGitHubService > ( ) } ,
19- { SerializationStrategy . NewtonsoftJson , new Dictionary < HttpStatusCode , IGitHubService > ( ) }
25+ {
26+ SerializationStrategy . SystemTextJson ,
27+ new Dictionary < HttpStatusCode , IGitHubService > ( )
28+ } ,
29+ {
30+ SerializationStrategy . NewtonsoftJson ,
31+ new Dictionary < HttpStatusCode , IGitHubService > ( )
32+ }
2033 } ;
2134
22- private readonly IDictionary < HttpVerb , HttpMethod > httpMethod = new Dictionary < HttpVerb , HttpMethod >
35+ private readonly IDictionary < HttpVerb , HttpMethod > httpMethod = new Dictionary <
36+ HttpVerb ,
37+ HttpMethod
38+ >
2339 {
24- { HttpVerb . Get , HttpMethod . Get } , { HttpVerb . Post , HttpMethod . Post }
40+ { HttpVerb . Get , HttpMethod . Get } ,
41+ { HttpVerb . Post , HttpMethod . Post }
2542 } ;
2643
2744 private const int TenUsers = 10 ;
@@ -41,26 +58,57 @@ public enum HttpVerb
4158 [ GlobalSetup ]
4259 public Task SetupAsync ( )
4360 {
44-
4561 systemTextJsonContentSerializer = new SystemTextJsonContentSerializer ( ) ;
46- refitClient [ SerializationStrategy . SystemTextJson ] [ HttpStatusCode . OK ] = RestService . For < IGitHubService > ( Host , new RefitSettings ( systemTextJsonContentSerializer )
47- {
48- HttpMessageHandlerFactory = ( ) => new StaticFileHttpResponseHandler ( "system-text-json-10-users.json" , HttpStatusCode . OK )
49- } ) ;
50- refitClient [ SerializationStrategy . SystemTextJson ] [ HttpStatusCode . InternalServerError ] = RestService . For < IGitHubService > ( Host , new RefitSettings ( systemTextJsonContentSerializer )
51- {
52- HttpMessageHandlerFactory = ( ) => new StaticFileHttpResponseHandler ( "system-text-json-10-users.json" , HttpStatusCode . InternalServerError )
53- } ) ;
62+ refitClient [ SerializationStrategy . SystemTextJson ] [ HttpStatusCode . OK ] =
63+ RestService . For < IGitHubService > (
64+ Host ,
65+ new RefitSettings ( systemTextJsonContentSerializer )
66+ {
67+ HttpMessageHandlerFactory = ( ) =>
68+ new StaticFileHttpResponseHandler (
69+ "system-text-json-10-users.json" ,
70+ HttpStatusCode . OK
71+ )
72+ }
73+ ) ;
74+ refitClient [ SerializationStrategy . SystemTextJson ] [ HttpStatusCode . InternalServerError ] =
75+ RestService . For < IGitHubService > (
76+ Host ,
77+ new RefitSettings ( systemTextJsonContentSerializer )
78+ {
79+ HttpMessageHandlerFactory = ( ) =>
80+ new StaticFileHttpResponseHandler (
81+ "system-text-json-10-users.json" ,
82+ HttpStatusCode . InternalServerError
83+ )
84+ }
85+ ) ;
5486
5587 newtonsoftJsonContentSerializer = new NewtonsoftJsonContentSerializer ( ) ;
56- refitClient [ SerializationStrategy . NewtonsoftJson ] [ HttpStatusCode . OK ] = RestService . For < IGitHubService > ( Host , new RefitSettings ( newtonsoftJsonContentSerializer )
57- {
58- HttpMessageHandlerFactory = ( ) => new StaticFileHttpResponseHandler ( "newtonsoft-json-10-users.json" , System . Net . HttpStatusCode . OK )
59- } ) ;
60- refitClient [ SerializationStrategy . NewtonsoftJson ] [ HttpStatusCode . InternalServerError ] = RestService . For < IGitHubService > ( Host , new RefitSettings ( newtonsoftJsonContentSerializer )
61- {
62- HttpMessageHandlerFactory = ( ) => new StaticFileHttpResponseHandler ( "newtonsoft-json-10-users.json" , System . Net . HttpStatusCode . InternalServerError )
63- } ) ;
88+ refitClient [ SerializationStrategy . NewtonsoftJson ] [ HttpStatusCode . OK ] =
89+ RestService . For < IGitHubService > (
90+ Host ,
91+ new RefitSettings ( newtonsoftJsonContentSerializer )
92+ {
93+ HttpMessageHandlerFactory = ( ) =>
94+ new StaticFileHttpResponseHandler (
95+ "newtonsoft-json-10-users.json" ,
96+ System . Net . HttpStatusCode . OK
97+ )
98+ }
99+ ) ;
100+ refitClient [ SerializationStrategy . NewtonsoftJson ] [ HttpStatusCode . InternalServerError ] =
101+ RestService . For < IGitHubService > (
102+ Host ,
103+ new RefitSettings ( newtonsoftJsonContentSerializer )
104+ {
105+ HttpMessageHandlerFactory = ( ) =>
106+ new StaticFileHttpResponseHandler (
107+ "newtonsoft-json-10-users.json" ,
108+ System . Net . HttpStatusCode . InternalServerError
109+ )
110+ }
111+ ) ;
64112
65113 users [ TenUsers ] = autoFixture . CreateMany < User > ( TenUsers ) ;
66114
@@ -94,7 +142,9 @@ public async Task Task_Async()
94142 await refitClient [ Serializer ] [ HttpStatusCode ] . GetUsersTaskAsync ( ) ;
95143 break ;
96144 case HttpVerb . Post :
97- await refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersTaskAsync ( users [ ModelCount ] ) ;
145+ await refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersTaskAsync (
146+ users [ ModelCount ]
147+ ) ;
98148 break ;
99149 default :
100150 throw new ArgumentOutOfRangeException ( nameof ( Verb ) ) ;
@@ -114,9 +164,13 @@ public async Task<string> TaskString_Async()
114164 switch ( Verb )
115165 {
116166 case HttpVerb . Get :
117- return await refitClient [ Serializer ] [ HttpStatusCode ] . GetUsersTaskStringAsync ( ) ;
167+ return await refitClient [ Serializer ] [
168+ HttpStatusCode
169+ ] . GetUsersTaskStringAsync ( ) ;
118170 case HttpVerb . Post :
119- return await refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersTaskStringAsync ( users [ ModelCount ] ) ;
171+ return await refitClient [ Serializer ] [
172+ HttpStatusCode
173+ ] . PostUsersTaskStringAsync ( users [ ModelCount ] ) ;
120174 default :
121175 throw new ArgumentOutOfRangeException ( nameof ( Verb ) ) ;
122176 }
@@ -137,9 +191,13 @@ public async Task<Stream> TaskStream_Async()
137191 switch ( Verb )
138192 {
139193 case HttpVerb . Get :
140- return await refitClient [ Serializer ] [ HttpStatusCode ] . GetUsersTaskStreamAsync ( ) ;
194+ return await refitClient [ Serializer ] [
195+ HttpStatusCode
196+ ] . GetUsersTaskStreamAsync ( ) ;
141197 case HttpVerb . Post :
142- return await refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersTaskStreamAsync ( users [ ModelCount ] ) ;
198+ return await refitClient [ Serializer ] [
199+ HttpStatusCode
200+ ] . PostUsersTaskStreamAsync ( users [ ModelCount ] ) ;
143201 default :
144202 throw new ArgumentOutOfRangeException ( nameof ( Verb ) ) ;
145203 }
@@ -160,9 +218,13 @@ public async Task<HttpContent> TaskHttpContent_Async()
160218 switch ( Verb )
161219 {
162220 case HttpVerb . Get :
163- return await refitClient [ Serializer ] [ HttpStatusCode ] . GetUsersTaskHttpContentAsync ( ) ;
221+ return await refitClient [ Serializer ] [
222+ HttpStatusCode
223+ ] . GetUsersTaskHttpContentAsync ( ) ;
164224 case HttpVerb . Post :
165- return await refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersTaskHttpContentAsync ( users [ ModelCount ] ) ;
225+ return await refitClient [ Serializer ] [
226+ HttpStatusCode
227+ ] . PostUsersTaskHttpContentAsync ( users [ ModelCount ] ) ;
166228 default :
167229 throw new ArgumentOutOfRangeException ( nameof ( Verb ) ) ;
168230 }
@@ -181,9 +243,13 @@ public async Task<HttpResponseMessage> TaskHttpResponseMessage_Async()
181243 switch ( Verb )
182244 {
183245 case HttpVerb . Get :
184- return await refitClient [ Serializer ] [ HttpStatusCode ] . GetUsersTaskHttpResponseMessageAsync ( ) ;
246+ return await refitClient [ Serializer ] [
247+ HttpStatusCode
248+ ] . GetUsersTaskHttpResponseMessageAsync ( ) ;
185249 case HttpVerb . Post :
186- return await refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersTaskHttpResponseMessageAsync ( users [ ModelCount ] ) ;
250+ return await refitClient [ Serializer ] [
251+ HttpStatusCode
252+ ] . PostUsersTaskHttpResponseMessageAsync ( users [ ModelCount ] ) ;
187253 default :
188254 throw new ArgumentOutOfRangeException ( nameof ( Verb ) ) ;
189255 }
@@ -195,9 +261,13 @@ public IObservable<HttpResponseMessage> ObservableHttpResponseMessage()
195261 switch ( Verb )
196262 {
197263 case HttpVerb . Get :
198- return refitClient [ Serializer ] [ HttpStatusCode ] . GetUsersObservableHttpResponseMessage ( ) ;
264+ return refitClient [ Serializer ] [
265+ HttpStatusCode
266+ ] . GetUsersObservableHttpResponseMessage ( ) ;
199267 case HttpVerb . Post :
200- return refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersObservableHttpResponseMessage ( users [ ModelCount ] ) ;
268+ return refitClient [ Serializer ] [
269+ HttpStatusCode
270+ ] . PostUsersObservableHttpResponseMessage ( users [ ModelCount ] ) ;
201271 default :
202272 throw new ArgumentOutOfRangeException ( nameof ( Verb ) ) ;
203273 }
@@ -213,7 +283,9 @@ public async Task<List<User>> TaskT_Async()
213283 case HttpVerb . Get :
214284 return await refitClient [ Serializer ] [ HttpStatusCode ] . GetUsersTaskTAsync ( ) ;
215285 case HttpVerb . Post :
216- return await refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersTaskTAsync ( users [ ModelCount ] ) ;
286+ return await refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersTaskTAsync (
287+ users [ ModelCount ]
288+ ) ;
217289 default :
218290 throw new ArgumentOutOfRangeException ( nameof ( Verb ) ) ;
219291 }
@@ -232,9 +304,13 @@ public async Task<ApiResponse<List<User>>> TaskApiResponseT_Async()
232304 switch ( Verb )
233305 {
234306 case HttpVerb . Get :
235- return await refitClient [ Serializer ] [ HttpStatusCode ] . GetUsersTaskApiResponseTAsync ( ) ;
307+ return await refitClient [ Serializer ] [
308+ HttpStatusCode
309+ ] . GetUsersTaskApiResponseTAsync ( ) ;
236310 case HttpVerb . Post :
237- return await refitClient [ Serializer ] [ HttpStatusCode ] . PostUsersTaskApiResponseTAsync ( users [ ModelCount ] ) ;
311+ return await refitClient [ Serializer ] [
312+ HttpStatusCode
313+ ] . PostUsersTaskApiResponseTAsync ( users [ ModelCount ] ) ;
238314 default :
239315 throw new ArgumentOutOfRangeException ( nameof ( Verb ) ) ;
240316 }
0 commit comments