1
1
namespace RestSharp . IntegrationTests
2
2
{
3
3
using System ;
4
- using System . Diagnostics ;
5
4
using System . IO ;
6
5
using System . Net ;
7
6
using System . Threading ;
8
- using System . Threading . Tasks ;
9
7
10
8
using RestSharp . IntegrationTests . Helpers ;
11
9
@@ -62,7 +60,7 @@ public void MultipartFormData()
62
60
}
63
61
64
62
[ Fact ]
65
- public void AlwaysMultipartFormData_WithParameter ( )
63
+ public void AlwaysMultipartFormData_WithParameter_Execute ( )
66
64
{
67
65
const string baseUrl = "http://localhost:8888/" ;
68
66
@@ -82,7 +80,7 @@ public void AlwaysMultipartFormData_WithParameter()
82
80
}
83
81
84
82
[ Fact ]
85
- public void AlwaysMultipartFormData_WithParameter_Async ( )
83
+ public void AlwaysMultipartFormData_WithParameter_ExecuteTaskAsync ( )
86
84
{
87
85
const string baseUrl = "http://localhost:8888/" ;
88
86
@@ -95,17 +93,42 @@ public void AlwaysMultipartFormData_WithParameter_Async()
95
93
Method = Method . POST ,
96
94
} ;
97
95
request . AddParameter ( "title" , "test" , ParameterType . RequestBody ) ;
96
+
97
+ var task = client . ExecuteTaskAsync ( request ) . ContinueWith (
98
+ x =>
99
+ {
100
+ Assert . Null ( x . Result . ErrorException ) ;
101
+ } ) ;
102
+
103
+ task . Wait ( ) ;
104
+ }
105
+ }
106
+
107
+ [ Fact ]
108
+ public void AlwaysMultipartFormData_WithParameter_ExecuteAsync ( )
109
+ {
110
+ const string baseUrl = "http://localhost:8888/" ;
111
+
112
+ using ( SimpleServer . Create ( baseUrl , EchoHandler ) )
113
+ {
114
+ var client = new RestClient ( baseUrl ) ;
115
+ var request = new RestRequest ( "?json_route=/posts" )
116
+ {
117
+ AlwaysMultipartFormData = true ,
118
+ Method = Method . POST ,
119
+ } ;
120
+ request . AddParameter ( "title" , "test" , ParameterType . RequestBody ) ;
98
121
IRestResponse syncResponse = null ;
99
122
100
123
using ( var eventWaitHandle = new AutoResetEvent ( false ) )
101
124
{
102
125
client . ExecuteAsync (
103
126
request ,
104
127
response =>
105
- {
106
- syncResponse = response ;
107
- eventWaitHandle . Set ( ) ;
108
- } ) ;
128
+ {
129
+ syncResponse = response ;
130
+ eventWaitHandle . Set ( ) ;
131
+ } ) ;
109
132
110
133
eventWaitHandle . WaitOne ( ) ;
111
134
}
0 commit comments