@@ -24,44 +24,18 @@ static void AssertHasRequestBody(string contentType, string bodyData) {
24
24
Assert . Equal ( bodyData , RequestBodyCapturer . CapturedEntityBody ) ;
25
25
}
26
26
27
- class RequestBodyCapturer {
28
- public const string RESOURCE = "Capture" ;
29
-
30
- public static string CapturedContentType { get ; set ; }
31
-
32
- public static bool CapturedHasEntityBody { get ; set ; }
33
-
34
- public static string CapturedEntityBody { get ; set ; }
35
-
36
- public static void Capture ( HttpListenerContext context ) {
37
- var request = context . Request ;
38
-
39
- CapturedContentType = request . ContentType ;
40
- CapturedHasEntityBody = request . HasEntityBody ;
41
- CapturedEntityBody = StreamToString ( request . InputStream ) ;
42
- }
43
-
44
- static string StreamToString ( Stream stream ) {
45
- var streamReader = new StreamReader ( stream ) ;
46
- return streamReader . ReadToEnd ( ) ;
47
- }
48
- }
49
-
50
27
[ Fact ]
51
- public void Can_Be_Added_To_COPY_Request ( ) {
28
+ public async Task Can_Be_Added_To_COPY_Request ( ) {
52
29
const Method httpMethod = Method . COPY ;
53
30
54
- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
31
+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
55
32
56
33
const string contentType = "text/plain" ;
57
34
const string bodyData = "abc123 foo bar baz BING!" ;
58
35
59
36
request . AddParameter ( contentType , bodyData , ParameterType . RequestBody ) ;
60
37
61
- var resetEvent = new ManualResetEvent ( false ) ;
62
-
63
- _client . ExecuteAsync ( request , response => resetEvent . Set ( ) ) ;
64
- resetEvent . WaitOne ( ) ;
38
+ await _client . ExecuteAsync ( request ) ;
65
39
66
40
AssertHasRequestBody ( contentType , bodyData ) ;
67
41
}
@@ -70,7 +44,7 @@ public void Can_Be_Added_To_COPY_Request() {
70
44
public void Can_Be_Added_To_DELETE_Request ( ) {
71
45
const Method httpMethod = Method . DELETE ;
72
46
73
- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
47
+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
74
48
75
49
const string contentType = "text/plain" ;
76
50
const string bodyData = "abc123 foo bar baz BING!" ;
@@ -89,7 +63,7 @@ public void Can_Be_Added_To_DELETE_Request() {
89
63
public void Can_Be_Added_To_OPTIONS_Request ( ) {
90
64
const Method httpMethod = Method . OPTIONS ;
91
65
92
- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
66
+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
93
67
94
68
const string contentType = "text/plain" ;
95
69
const string bodyData = "abc123 foo bar baz BING!" ;
@@ -108,7 +82,7 @@ public void Can_Be_Added_To_OPTIONS_Request() {
108
82
public void Can_Be_Added_To_PATCH_Request ( ) {
109
83
const Method httpMethod = Method . PATCH ;
110
84
111
- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
85
+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
112
86
113
87
const string contentType = "text/plain" ;
114
88
const string bodyData = "abc123 foo bar baz BING!" ;
@@ -127,7 +101,7 @@ public void Can_Be_Added_To_PATCH_Request() {
127
101
public void Can_Be_Added_To_POST_Request ( ) {
128
102
const Method httpMethod = Method . POST ;
129
103
130
- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
104
+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
131
105
132
106
const string contentType = "text/plain" ;
133
107
const string bodyData = "abc123 foo bar baz BING!" ;
@@ -146,7 +120,7 @@ public void Can_Be_Added_To_POST_Request() {
146
120
public void Can_Be_Added_To_PUT_Request ( ) {
147
121
const Method httpMethod = Method . PUT ;
148
122
149
- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
123
+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
150
124
151
125
const string contentType = "text/plain" ;
152
126
const string bodyData = "abc123 foo bar baz BING!" ;
@@ -165,7 +139,7 @@ public void Can_Be_Added_To_PUT_Request() {
165
139
public void Can_Have_No_Body_Added_To_POST_Request ( ) {
166
140
const Method httpMethod = Method . POST ;
167
141
168
- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
142
+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
169
143
var resetEvent = new ManualResetEvent ( false ) ;
170
144
171
145
_client . ExecuteAsync ( request , response => resetEvent . Set ( ) ) ;
@@ -175,20 +149,17 @@ public void Can_Have_No_Body_Added_To_POST_Request() {
175
149
}
176
150
177
151
[ Fact ]
178
- public void Can_Not_Be_Added_To_GET_Request ( ) {
152
+ public async Task Can_Be_Added_To_GET_Request ( ) {
179
153
const Method httpMethod = Method . GET ;
180
154
181
- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
155
+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
182
156
183
157
const string contentType = "text/plain" ;
184
158
const string bodyData = "abc123 foo bar baz BING!" ;
185
159
186
160
request . AddParameter ( contentType , bodyData , ParameterType . RequestBody ) ;
187
161
188
- var resetEvent = new ManualResetEvent ( false ) ;
189
-
190
- _client . ExecuteAsync ( request , response => resetEvent . Set ( ) ) ;
191
- resetEvent . WaitOne ( ) ;
162
+ await _client . ExecuteAsync ( request ) ;
192
163
193
164
AssertHasNoRequestBody ( ) ;
194
165
}
@@ -197,7 +168,7 @@ public void Can_Not_Be_Added_To_GET_Request() {
197
168
public void Can_Not_Be_Added_To_HEAD_Request ( ) {
198
169
const Method httpMethod = Method . HEAD ;
199
170
200
- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
171
+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
201
172
202
173
const string contentType = "text/plain" ;
203
174
const string bodyData = "abc123 foo bar baz BING!" ;
0 commit comments