@@ -24,44 +24,18 @@ static void AssertHasRequestBody(string contentType, string bodyData) {
2424 Assert . Equal ( bodyData , RequestBodyCapturer . CapturedEntityBody ) ;
2525 }
2626
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-
5027 [ Fact ]
51- public void Can_Be_Added_To_COPY_Request ( ) {
28+ public async Task Can_Be_Added_To_COPY_Request ( ) {
5229 const Method httpMethod = Method . COPY ;
5330
54- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
31+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
5532
5633 const string contentType = "text/plain" ;
5734 const string bodyData = "abc123 foo bar baz BING!" ;
5835
5936 request . AddParameter ( contentType , bodyData , ParameterType . RequestBody ) ;
6037
61- var resetEvent = new ManualResetEvent ( false ) ;
62-
63- _client . ExecuteAsync ( request , response => resetEvent . Set ( ) ) ;
64- resetEvent . WaitOne ( ) ;
38+ await _client . ExecuteAsync ( request ) ;
6539
6640 AssertHasRequestBody ( contentType , bodyData ) ;
6741 }
@@ -70,7 +44,7 @@ public void Can_Be_Added_To_COPY_Request() {
7044 public void Can_Be_Added_To_DELETE_Request ( ) {
7145 const Method httpMethod = Method . DELETE ;
7246
73- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
47+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
7448
7549 const string contentType = "text/plain" ;
7650 const string bodyData = "abc123 foo bar baz BING!" ;
@@ -89,7 +63,7 @@ public void Can_Be_Added_To_DELETE_Request() {
8963 public void Can_Be_Added_To_OPTIONS_Request ( ) {
9064 const Method httpMethod = Method . OPTIONS ;
9165
92- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
66+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
9367
9468 const string contentType = "text/plain" ;
9569 const string bodyData = "abc123 foo bar baz BING!" ;
@@ -108,7 +82,7 @@ public void Can_Be_Added_To_OPTIONS_Request() {
10882 public void Can_Be_Added_To_PATCH_Request ( ) {
10983 const Method httpMethod = Method . PATCH ;
11084
111- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
85+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
11286
11387 const string contentType = "text/plain" ;
11488 const string bodyData = "abc123 foo bar baz BING!" ;
@@ -127,7 +101,7 @@ public void Can_Be_Added_To_PATCH_Request() {
127101 public void Can_Be_Added_To_POST_Request ( ) {
128102 const Method httpMethod = Method . POST ;
129103
130- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
104+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
131105
132106 const string contentType = "text/plain" ;
133107 const string bodyData = "abc123 foo bar baz BING!" ;
@@ -146,7 +120,7 @@ public void Can_Be_Added_To_POST_Request() {
146120 public void Can_Be_Added_To_PUT_Request ( ) {
147121 const Method httpMethod = Method . PUT ;
148122
149- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
123+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
150124
151125 const string contentType = "text/plain" ;
152126 const string bodyData = "abc123 foo bar baz BING!" ;
@@ -165,7 +139,7 @@ public void Can_Be_Added_To_PUT_Request() {
165139 public void Can_Have_No_Body_Added_To_POST_Request ( ) {
166140 const Method httpMethod = Method . POST ;
167141
168- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
142+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
169143 var resetEvent = new ManualResetEvent ( false ) ;
170144
171145 _client . ExecuteAsync ( request , response => resetEvent . Set ( ) ) ;
@@ -175,20 +149,17 @@ public void Can_Have_No_Body_Added_To_POST_Request() {
175149 }
176150
177151 [ Fact ]
178- public void Can_Not_Be_Added_To_GET_Request ( ) {
152+ public async Task Can_Be_Added_To_GET_Request ( ) {
179153 const Method httpMethod = Method . GET ;
180154
181- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
155+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
182156
183157 const string contentType = "text/plain" ;
184158 const string bodyData = "abc123 foo bar baz BING!" ;
185159
186160 request . AddParameter ( contentType , bodyData , ParameterType . RequestBody ) ;
187161
188- var resetEvent = new ManualResetEvent ( false ) ;
189-
190- _client . ExecuteAsync ( request , response => resetEvent . Set ( ) ) ;
191- resetEvent . WaitOne ( ) ;
162+ await _client . ExecuteAsync ( request ) ;
192163
193164 AssertHasNoRequestBody ( ) ;
194165 }
@@ -197,7 +168,7 @@ public void Can_Not_Be_Added_To_GET_Request() {
197168 public void Can_Not_Be_Added_To_HEAD_Request ( ) {
198169 const Method httpMethod = Method . HEAD ;
199170
200- var request = new RestRequest ( RequestBodyCapturer . RESOURCE , httpMethod ) ;
171+ var request = new RestRequest ( RequestBodyCapturer . Resource , httpMethod ) ;
201172
202173 const string contentType = "text/plain" ;
203174 const string bodyData = "abc123 foo bar baz BING!" ;
0 commit comments