@@ -10,10 +10,10 @@ public async Task UsingTestHandler_WithoutSettingUpResponse_Returns200OKWithoutC
1010 using TestableHttpMessageHandler testHandler = new ( ) ;
1111
1212 using HttpClient httpClient = new ( testHandler ) ;
13- HttpResponseMessage result = await httpClient . GetAsync ( "http://httpbin.org/status/200" ) ;
13+ HttpResponseMessage result = await httpClient . GetAsync ( "http://httpbin.org/status/200" , TestContext . Current . CancellationToken ) ;
1414
1515 Assert . Equal ( HttpStatusCode . OK , result . StatusCode ) ;
16- Assert . Equal ( string . Empty , await result . Content . ReadAsStringAsync ( ) ) ;
16+ Assert . Equal ( string . Empty , await result . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ) ;
1717 }
1818
1919 [ Fact ]
@@ -23,10 +23,10 @@ public async Task UsingTestHandlerWithCustomResponse_ReturnsCustomResponse()
2323 testHandler . RespondWith ( Text ( "HttpClient testing is easy" ) ) ;
2424
2525 using HttpClient httpClient = new ( testHandler ) ;
26- HttpResponseMessage result = await httpClient . GetAsync ( "http://httpbin.org/status/200" ) ;
26+ HttpResponseMessage result = await httpClient . GetAsync ( "http://httpbin.org/status/200" , TestContext . Current . CancellationToken ) ;
2727
2828 Assert . Equal ( HttpStatusCode . OK , result . StatusCode ) ;
29- Assert . Equal ( "HttpClient testing is easy" , await result . Content . ReadAsStringAsync ( ) ) ;
29+ Assert . Equal ( "HttpClient testing is easy" , await result . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ) ;
3030 }
3131
3232 [ Fact ]
@@ -37,10 +37,10 @@ public async Task UsingTestHandlerWithMultipleCustomResponse_ReturnsLastCustomRe
3737 testHandler . RespondWith ( Json ( "Not Found" , HttpStatusCode . NotFound ) ) ;
3838
3939 using HttpClient httpClient = new ( testHandler ) ;
40- HttpResponseMessage result = await httpClient . GetAsync ( "http://httpbin.org/status/201" ) ;
40+ HttpResponseMessage result = await httpClient . GetAsync ( "http://httpbin.org/status/201" , TestContext . Current . CancellationToken ) ;
4141
4242 Assert . Equal ( HttpStatusCode . NotFound , result . StatusCode ) ;
43- Assert . Equal ( "\" Not Found\" " , await result . Content . ReadAsStringAsync ( ) ) ;
43+ Assert . Equal ( "\" Not Found\" " , await result . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ) ;
4444 }
4545
4646 [ Fact ]
@@ -60,10 +60,10 @@ public async Task UsingTestHandlerWithCustomResponse_AlwaysReturnsSameCustomResp
6060
6161 foreach ( string ? url in urls )
6262 {
63- HttpResponseMessage result = await httpClient . GetAsync ( url ) ;
63+ HttpResponseMessage result = await httpClient . GetAsync ( url , TestContext . Current . CancellationToken ) ;
6464
6565 Assert . Equal ( HttpStatusCode . OK , result . StatusCode ) ;
66- Assert . Equal ( "HttpClient testing is easy" , await result . Content . ReadAsStringAsync ( ) ) ;
66+ Assert . Equal ( "HttpClient testing is easy" , await result . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ) ;
6767 }
6868 }
6969
@@ -85,13 +85,13 @@ static IResponse PathBasedResponse(HttpResponseContext context)
8585 testHandler . RespondWith ( SelectResponse ( PathBasedResponse ) ) ;
8686
8787 using HttpClient httpClient = new ( testHandler ) ;
88- HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin/status/200" ) ;
88+ HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin/status/200" , TestContext . Current . CancellationToken ) ;
8989 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
9090
91- response = await httpClient . GetAsync ( "http://httpbin.org/status/400" ) ;
91+ response = await httpClient . GetAsync ( "http://httpbin.org/status/400" , TestContext . Current . CancellationToken ) ;
9292 Assert . Equal ( HttpStatusCode . BadRequest , response . StatusCode ) ;
9393
94- response = await httpClient . GetAsync ( "http://httpbin.org/status/500" ) ;
94+ response = await httpClient . GetAsync ( "http://httpbin.org/status/500" , TestContext . Current . CancellationToken ) ;
9595 Assert . Equal ( HttpStatusCode . NotFound , response . StatusCode ) ;
9696 }
9797
@@ -108,16 +108,16 @@ public async Task UsingTestHandlerWithRoute_AllowsForRoutingUseCases()
108108 } ) ) ;
109109
110110 using HttpClient httpClient = new ( testHandler ) ;
111- HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin/status/200" ) ;
111+ HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin/status/200" , TestContext . Current . CancellationToken ) ;
112112 Assert . Equal ( HttpStatusCode . Redirect , response . StatusCode ) ;
113113
114- response = await httpClient . GetAsync ( "https://httpbin/status/200" ) ;
114+ response = await httpClient . GetAsync ( "https://httpbin/status/200" , TestContext . Current . CancellationToken ) ;
115115 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
116116
117- response = await httpClient . GetAsync ( "https://httpbin.org/status/400" ) ;
117+ response = await httpClient . GetAsync ( "https://httpbin.org/status/400" , TestContext . Current . CancellationToken ) ;
118118 Assert . Equal ( HttpStatusCode . BadRequest , response . StatusCode ) ;
119119
120- response = await httpClient . GetAsync ( "https://httpbin.org/status/500" ) ;
120+ response = await httpClient . GetAsync ( "https://httpbin.org/status/500" , TestContext . Current . CancellationToken ) ;
121121 Assert . Equal ( HttpStatusCode . NotFound , response . StatusCode ) ;
122122 }
123123
@@ -128,7 +128,7 @@ public async Task SimulateTimeout_WillThrowExceptionSimulatingTheTimeout()
128128 testHandler . RespondWith ( Timeout ( ) ) ;
129129
130130 using HttpClient httpClient = new ( testHandler ) ;
131- await Assert . ThrowsAsync < TaskCanceledException > ( ( ) => httpClient . GetAsync ( "https://httpbin.org/delay/500" ) ) ;
131+ await Assert . ThrowsAsync < TaskCanceledException > ( ( ) => httpClient . GetAsync ( "https://httpbin.org/delay/500" , TestContext . Current . CancellationToken ) ) ;
132132 }
133133
134134 [ Fact ]
@@ -143,20 +143,20 @@ public async Task UsingTestHandlerWithSequencedResponses_WillReturnDifferentResp
143143 ) ) ;
144144
145145 using HttpClient httpClient = new ( testHandler ) ;
146- HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin.org/anything" ) ;
146+ HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin.org/anything" , TestContext . Current . CancellationToken ) ;
147147 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
148148
149- response = await httpClient . GetAsync ( "http://httpbin.org/anything" ) ;
149+ response = await httpClient . GetAsync ( "http://httpbin.org/anything" , TestContext . Current . CancellationToken ) ;
150150 Assert . Equal ( HttpStatusCode . Unauthorized , response . StatusCode ) ;
151151
152- response = await httpClient . GetAsync ( "http://httpbin.org/anything" ) ;
152+ response = await httpClient . GetAsync ( "http://httpbin.org/anything" , TestContext . Current . CancellationToken ) ;
153153 Assert . Equal ( HttpStatusCode . NoContent , response . StatusCode ) ;
154154
155- response = await httpClient . GetAsync ( "http://httpbin.org/anything" ) ;
155+ response = await httpClient . GetAsync ( "http://httpbin.org/anything" , TestContext . Current . CancellationToken ) ;
156156 Assert . Equal ( HttpStatusCode . NotFound , response . StatusCode ) ;
157157
158158 // Last configured response is returned when all other responses are used.
159- response = await httpClient . GetAsync ( "http://httpbin.org/anything" ) ;
159+ response = await httpClient . GetAsync ( "http://httpbin.org/anything" , TestContext . Current . CancellationToken ) ;
160160 Assert . Equal ( HttpStatusCode . NotFound , response . StatusCode ) ;
161161 }
162162
@@ -167,7 +167,7 @@ public async Task UsingTestHandlerWithDelayedResponses_WillDelayTheResponse()
167167 testHandler . RespondWith ( Delayed ( StatusCode ( HttpStatusCode . OK ) , TimeSpan . FromSeconds ( 1 ) ) ) ;
168168
169169 using HttpClient httpClient = new ( testHandler ) ;
170- HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin.org/anything" ) ;
170+ HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin.org/anything" , TestContext . Current . CancellationToken ) ;
171171 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
172172 }
173173
@@ -178,7 +178,7 @@ public async Task UsingTestHandlerWithConfiguredResponses_WillConfigureTheRespon
178178 testHandler . RespondWith ( Configured ( StatusCode ( HttpStatusCode . NoContent ) , x => x . Headers . Add ( "server" , "test" ) ) ) ;
179179
180180 using HttpClient httpClient = new ( testHandler ) ;
181- HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin.org/anything" ) ;
181+ HttpResponseMessage response = await httpClient . GetAsync ( "http://httpbin.org/anything" , TestContext . Current . CancellationToken ) ;
182182 Assert . Equal ( "test" , response . Headers . Server . ToString ( ) ) ;
183183 }
184184}
0 commit comments