1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . IO ;
4+ using System . Net ;
45using System . Net . Http ;
6+ using System . Net . Http . Json ;
57using System . Runtime . CompilerServices ;
68using System . Threading ;
79using System . Threading . Tasks ;
@@ -43,7 +45,7 @@ await ExecuteModeIterations(async (client, mode) =>
4345 if ( mode == HttpRecorderMode . Passthrough )
4446 {
4547 passthroughResponse = response ;
46- var result = await response . Content . ReadAsAsync < SampleModel > ( ) ;
48+ var result = await response . Content . ReadFromJsonAsync < SampleModel > ( ) ;
4749 result . Name . Should ( ) . Be ( SampleModel . DefaultName ) ;
4850 }
4951 else
@@ -68,7 +70,7 @@ await ExecuteModeIterations(async (client, mode) =>
6870 if ( mode == HttpRecorderMode . Passthrough )
6971 {
7072 passthroughResponse = response ;
71- var result = await response . Content . ReadAsAsync < SampleModel > ( ) ;
73+ var result = await response . Content . ReadFromJsonAsync < SampleModel > ( ) ;
7274 result . Name . Should ( ) . Be ( name ) ;
7375 }
7476 else
@@ -94,7 +96,7 @@ await ExecuteModeIterations(async (client, mode) =>
9496 if ( mode == HttpRecorderMode . Passthrough )
9597 {
9698 passthroughResponse = response ;
97- var result = await response . Content . ReadAsAsync < SampleModel > ( ) ;
99+ var result = await response . Content . ReadFromJsonAsync < SampleModel > ( ) ;
98100 result . Name . Should ( ) . Be ( sampleModel . Name ) ;
99101 }
100102 else
@@ -124,7 +126,7 @@ await ExecuteModeIterations(async (client, mode) =>
124126 if ( mode == HttpRecorderMode . Passthrough )
125127 {
126128 passthroughResponse = response ;
127- var result = await response . Content . ReadAsAsync < SampleModel > ( ) ;
129+ var result = await response . Content . ReadFromJsonAsync < SampleModel > ( ) ;
128130 result . Name . Should ( ) . Be ( sampleModel . Name ) ;
129131 }
130132 else
@@ -162,7 +164,7 @@ await ExecuteModeIterations(async (client, mode) =>
162164 {
163165 var response = responses [ i ] ;
164166 response . EnsureSuccessStatusCode ( ) ;
165- var result = await response . Content . ReadAsAsync < SampleModel > ( ) ;
167+ var result = await response . Content . ReadFromJsonAsync < SampleModel > ( ) ;
166168 result . Name . Should ( ) . Be ( $ "{ i } ") ;
167169 }
168170 }
@@ -188,10 +190,10 @@ public async Task ItShouldExecuteMultipleRequestsInSequenceWithRecorderModeAuto(
188190 nameof ( ItShouldExecuteMultipleRequestsInSequenceWithRecorderModeAuto ) ) ;
189191 var response1 = await client . GetAsync ( $ "{ ApiController . JsonUri } ?name=1") ;
190192 var response2 = await client . GetAsync ( $ "{ ApiController . JsonUri } ?name=2") ;
191- var result1 = await response1 . Content . ReadAsAsync < SampleModel > ( ) ;
193+ var result1 = await response1 . Content . ReadFromJsonAsync < SampleModel > ( ) ;
192194 result1 . Name . Should ( ) . Be ( "1" ) ;
193195
194- var result2 = await response2 . Content . ReadAsAsync < SampleModel > ( ) ;
196+ var result2 = await response2 . Content . ReadFromJsonAsync < SampleModel > ( ) ;
195197 result2 . Name . Should ( ) . Be ( "2" ) ;
196198
197199 // We resolve to replay at this point.
@@ -239,7 +241,7 @@ public async Task ItShouldThrowIfDoesNotFindFile()
239241
240242 Func < Task > act = async ( ) => await client . GetAsync ( ApiController . JsonUri ) ;
241243
242- act . Should ( ) . Throw < HttpRecorderException > ( )
244+ await act . Should ( ) . ThrowAsync < HttpRecorderException > ( )
243245 . WithMessage ( $ "*{ TestFile } *") ;
244246 }
245247
@@ -251,7 +253,7 @@ public async Task ItShouldThrowIfFileIsCorrupted()
251253
252254 Func < Task > act = async ( ) => await client . GetAsync ( ApiController . JsonUri ) ;
253255
254- act . Should ( ) . Throw < HttpRecorderException > ( )
256+ await act . Should ( ) . ThrowAsync < HttpRecorderException > ( )
255257 . WithMessage ( $ "*{ file } *") ;
256258 }
257259
@@ -268,24 +270,24 @@ public async Task ItShouldThrowIfNoRequestCanBeMatched()
268270
269271 Func < Task > act = async ( ) => await client . GetAsync ( ApiController . JsonUri ) ;
270272
271- act . Should ( ) . Throw < HttpRecorderException > ( )
273+ await act . Should ( ) . ThrowAsync < HttpRecorderException > ( )
272274 . WithMessage ( $ "*{ ApiController . JsonUri } *") ;
273275 }
274276
275277 [ Theory ]
276- [ InlineData ( 202 ) ]
277- [ InlineData ( 301 ) ]
278- [ InlineData ( 303 ) ]
279- [ InlineData ( 404 ) ]
280- [ InlineData ( 500 ) ]
281- [ InlineData ( 502 ) ]
282- public async Task ItShouldGetStatus ( int statusCode )
278+ [ InlineData ( HttpStatusCode . Accepted ) ]
279+ [ InlineData ( HttpStatusCode . MovedPermanently ) ]
280+ [ InlineData ( HttpStatusCode . RedirectMethod ) ]
281+ [ InlineData ( HttpStatusCode . NotFound ) ]
282+ [ InlineData ( HttpStatusCode . InternalServerError ) ]
283+ [ InlineData ( HttpStatusCode . BadGateway ) ]
284+ public async Task ItShouldGetStatus ( HttpStatusCode statusCode )
283285 {
284286 HttpResponseMessage passthroughResponse = null ;
285287
286288 await ExecuteModeIterations ( async ( client , mode ) =>
287289 {
288- var response = await client . GetAsync ( $ "{ ApiController . StatusCodeUri } ?statusCode={ statusCode } ") ;
290+ var response = await client . GetAsync ( $ "{ ApiController . StatusCodeUri } ?statusCode={ ( int ) statusCode } ") ;
289291 response . StatusCode . Should ( ) . Be ( statusCode ) ;
290292 response . Headers . Remove ( "Date" ) ;
291293
@@ -310,7 +312,7 @@ public async Task ItShouldOverrideModeWithEnvironmentVariable()
310312
311313 Func < Task > act = ( ) => client . GetAsync ( ApiController . JsonUri ) ;
312314
313- act . Should ( ) . Throw < HttpRecorderException > ( ) ;
315+ await act . Should ( ) . ThrowAsync < HttpRecorderException > ( ) ;
314316 }
315317 finally
316318 {
@@ -326,8 +328,8 @@ public async Task ItShouldAnonymize()
326328 HttpRecorderMode . Record ,
327329 repository : repositoryMock . Object ,
328330 anonymizer : RulesInteractionAnonymizer . Default . AnonymizeRequestQueryStringParameter ( "key" ) ) ;
329- Func < Task > act = async ( ) => await client . GetAsync ( $ " { ApiController . JsonUri } ?key=foo" ) ;
330- act . Should ( ) . Throw < InvalidOperationException > ( ) ; // Because we don't act on the stream in the repository. That's fine.
331+
332+ await client . GetAsync ( $ " { ApiController . JsonUri } ?key=foo" ) ;
331333
332334 repositoryMock . Verify (
333335 x => x . StoreAsync (
0 commit comments