Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(728)

Side by Side Diff: Src/GoogleApis.Tests/Apis/Http/ConfigurableMessageHandlerTest.cs

Issue 12772043: Issues 373 (Execute Bug), 374 (Remove Tests.Utility) and 375 (Clean warnings) (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Error in uploading the first time Created 10 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 Copyright 2013 Google Inc 2 Copyright 2013 Google Inc
3 3
4 Licensed under the Apache License, Version 2.0 (the "License"); 4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License. 5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at 6 You may obtain a copy of the License at
7 7
8 http://www.apache.org/licenses/LICENSE-2.0 8 http://www.apache.org/licenses/LICENSE-2.0
9 9
10 Unless required by applicable law or agreed to in writing, software 10 Unless required by applicable law or agreed to in writing, software
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 { 44 {
45 public bool HandleResponse(HandleUnsuccessfulResponseArgs args) 45 public bool HandleResponse(HandleUnsuccessfulResponseArgs args)
46 { 46 {
47 return true; 47 return true;
48 } 48 }
49 } 49 }
50 50
51 /// <summary> Message handler which returns a new successful (and empty) response. </summary> 51 /// <summary> Message handler which returns a new successful (and empty) response. </summary>
52 private class MockMessageHandler : HttpMessageHandler 52 private class MockMessageHandler : HttpMessageHandler
53 { 53 {
54 protected override async Task<HttpResponseMessage> SendAsync(HttpReq uestMessage request, 54 protected override Task<HttpResponseMessage> SendAsync(HttpRequestMe ssage request,
55 CancellationToken cancellationToken) 55 CancellationToken cancellationToken)
56 { 56 {
57 return new HttpResponseMessage(); 57 TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompleti onSource<HttpResponseMessage>();
58 tcs.SetResult(new HttpResponseMessage());
59 return tcs.Task;
58 } 60 }
59 } 61 }
60 62
61 #endregion 63 #endregion
62 64
63 #region Redirect 65 #region Redirect
64 66
65 /// <summary> Redirect message handler which return redirect response. < /summary> 67 /// <summary> Redirect message handler which return redirect response. < /summary>
66 private class RedirectMessageHandler : CountableMessageHandler 68 private class RedirectMessageHandler : CountableMessageHandler
67 { 69 {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 /// Mock interceptor handler which verifies that an interceptor is being called on a request.· 175 /// Mock interceptor handler which verifies that an interceptor is being called on a request.·
174 /// </summary> 176 /// </summary>
175 private class InterceptorMessageHandler : CountableMessageHandler 177 private class InterceptorMessageHandler : CountableMessageHandler
176 { 178 {
177 /// <summary> Gets or sets an injected response message which will b e returned on send. </summary> 179 /// <summary> Gets or sets an injected response message which will b e returned on send. </summary>
178 public HttpResponseMessage InjectedResponseMessage { get; set; } 180 public HttpResponseMessage InjectedResponseMessage { get; set; }
179 181
180 const string InjectedHeader = "Some-Header"; 182 const string InjectedHeader = "Some-Header";
181 const string InjectedValue = "123"; 183 const string InjectedValue = "123";
182 184
183 protected override async Task<HttpResponseMessage> SendAsyncCore(Htt pRequestMessage request, 185 protected override Task<HttpResponseMessage> SendAsyncCore(HttpReque stMessage request,
184 CancellationToken cancellationToken) 186 CancellationToken cancellationToken)
185 { 187 {
186 Assert.That(request.Headers.GetValues(InjectedHeader).First(), I s.EqualTo(InjectedValue)); 188 Assert.That(request.Headers.GetValues(InjectedHeader).First(), I s.EqualTo(InjectedValue));
187 return InjectedResponseMessage; 189
190 TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompleti onSource<HttpResponseMessage>();
191 tcs.SetResult(InjectedResponseMessage);
192 return tcs.Task;
188 } 193 }
189 194
190 /// <summary> A mock interceptor which inject a header to a request. </summary> 195 /// <summary> A mock interceptor which inject a header to a request. </summary>
191 internal class Interceptor : IHttpExecuteInterceptor 196 internal class Interceptor : IHttpExecuteInterceptor
192 { 197 {
193 public int Calls { get; set; } 198 public int Calls { get; set; }
194 199
195 public void Intercept(HttpRequestMessage request) 200 public void Intercept(HttpRequestMessage request)
196 { 201 {
197 ++Calls; 202 ++Calls;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 public HttpStatusCode ResponseStatusCode { get; set; } 286 public HttpStatusCode ResponseStatusCode { get; set; }
282 287
283 /// <summary> Gets or sets the cancellation token source.</summary> 288 /// <summary> Gets or sets the cancellation token source.</summary>
284 public CancellationTokenSource CancellationTokenSource { get; set; } 289 public CancellationTokenSource CancellationTokenSource { get; set; }
285 290
286 /// <summary>· 291 /// <summary>·
287 /// Gets or sets the request number to invoke the Cancel method on < see cref="CancellationTokenSource"/>. 292 /// Gets or sets the request number to invoke the Cancel method on < see cref="CancellationTokenSource"/>.
288 /// </summary> 293 /// </summary>
289 public int CancelRequestNum { get; set; } 294 public int CancelRequestNum { get; set; }
290 295
291 protected override async Task<HttpResponseMessage> SendAsyncCore(Htt pRequestMessage request, 296 protected override Task<HttpResponseMessage> SendAsyncCore(HttpReque stMessage request,
292 CancellationToken cancellationToken) 297 CancellationToken cancellationToken)
293 { 298 {
294 if (Calls == CancelRequestNum) 299 if (Calls == CancelRequestNum)
295 { 300 {
296 CancellationTokenSource.Cancel(); 301 CancellationTokenSource.Cancel();
297 } 302 }
298 303
299 return new HttpResponseMessage { StatusCode = ResponseStatusCode }; 304 TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompleti onSource<HttpResponseMessage>();
305 tcs.SetResult(new HttpResponseMessage { StatusCode = ResponseSta tusCode });
306 return tcs.Task;
300 } 307 }
301 308
302 /// <summary> Unsuccessful response handler which "handles" only ser vice unavailable responses. </summary> 309 /// <summary> Unsuccessful response handler which "handles" only ser vice unavailable responses. </summary>
303 internal class ServiceUnavailableResponseHandler : IHttpUnsuccessful ResponseHandler 310 internal class ServiceUnavailableResponseHandler : IHttpUnsuccessful ResponseHandler
304 { 311 {
305 public int Calls { get; set; } 312 public int Calls { get; set; }
306 313
307 public bool HandleResponse(HandleUnsuccessfulResponseArgs args) 314 public bool HandleResponse(HandleUnsuccessfulResponseArgs args)
308 { 315 {
309 ++Calls; 316 ++Calls;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 /// <summary>· 416 /// <summary>·
410 /// Gets or sets a specific exception to throw. Default value is <se ealso cref="System.Exception"/>· 417 /// Gets or sets a specific exception to throw. Default value is <se ealso cref="System.Exception"/>·
411 /// with <see cref="ExceptionMessage"/>. </summary> 418 /// with <see cref="ExceptionMessage"/>. </summary>
412 public Exception Exception { get; set; } 419 public Exception Exception { get; set; }
413 420
414 /// <summary>· 421 /// <summary>·
415 /// The exception message which is thrown in case <see cref="ThrowEx ception"/> is <c>true</c>.· 422 /// The exception message which is thrown in case <see cref="ThrowEx ception"/> is <c>true</c>.·
416 /// </summary> 423 /// </summary>
417 public const string ExceptionMessage = "Exception from execute"; 424 public const string ExceptionMessage = "Exception from execute";
418 425
419 protected override async Task<HttpResponseMessage> SendAsyncCore(Htt pRequestMessage request, 426 protected override Task<HttpResponseMessage> SendAsyncCore(HttpReque stMessage request,
420 CancellationToken cancellationToken) 427 CancellationToken cancellationToken)
421 { 428 {
422 if (ThrowException) 429 if (ThrowException)
423 { 430 {
424 throw Exception; 431 throw Exception;
425 } 432 }
426 433
427 return new HttpResponseMessage(); 434 TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompleti onSource<HttpResponseMessage>();
435 tcs.SetResult(new HttpResponseMessage());
436 return tcs.Task;
428 } 437 }
429 438
430 /// <summary> Mock Exception handler which "handles" the exception. </summary> 439 /// <summary> Mock Exception handler which "handles" the exception. </summary>
431 internal class ExceptionHandler : IHttpExceptionHandler 440 internal class ExceptionHandler : IHttpExceptionHandler
432 { 441 {
433 public int Calls { get; set; } 442 public int Calls { get; set; }
434 public bool Handle { get; set; } 443 public bool Handle { get; set; }
435 444
436 public ExceptionHandler(bool handle = true) 445 public ExceptionHandler(bool handle = true)
437 { 446 {
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 // with application name 1000 // with application name
992 configurableHanlder.ApplicationName = applicationName; 1001 configurableHanlder.ApplicationName = applicationName;
993 request = new HttpRequestMessage(HttpMethod.Get, "https://test-u ser-agent"); 1002 request = new HttpRequestMessage(HttpMethod.Get, "https://test-u ser-agent");
994 response = client.SendAsync(request).Result; 1003 response = client.SendAsync(request).Result;
995 userAgent = string.Join(" ", request.Headers.GetValues("User-Age nt").ToArray()); 1004 userAgent = string.Join(" ", request.Headers.GetValues("User-Age nt").ToArray());
996 Assert.That(userAgent, Is.EqualTo(applicationName + " " + apiVer sion)); 1005 Assert.That(userAgent, Is.EqualTo(applicationName + " " + apiVer sion));
997 } 1006 }
998 } 1007 }
999 } 1008 }
1000 } 1009 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b