Skip to content

Commit

Permalink
Added a test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Jul 30, 2024
1 parent f8b5f7f commit 8a79628
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion test/RestSharp.Tests.Integrated/MultipartFormDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public MultipartFormDataTests(ITestOutputHelper output) {
_server = WireMockServer.Start();

_capturer = _server.ConfigureBodyCapturer(Method.Post);

var options = new RestClientOptions($"{_server.Url!}{RequestBodyCapturer.Resource}") {
ConfigureMessageHandler = handler => new HttpTracerHandler(handler, new OutputLogger(output), HttpMessageParts.All)
};
Expand Down Expand Up @@ -180,7 +181,7 @@ public async Task MultipartFormDataAsync() {

_capturer.Body.Should().Be(expected);
}

[Fact]
public async Task MultipartFormData_Without_File_Creates_A_Valid_RequestBody() {
using var client = new RestClient(_server.Url!);
Expand All @@ -206,4 +207,29 @@ public async Task MultipartFormData_Without_File_Creates_A_Valid_RequestBody() {
var actual = capturer.Body!.Replace("\n", string.Empty).Split('\r');
actual.Should().Contain(expectedBody);
}

[Fact]
public async Task PostParameter_contentType_in_multipart_form() {
using var client = new RestClient(_server.Url!);

var request = new RestRequest(RequestBodyCapturer.Resource, Method.Post) {
AlwaysMultipartFormData = true
};
var capturer = _server.ConfigureBodyCapturer(Method.Post);

const string parameterName = "Arequest";
const string parameterValue = "{\"attributeFormat\":\"pdf\"}";

var parameter = new GetOrPostParameter(parameterName, parameterValue) {
ContentType = "application/json"
};
request.AddParameter(parameter);

await client.ExecuteAsync(request);

var actual = capturer.Body!.Replace("\n", string.Empty).Split('\r');
actual[1].Should().Be("Content-Type: application/json; charset=utf-8");
actual[2].Should().Be($"Content-Disposition: form-data; name={parameterName}");
actual[4].Should().Be(parameterValue);
}
}

0 comments on commit 8a79628

Please sign in to comment.