@@ -9,16 +9,18 @@ public class RequestBodyTests : IClassFixture<RequestBodyFixture> {
9
9
10
10
const string NewLine = "\r \n " ;
11
11
12
- const string TextPlainContentType = "text/plain" ;
13
- const string ExpectedTextContentType = $ "{ TextPlainContentType } ; charset=utf-8";
12
+ const string TextPlainContentType = "text/plain" ;
13
+ const string ExpectedTextContentType = $ "{ TextPlainContentType } ; charset=utf-8";
14
+ const string ExpectedTextContentTypeNoCharset = TextPlainContentType ;
14
15
15
16
public RequestBodyTests ( RequestBodyFixture fixture , ITestOutputHelper output ) {
16
17
_output = output ;
17
18
_server = fixture . Server ;
18
19
}
19
20
20
- async Task AssertBody ( Method method ) {
21
- var client = new RestClient ( _server . Url ) ;
21
+ async Task AssertBody ( Method method , bool disableCharset = false ) {
22
+ var options = new RestClientOptions ( _server . Url ) { DisableCharset = disableCharset } ;
23
+ var client = new RestClient ( options ) ;
22
24
23
25
var request = new RestRequest ( RequestBodyCapturer . Resource , method ) {
24
26
OnBeforeRequest = async m => {
@@ -33,7 +35,8 @@ async Task AssertBody(Method method) {
33
35
34
36
await client . ExecuteAsync ( request ) ;
35
37
36
- AssertHasRequestBody ( ExpectedTextContentType , bodyData ) ;
38
+ var expected = disableCharset ? ExpectedTextContentTypeNoCharset : ExpectedTextContentType ;
39
+ AssertHasRequestBody ( expected , bodyData ) ;
37
40
}
38
41
39
42
[ Fact ]
@@ -48,9 +51,15 @@ async Task AssertBody(Method method) {
48
51
[ Fact ]
49
52
public Task Can_Be_Added_To_PATCH_Request ( ) => AssertBody ( Method . Patch ) ;
50
53
54
+ [ Fact ]
55
+ public Task Can_Be_Added_To_POST_Request_NoCharset ( ) => AssertBody ( Method . Post , true ) ;
56
+
51
57
[ Fact ]
52
58
public Task Can_Be_Added_To_POST_Request ( ) => AssertBody ( Method . Post ) ;
53
59
60
+ [ Fact ]
61
+ public Task Can_Be_Added_To_PUT_Request_NoCharset ( ) => AssertBody ( Method . Put , true ) ;
62
+
54
63
[ Fact ]
55
64
public Task Can_Be_Added_To_PUT_Request ( ) => AssertBody ( Method . Put ) ;
56
65
@@ -108,7 +117,7 @@ public async Task Query_Parameters_With_Json_Body() {
108
117
. AddQueryParameter ( "key" , "value" ) ;
109
118
110
119
await client . ExecuteAsync ( request ) ;
111
-
120
+
112
121
RequestBodyCapturer . CapturedUrl . ToString ( ) . Should ( ) . Be ( $ "{ _server . Url } Capture?key=value") ;
113
122
RequestBodyCapturer . CapturedContentType . Should ( ) . Be ( "application/json; charset=utf-8" ) ;
114
123
RequestBodyCapturer . CapturedEntityBody . Should ( ) . Be ( "{\" displayName\" :\" Display Name\" }" ) ;
0 commit comments