Skip to content

Commit ac24d7b

Browse files
committed
Add unit tests for Sync and Async MultpartFormData_WithParameter.
1 parent ccf312a commit ac24d7b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

RestSharp.IntegrationTests/MultipartFormDataTests.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
namespace RestSharp.IntegrationTests
22
{
33
using System;
4+
using System.Diagnostics;
45
using System.IO;
56
using System.Net;
7+
using System.Threading;
8+
using System.Threading.Tasks;
69

710
using RestSharp.IntegrationTests.Helpers;
811

@@ -58,6 +61,59 @@ public void MultipartFormData()
5861
}
5962
}
6063

64+
[Fact]
65+
public void AlwaysMultipartFormData_WithParameter()
66+
{
67+
const string baseUrl = "http://localhost:8888/";
68+
69+
using (SimpleServer.Create(baseUrl, EchoHandler))
70+
{
71+
var client = new RestClient(baseUrl);
72+
var request = new RestRequest("?json_route=/posts")
73+
{
74+
AlwaysMultipartFormData = true,
75+
Method = Method.POST,
76+
};
77+
request.AddParameter("title", "test", ParameterType.RequestBody);
78+
79+
var response = client.Execute(request);
80+
Assert.Null(response.ErrorException);
81+
}
82+
}
83+
84+
[Fact]
85+
public void AlwaysMultipartFormData_WithParameter_Async()
86+
{
87+
const string baseUrl = "http://localhost:8888/";
88+
89+
using (SimpleServer.Create(baseUrl, EchoHandler))
90+
{
91+
var client = new RestClient(baseUrl);
92+
var request = new RestRequest("?json_route=/posts")
93+
{
94+
AlwaysMultipartFormData = true,
95+
Method = Method.POST,
96+
};
97+
request.AddParameter("title", "test", ParameterType.RequestBody);
98+
IRestResponse syncResponse = null;
99+
100+
using (var eventWaitHandle = new AutoResetEvent(false))
101+
{
102+
client.ExecuteAsync(
103+
request,
104+
response =>
105+
{
106+
syncResponse = response;
107+
eventWaitHandle.Set();
108+
});
109+
110+
eventWaitHandle.WaitOne();
111+
}
112+
113+
Assert.Null(syncResponse.ErrorException);
114+
}
115+
}
116+
61117
private static void EchoHandler(HttpListenerContext obj)
62118
{
63119
obj.Response.StatusCode = 200;

0 commit comments

Comments
 (0)