|
1 | 1 | namespace RestSharp.IntegrationTests |
2 | 2 | { |
3 | 3 | using System; |
| 4 | + using System.Diagnostics; |
4 | 5 | using System.IO; |
5 | 6 | using System.Net; |
| 7 | + using System.Threading; |
| 8 | + using System.Threading.Tasks; |
6 | 9 |
|
7 | 10 | using RestSharp.IntegrationTests.Helpers; |
8 | 11 |
|
@@ -58,6 +61,59 @@ public void MultipartFormData() |
58 | 61 | } |
59 | 62 | } |
60 | 63 |
|
| 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 | + |
61 | 117 | private static void EchoHandler(HttpListenerContext obj) |
62 | 118 | { |
63 | 119 | obj.Response.StatusCode = 200; |
|
0 commit comments