1
- using Newtonsoft . Json ;
2
- using System ;
1
+ using System ;
3
2
using System . Collections . Generic ;
4
3
using System . Net ;
5
4
using System . Net . Http ;
@@ -19,7 +18,7 @@ public static HttpClient SetupHttpClientWithJsonResponse<TResponseContent>(HttpS
19
18
public static HttpClient SetupHttpClientWithJsonResponse < TResponseContent > ( HttpResponseContent < TResponseContent > response )
20
19
{
21
20
var messageHandler =
22
- new TestHttpMessageHandler ( _ => Task . FromResult ( new HttpResponseMessage ( response . StatusCode ) { Content = new StringContent ( JsonConvert . SerializeObject ( response . Content ) , Encoding . UTF8 , "application/json" ) } ) ) ;
21
+ new TestHttpMessageHandler ( _ => Task . FromResult ( new HttpResponseMessage ( response . StatusCode ) { Content = new StringContent ( System . Text . Json . JsonSerializer . Serialize ( response . Content ) , Encoding . UTF8 , "application/json" ) } ) ) ;
23
22
24
23
return new HttpClient ( messageHandler ) ;
25
24
}
@@ -33,7 +32,7 @@ public static HttpClient SetupHttpClientWithJsonResponse<TResponseContent>(Func<
33
32
34
33
var response = new HttpResponseMessage ( responseContent . StatusCode )
35
34
{
36
- Content = new StringContent ( JsonConvert . SerializeObject ( responseContent . Content ) ,
35
+ Content = new StringContent ( System . Text . Json . JsonSerializer . Serialize ( responseContent . Content ) ,
37
36
Encoding . UTF8 ,
38
37
"application/json" )
39
38
} ;
@@ -42,7 +41,15 @@ public static HttpClient SetupHttpClientWithJsonResponse<TResponseContent>(Func<
42
41
} ) ;
43
42
44
43
return new HttpClient ( messageHandler ) ;
45
- }
44
+ }
45
+
46
+ public static HttpClient SetupHttpClientWithRawJsonResponse ( HttpStatusCode statusCode , string rawJson )
47
+ {
48
+ var messageHandler =
49
+ new TestHttpMessageHandler ( _ => Task . FromResult ( new HttpResponseMessage ( statusCode ) { Content = new StringContent ( rawJson , Encoding . UTF8 , "application/json" ) } ) ) ;
50
+
51
+ return new HttpClient ( messageHandler ) ;
52
+ }
46
53
47
54
/// <summary>
48
55
/// Sets up a HttpClientMock that will return another response on each invocation.
@@ -65,7 +72,7 @@ public static HttpClient SetupHttpClientWithMultipleJsonResponses<TResponseConte
65
72
66
73
var response = new HttpResponseMessage ( responseContent . StatusCode )
67
74
{
68
- Content = new StringContent ( JsonConvert . SerializeObject ( responseContent . Content ) ,
75
+ Content = new StringContent ( System . Text . Json . JsonSerializer . Serialize ( responseContent . Content ) ,
69
76
Encoding . UTF8 ,
70
77
"application/json" )
71
78
} ;
0 commit comments