@@ -13,6 +13,7 @@ public MultipartFormDataTests(ITestOutputHelper output) {
1313 _server = WireMockServer . Start ( ) ;
1414
1515 _capturer = _server . ConfigureBodyCapturer ( Method . Post ) ;
16+
1617 var options = new RestClientOptions ( $ "{ _server . Url ! } { RequestBodyCapturer . Resource } ") {
1718 ConfigureMessageHandler = handler => new HttpTracerHandler ( handler , new OutputLogger ( output ) , HttpMessageParts . All )
1819 } ;
@@ -180,7 +181,7 @@ public async Task MultipartFormDataAsync() {
180181
181182 _capturer . Body . Should ( ) . Be ( expected ) ;
182183 }
183-
184+
184185 [ Fact ]
185186 public async Task MultipartFormData_Without_File_Creates_A_Valid_RequestBody ( ) {
186187 using var client = new RestClient ( _server . Url ! ) ;
@@ -206,4 +207,29 @@ public async Task MultipartFormData_Without_File_Creates_A_Valid_RequestBody() {
206207 var actual = capturer . Body ! . Replace ( "\n " , string . Empty ) . Split ( '\r ' ) ;
207208 actual . Should ( ) . Contain ( expectedBody ) ;
208209 }
210+
211+ [ Fact ]
212+ public async Task PostParameter_contentType_in_multipart_form ( ) {
213+ using var client = new RestClient ( _server . Url ! ) ;
214+
215+ var request = new RestRequest ( RequestBodyCapturer . Resource , Method . Post ) {
216+ AlwaysMultipartFormData = true
217+ } ;
218+ var capturer = _server . ConfigureBodyCapturer ( Method . Post ) ;
219+
220+ const string parameterName = "Arequest" ;
221+ const string parameterValue = "{\" attributeFormat\" :\" pdf\" }" ;
222+
223+ var parameter = new GetOrPostParameter ( parameterName , parameterValue ) {
224+ ContentType = "application/json"
225+ } ;
226+ request . AddParameter ( parameter ) ;
227+
228+ await client . ExecuteAsync ( request ) ;
229+
230+ var actual = capturer . Body ! . Replace ( "\n " , string . Empty ) . Split ( '\r ' ) ;
231+ actual [ 1 ] . Should ( ) . Be ( "Content-Type: application/json; charset=utf-8" ) ;
232+ actual [ 2 ] . Should ( ) . Be ( $ "Content-Disposition: form-data; name={ parameterName } ") ;
233+ actual [ 4 ] . Should ( ) . Be ( parameterValue ) ;
234+ }
209235}
0 commit comments