LEFT | RIGHT |
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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 using Newtonsoft.Json; | 27 using Newtonsoft.Json; |
28 using NUnit.Framework; | 28 using NUnit.Framework; |
29 | 29 |
30 using Google.Apis.Authentication; | 30 using Google.Apis.Authentication; |
31 using Google.Apis.Discovery; | 31 using Google.Apis.Discovery; |
32 using Google.Apis.Http; | 32 using Google.Apis.Http; |
33 using Google.Apis.Json; | 33 using Google.Apis.Json; |
34 using Google.Apis.Requests; | 34 using Google.Apis.Requests; |
35 using Google.Apis.Services; | 35 using Google.Apis.Services; |
36 using Google.Apis.Testing; | 36 using Google.Apis.Tests; |
37 using Google.Apis.Tests._Mock_; | |
38 using Google.Apis.Util; | 37 using Google.Apis.Util; |
39 | 38 |
40 namespace Google.Apis.Tests.Apis.Services | 39 namespace Google.Apis.Tests.Apis.Services |
41 { | 40 { |
42 /// <summary>Test for the BaseClientService class.</summary> | 41 /// <summary>Test for the BaseClientService class.</summary> |
43 [TestFixture] | 42 [TestFixture] |
44 public class BaseClientServiceTest | 43 public class BaseClientServiceTest |
45 { | 44 { |
46 /// <summary>A Json schema for testing serialization/deserialization.</s
ummary> | 45 /// <summary>A Json schema for testing serialization/deserialization.</s
ummary> |
47 internal class MockJsonSchema : IDirectResponseSchema | 46 internal class MockJsonSchema : IDirectResponseSchema |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 Assert.That(request.Method, Is.EqualTo(HttpMethod.Post)); | 398 Assert.That(request.Method, Is.EqualTo(HttpMethod.Post)); |
400 Assert.That(request.Headers.GetValues("X-HTTP-Method-Override").
Single(), Is.EqualTo("GET")); | 399 Assert.That(request.Headers.GetValues("X-HTTP-Method-Override").
Single(), Is.EqualTo("GET")); |
401 Assert.That(request.Content.Headers.ContentType, | 400 Assert.That(request.Content.Headers.ContentType, |
402 Is.EqualTo(new MediaTypeHeaderValue("application/x-www-form-
urlencoded"))); | 401 Is.EqualTo(new MediaTypeHeaderValue("application/x-www-form-
urlencoded"))); |
403 Assert.That(request.RequestUri, Is.EqualTo(new Uri(uri))); | 402 Assert.That(request.RequestUri, Is.EqualTo(new Uri(uri))); |
404 Assert.That(messageHandler.RequestContent, Is.EqualTo(query)); | 403 Assert.That(messageHandler.RequestContent, Is.EqualTo(query)); |
405 } | 404 } |
406 } | 405 } |
407 | 406 |
408 /// <summary> | 407 /// <summary> |
409 /// Verifies that URLs of greath lengths on GET requests are NOT transla
ted to a POST request when the user | 408 /// Verifies that URLs of great lengths on GET requests are NOT translat
ed to a POST request when the user |
410 /// sets the <c>maxUrlLength = 0</c>. | 409 /// sets the <c>maxUrlLength = 0</c>. |
411 /// </summary> | 410 /// </summary> |
412 [Test] | 411 [Test] |
413 public void TestGetWithUrlMaxLengthDisabled() | 412 public void TestGetWithUrlMaxLengthDisabled() |
414 { | 413 { |
415 var query = "q=" + new String('x', 5000) + "&x=" + new String('y', 6
000); | 414 var query = "q=" + new String('x', 5000) + "&x=" + new String('y', 6
000); |
416 var uri = "http://www.example.com/"; | 415 var uri = "http://www.example.com/"; |
417 var requestUri = uri + "?" + query; | 416 var requestUri = uri + "?" + query; |
418 var request = new HttpRequestMessage(HttpMethod.Get, requestUri); | 417 var request = new HttpRequestMessage(HttpMethod.Get, requestUri); |
419 var messageHandler = new MockMessageHandler(); | 418 var messageHandler = new MockMessageHandler(); |
420 using (var service = new MockClientService(new BaseClientService.Ini
tializer() | 419 var initializer = (new BaseClientService.Initializer |
421 { | 420 { |
422 HttpClientFactory = new MockHttpClientFactory(messageHandler
), | 421 HttpClientFactory = new MockHttpClientFactory(messageHandler), |
423 MaxUrlLength = 0 | 422 MaxUrlLength = 0 |
424 })) | 423 }); |
| 424 |
| 425 using (var service = new MockClientService(initializer)) |
425 { | 426 { |
426 service.HttpClient.SendAsync(request); | 427 service.HttpClient.SendAsync(request); |
427 // Confirm the request was not modified: | 428 // Confirm the request was not modified. |
428 Assert.That(request.RequestUri.ToString().Length, Is.EqualTo(req
uestUri.Length)); | 429 Assert.That(request.RequestUri.ToString().Length, Is.EqualTo(req
uestUri.Length)); |
429 Assert.That(request.Method, Is.EqualTo(HttpMethod.Get)); | 430 Assert.That(request.Method, Is.EqualTo(HttpMethod.Get)); |
430 Assert.That(request.Headers.Contains("X-HTTP-Method-Override"),
Is.False); | 431 Assert.That(request.Headers.Contains("X-HTTP-Method-Override"),
Is.False); |
431 Assert.That(request.Content, Is.Null); | 432 Assert.That(request.Content, Is.Null); |
432 Assert.That(request.RequestUri, Is.EqualTo(new Uri(requestUri)))
; | 433 Assert.That(request.RequestUri, Is.EqualTo(new Uri(requestUri)))
; |
433 } | 434 } |
434 } | 435 } |
435 } | 436 } |
436 } | 437 } |
LEFT | RIGHT |