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 19 matching lines...) Expand all Loading... |
30 using Google.Apis.Discovery; | 30 using Google.Apis.Discovery; |
31 using Google.Apis.Http; | 31 using Google.Apis.Http; |
32 using Google.Apis.Json; | 32 using Google.Apis.Json; |
33 using Google.Apis.Requests; | 33 using Google.Apis.Requests; |
34 using Google.Apis.Services; | 34 using Google.Apis.Services; |
35 using Google.Apis.Testing; | 35 using Google.Apis.Testing; |
36 using Google.Apis.Util; | 36 using Google.Apis.Util; |
37 | 37 |
38 namespace Google.Apis.Tests.Apis.Services | 38 namespace Google.Apis.Tests.Apis.Services |
39 { | 39 { |
40 /// <summary> Test for the BaseClientService class. </summary> | 40 /// <summary>Test for the BaseClientService class.</summary> |
41 [TestFixture] | 41 [TestFixture] |
42 public class BaseClientServiceTest | 42 public class BaseClientServiceTest |
43 { | 43 { |
44 /// <summary> A Json schema for testing serialization/deserialization. <
/summary> | 44 /// <summary>A Json schema for testing serialization/deserialization.</s
ummary> |
45 internal class MockJsonSchema : IDirectResponseSchema | 45 internal class MockJsonSchema : IDirectResponseSchema |
46 { | 46 { |
47 [JsonProperty("kind")] | 47 [JsonProperty("kind")] |
48 public string Kind { get; set; } | 48 public string Kind { get; set; } |
49 | 49 |
50 [JsonProperty("longUrl")] | 50 [JsonProperty("longUrl")] |
51 public string LongURL { get; set; } | 51 public string LongURL { get; set; } |
52 | 52 |
53 [JsonProperty("status")] | 53 [JsonProperty("status")] |
54 public string Status { get; set; } | 54 public string Status { get; set; } |
55 | 55 |
56 public RequestError Error { get; set; } | 56 public RequestError Error { get; set; } |
57 | 57 |
58 public string ETag { get; set; } | 58 public string ETag { get; set; } |
59 } | 59 } |
60 | 60 |
61 private void CheckDeserializationResults(MockJsonSchema result) | 61 /// <summary>Validates the deserialization result.</summary> |
| 62 private void CheckDeserializationResult(MockJsonSchema result) |
62 { | 63 { |
63 Assert.NotNull(result); | 64 Assert.NotNull(result); |
64 Assert.That(result.Kind, Is.EqualTo("urlshortener#url")); | 65 Assert.That(result.Kind, Is.EqualTo("urlshortener#url")); |
65 Assert.That(result.LongURL, Is.EqualTo("http://google.com/")); | 66 Assert.That(result.LongURL, Is.EqualTo("http://google.com/")); |
66 Assert.That(result.Status, Is.Null); | 67 Assert.That(result.Status, Is.Null); |
67 } | 68 } |
68 | 69 |
69 private IClientService CreateClientServiceV_03() | 70 /// <summary>Creates a client service for the given features.</summary> |
70 { | 71 private IClientService CreateClientService(Features? features = null) |
71 return CreateClientService(DiscoveryVersion.Version_0_3); | |
72 } | |
73 | |
74 private IClientService CreateClientServiceV_1() | |
75 { | |
76 return CreateClientService(DiscoveryVersion.Version_1_0); | |
77 } | |
78 | |
79 private IClientService CreateClientService(DiscoveryVersion version) | |
80 { | 72 { |
81 var client = new MockClientService(); | 73 var client = new MockClientService(); |
82 if (version == DiscoveryVersion.Version_0_3) | 74 if (features.HasValue) |
83 client.SetFeatures(new[] { Features.LegacyDataResponse.GetString
Value() }); | 75 { |
| 76 client.SetFeatures(new[] { features.Value.GetStringValue() }); |
| 77 } |
| 78 |
84 return client; | 79 return client; |
85 } | 80 } |
86 | 81 |
87 /// <summary> This tests the v0.3 deserialization of the BaseService. </
summary> | 82 /// <summary>This tests deserialization with data wrapping.</summary> |
88 [Test] | 83 [Test] |
89 public void TestDeserializationV0_3() | 84 public void TestDeserialization_WithDataWrapping() |
90 { | 85 { |
91 const string ResponseV0_3 = | 86 const string Response = |
92 @"{ ""data"" :· | 87 @"{ ""data"" :· |
93 { | 88 { |
94 ""kind"": ""urlshortener#url"", | 89 ""kind"": ""urlshortener#url"", |
95 ""longUrl"": ""http://google.com/"", | 90 ""longUrl"": ""http://google.com/"", |
96 }· | 91 }· |
97 }"; | 92 }"; |
98 | 93 |
99 var client = CreateClientServiceV_03(); | 94 var client = CreateClientService(Features.LegacyDataResponse); |
100 | 95 |
101 // Check that the default serializer is set. | 96 // Check that the default serializer is set. |
102 Assert.IsInstanceOf<NewtonsoftJsonSerializer>(client.Serializer); | 97 Assert.IsInstanceOf<NewtonsoftJsonSerializer>(client.Serializer); |
103 | 98 |
104 // Check that the response is decoded correctly. | 99 // Check that the response is decoded correctly. |
105 var stream = new MemoryStream(Encoding.Default.GetBytes(ResponseV0_3
)); | 100 var stream = new MemoryStream(Encoding.Default.GetBytes(Response)); |
106 var response = new HttpResponseMessage { Content = new StreamContent
(stream) }; | 101 var response = new HttpResponseMessage { Content = new StreamContent
(stream) }; |
107 CheckDeserializationResults(client.DeserializeResponse<MockJsonSchem
a>(response).Result); | 102 CheckDeserializationResult(client.DeserializeResponse<MockJsonSchema
>(response).Result); |
108 } | 103 } |
109 | 104 |
110 | 105 |
111 /// <summary> This tests the v1 Deserialization of the BaseService. </su
mmary> | 106 /// <summary>This tests Deserialization without data wrapping.</summary> |
112 [Test] | 107 [Test] |
113 public void TestDeserializationV1() | 108 public void TestDeserialization_WithoutDataWrapping() |
114 { | 109 { |
115 const string ResponseV1 = @"{""kind"":""urlshortener#url"",""longUrl
"":""http://google.com/""}"; | 110 const string Response = @"{""kind"":""urlshortener#url"",""longUrl""
:""http://google.com/""}"; |
116 | 111 |
117 // by default the request provider doesn't contain the LegacyDataRes
ponse | 112 // by default the request provider doesn't contain the LegacyDataRes
ponse |
118 var client = CreateClientServiceV_1(); | 113 var client = CreateClientService(); |
119 | 114 |
120 // Check that the default serializer is set | 115 // Check that the default serializer is set |
121 Assert.IsInstanceOf<NewtonsoftJsonSerializer>(client.Serializer); | 116 Assert.IsInstanceOf<NewtonsoftJsonSerializer>(client.Serializer); |
122 | 117 |
123 // Check that the response is decoded correctly | 118 // Check that the response is decoded correctly |
124 var stream = new MemoryStream(Encoding.Default.GetBytes(ResponseV1))
; | 119 var stream = new MemoryStream(Encoding.Default.GetBytes(Response)); |
125 var response = new HttpResponseMessage { Content = new StreamContent
(stream) }; | 120 var response = new HttpResponseMessage { Content = new StreamContent
(stream) }; |
126 CheckDeserializationResults( | 121 CheckDeserializationResult( |
127 client.DeserializeResponse<MockJsonSchema>(response).Result); | 122 client.DeserializeResponse<MockJsonSchema>(response).Result); |
128 } | 123 } |
129 | 124 |
130 /// <summary> Tests if serialization works. </summary> | 125 /// <summary>Tests serialization with data wrapping.</summary> |
131 [Test] | 126 [Test] |
132 public void TestSerializationV0_3() | 127 public void TestSerialization_WithDataWrapping() |
133 { | 128 { |
134 const string ResponseV0_3 = | 129 const string Response = |
135 "{\"data\":{\"kind\":\"urlshortener#url\",\"longUrl\":\"http://g
oogle.com/\"}}"; | 130 "{\"data\":{\"kind\":\"urlshortener#url\",\"longUrl\":\"http://g
oogle.com/\"}}"; |
136 | 131 |
137 MockJsonSchema schema = new MockJsonSchema(); | 132 MockJsonSchema schema = new MockJsonSchema(); |
138 schema.Kind = "urlshortener#url"; | 133 schema.Kind = "urlshortener#url"; |
139 schema.LongURL = "http://google.com/"; | 134 schema.LongURL = "http://google.com/"; |
140 | 135 |
141 var client = CreateClientServiceV_03(); | 136 var client = CreateClientService(Features.LegacyDataResponse); |
142 | 137 |
143 // Check if a response is serialized correctly | 138 // Check if a response is serialized correctly |
144 string result = client.SerializeObject(schema); | 139 string result = client.SerializeObject(schema); |
145 Assert.AreEqual(ResponseV0_3, result); | 140 Assert.AreEqual(Response, result); |
146 } | 141 } |
147 | 142 |
148 /// <summary> Tests if serialization works. </summary> | 143 /// <summary>Tests serialization without data wrapping.</summary> |
149 [Test] | 144 [Test] |
150 public void TestSerializationV1() | 145 public void TestSerialization_WithoutDataWrapping() |
151 { | 146 { |
152 const string ResponseV1 = @"{""kind"":""urlshortener#url"",""longUrl
"":""http://google.com/""}"; | 147 const string Response = @"{""kind"":""urlshortener#url"",""longUrl""
:""http://google.com/""}"; |
153 | 148 |
154 MockJsonSchema schema = new MockJsonSchema(); | 149 MockJsonSchema schema = new MockJsonSchema(); |
155 schema.Kind = "urlshortener#url"; | 150 schema.Kind = "urlshortener#url"; |
156 schema.LongURL = "http://google.com/"; | 151 schema.LongURL = "http://google.com/"; |
157 | 152 |
158 var client = CreateClientServiceV_1(); | 153 var client = CreateClientService(); |
159 | 154 |
160 // Check if a response is serialized correctly | 155 // Check if a response is serialized correctly. |
161 string result = client.SerializeObject(schema); | 156 string result = client.SerializeObject(schema); |
162 Assert.AreEqual(ResponseV1, result); | 157 Assert.AreEqual(Response, result); |
163 } | 158 } |
164 | 159 |
165 /// <summary> | 160 /// <summary> |
166 /// Confirms that the serializer won't do anything if a string is the re
quested response type. | 161 /// Confirms that the serializer won't do anything if a string is the re
quested response type. |
167 /// </summary> | 162 /// </summary> |
168 [Test] | 163 [Test] |
169 public void TestDeserializationString() | 164 public void TestDeserializationString() |
170 { | 165 { |
171 const string ResponseV1 = @"{""kind"":""urlshortener#url"",""longUrl
"":""http://google.com/""}"; | 166 const string Response = @"{""kind"":""urlshortener#url"",""longUrl""
:""http://google.com/""}"; |
172 | 167 |
173 MockClientService client = new MockClientService(); | 168 MockClientService client = new MockClientService(); |
174 | 169 |
175 // Check that the response is decoded correctly | 170 // Check that the response is decoded correctly |
176 var stream = new MemoryStream(Encoding.Default.GetBytes(ResponseV1))
; | 171 var stream = new MemoryStream(Encoding.Default.GetBytes(Response)); |
177 var response = new HttpResponseMessage { Content = new StreamContent
(stream) }; | 172 var response = new HttpResponseMessage { Content = new StreamContent
(stream) }; |
178 string result = client.DeserializeResponse<string>(response).Result; | 173 string result = client.DeserializeResponse<string>(response).Result; |
179 Assert.AreEqual(ResponseV1, result); | 174 Assert.AreEqual(Response, result); |
180 } | 175 } |
181 | 176 |
182 /// <summary> Tests the deserialization for server error responses. </su
mmary> | 177 /// <summary>Tests deserialization for server error response.</summary> |
183 [Test] | 178 [Test] |
184 public void TestErrorDeserialization( | 179 public void TestErrorDeserialization( |
185 [Values(DiscoveryVersion.Version_0_3, DiscoveryVersion.Version_1_0)] D
iscoveryVersion version) | 180 [Values(Features.LegacyDataResponse, null)] Features? features) |
186 { | 181 { |
187 const string ErrorResponse = | 182 const string ErrorResponse = |
188 @"{ | 183 @"{ |
189 ""error"": { | 184 ""error"": { |
190 ""errors"": [ | 185 ""errors"": [ |
191 { | 186 { |
192 ""domain"": ""global"", | 187 ""domain"": ""global"", |
193 ""reason"": ""required"", | 188 ""reason"": ""required"", |
194 ""message"": ""Required"", | 189 ""message"": ""Required"", |
195 ""locationType"": ""parameter"", | 190 ""locationType"": ""parameter"", |
196 ""location"": ""resource.longUrl"" | 191 ""location"": ""resource.longUrl"" |
197 } | 192 } |
198 ], | 193 ], |
199 ""code"": 400, | 194 ""code"": 400, |
200 ""message"": ""Required"" | 195 ""message"": ""Required"" |
201 } | 196 } |
202 }"; | 197 }"; |
203 | 198 |
204 var client = CreateClientService(version); | 199 var client = CreateClientService(features); |
205 | 200 |
206 using (var stream = new MemoryStream(Encoding.Default.GetBytes(Error
Response))) | 201 using (var stream = new MemoryStream(Encoding.Default.GetBytes(Error
Response))) |
207 { | 202 { |
208 var response = new HttpResponseMessage { Content = new StreamCon
tent(stream) }; | 203 var response = new HttpResponseMessage { Content = new StreamCon
tent(stream) }; |
209 RequestError error = client.DeserializeError(response).Result; | 204 RequestError error = client.DeserializeError(response).Result; |
210 Assert.AreEqual(400, error.Code); | 205 Assert.AreEqual(400, error.Code); |
211 Assert.AreEqual("Required", error.Message); | 206 Assert.AreEqual("Required", error.Message); |
212 Assert.AreEqual(1, error.Errors.Count); | 207 Assert.AreEqual(1, error.Errors.Count); |
213 } | 208 } |
214 } | 209 } |
215 | 210 |
216 #region Authentication | 211 #region Authentication |
217 | 212 |
218 /// <summary> | 213 /// <summary> |
219 /// Mock authentication message handler which returns unauthorized respo
nse in the first call, and in the· | 214 /// A mock authentication message handler which returns an unauthorized
response in the first call, and a· |
220 /// second call it returns a successful response. | 215 /// successful response in the second. |
221 /// </summary> | 216 /// </summary> |
222 class MockAuthenticationMessageHandler : CountableMessageHandler | 217 class MockAuthenticationMessageHandler : CountableMessageHandler |
223 { | 218 { |
224 internal static string FirstToken = "invalid"; | 219 internal static string FirstToken = "invalid"; |
225 internal static string SecondToken = "valid"; | 220 internal static string SecondToken = "valid"; |
226 | 221 |
227 protected override Task<HttpResponseMessage> SendAsyncCore(HttpReque
stMessage request, | 222 protected override Task<HttpResponseMessage> SendAsyncCore(HttpReque
stMessage request, |
228 CancellationToken cancellationToken) | 223 CancellationToken cancellationToken) |
229 { | 224 { |
230 TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompleti
onSource<HttpResponseMessage>(); | 225 TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompleti
onSource<HttpResponseMessage>(); |
(...skipping 13 matching lines...) Expand all Loading... |
244 tcs.SetResult(new HttpResponseMessage()); | 239 tcs.SetResult(new HttpResponseMessage()); |
245 break; | 240 break; |
246 default: | 241 default: |
247 throw new Exception("There should be only two calls"); | 242 throw new Exception("There should be only two calls"); |
248 } | 243 } |
249 | 244 |
250 return tcs.Task; | 245 return tcs.Task; |
251 } | 246 } |
252 } | 247 } |
253 | 248 |
254 /// <summary> Mock Authenticator which adds Authorization header to a re
quest on the second call. </summary> | 249 /// <summary>A mock Authenticator which adds Authorization header to a r
equest on the second call.</summary> |
255 class Authenticator : IAuthenticator | 250 class Authenticator : IAuthenticator |
256 { | 251 { |
| 252 /// <summary>Gets ot set the number of calls to <see cref="ApplyAuth
enticationToRequest"/>.</summary> |
257 public int ApplyCalls { get; set; } | 253 public int ApplyCalls { get; set; } |
258 | 254 |
259 public void ApplyAuthenticationToRequest(System.Net.HttpWebRequest r
equest) | 255 public void ApplyAuthenticationToRequest(HttpWebRequest request) |
260 { | 256 { |
261 ApplyCalls ; | 257 ApplyCalls ; |
262 switch (ApplyCalls) | 258 switch (ApplyCalls) |
263 { | 259 { |
264 case 1: | 260 case 1: |
265 request.Headers["Authorization"] = MockAuthenticationMes
sageHandler.FirstToken; | 261 request.Headers["Authorization"] = MockAuthenticationMes
sageHandler.FirstToken; |
266 break; | 262 break; |
267 case 2: | 263 case 2: |
268 request.Headers["Authorization"] = MockAuthenticationMes
sageHandler.SecondToken; | 264 request.Headers["Authorization"] = MockAuthenticationMes
sageHandler.SecondToken; |
269 break; | 265 break; |
270 default: | 266 default: |
271 throw new Exception("There should be only two calls"); | 267 throw new Exception("There should be only two calls"); |
272 } | 268 } |
273 } | 269 } |
274 } | 270 } |
275 | 271 |
276 /// <summary> Mock Authenticator which handles unsuccessful response by
"refreshing" the token. </summary> | 272 /// <summary>Mock Authenticator which handles unsuccessful response by "
refreshing" the token.</summary> |
277 class AuthenticatorUnsuccessfulHandler : Authenticator, IHttpUnsuccessfu
lResponseHandler | 273 class AuthenticatorUnsuccessfulHandler : Authenticator, IHttpUnsuccessfu
lResponseHandler |
278 { | 274 { |
| 275 /// <summary>Gets or sets the number of calls to <see cref="HandleRe
sponseAsync"/>.</summary> |
279 public int HandleCalls { get; set; } | 276 public int HandleCalls { get; set; } |
280 | 277 |
281 public Task<bool> HandleResponseAsync(HandleUnsuccessfulResponseArgs
args) | 278 public Task<bool> HandleResponseAsync(HandleUnsuccessfulResponseArgs
args) |
282 { | 279 { |
283 HandleCalls ; | 280 HandleCalls ; |
284 // Mock a refresh token process here... (second apply will attac
h SecondToken authorization) | 281 // Mock a refresh token process here... (second apply will attac
h SecondToken authorization). |
285 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(
); | 282 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(
); |
286 tcs.SetResult(true); | 283 tcs.SetResult(true); |
287 return tcs.Task; | 284 return tcs.Task; |
288 } | 285 } |
289 } | 286 } |
290 | 287 |
291 /// <summary> | 288 /// <summary> |
292 /// Tests that authenticator helpers invokes both apply authentication a
nd handle response methods on the | 289 /// Tests that the authenticator helpers, when invoked, both apply authe
ntication and handle response methods· |
293 /// authentication instance. | 290 /// on the authentication instance. |
294 /// </summary> | 291 /// </summary> |
295 [Test] | 292 [Test] |
296 public void Test_Authentication_UnsuccessfulHandler() | 293 public void Test_Authentication_UnsuccessfulHandler() |
297 { | 294 { |
298 var handler = new MockAuthenticationMessageHandler(); | 295 var handler = new MockAuthenticationMessageHandler(); |
299 var authenticator = new AuthenticatorUnsuccessfulHandler(); | 296 var authenticator = new AuthenticatorUnsuccessfulHandler(); |
300 using (var service = new MockClientService(new BaseClientService.Ini
tializer() | 297 var initializer = new BaseClientService.Initializer() |
301 { | 298 { |
302 HttpClientFactory = new MockHttpClientFactory(handler), | 299 HttpClientFactory = new MockHttpClientFactory(handler), |
303 Authenticator = authenticator | 300 Authenticator = authenticator |
304 })) | 301 }; |
| 302 |
| 303 using (var service = new MockClientService(initializer)) |
305 { | 304 { |
306 var response = service.HttpClient.SendAsync( | 305 var response = service.HttpClient.SendAsync( |
307 new HttpRequestMessage(HttpMethod.Get, "https://test")).Resu
lt; | 306 new HttpRequestMessage(HttpMethod.Get, "https://test")).Resu
lt; |
308 // the authenticator handles unsuccessful response handler by "r
efreshing" the token, so the request | 307 // The authenticator handles unsuccessful response handler by "r
efreshing" the token, so the request |
309 // will success | 308 // will success. |
310 Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); | 309 Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); |
311 Assert.That(handler.Calls, Is.EqualTo(2)); | 310 Assert.That(handler.Calls, Is.EqualTo(2)); |
312 Assert.That(authenticator.ApplyCalls, Is.EqualTo(2)); | 311 Assert.That(authenticator.ApplyCalls, Is.EqualTo(2)); |
313 Assert.That(authenticator.HandleCalls, Is.EqualTo(1)); | 312 Assert.That(authenticator.HandleCalls, Is.EqualTo(1)); |
314 } | 313 } |
315 } | 314 } |
316 | 315 |
317 /// <summary> | 316 /// <summary> |
318 /// Tests an authenticator which doesn't implement unsuccessful response
handler, and as a result the request | 317 /// Tests an authenticator which doesn't implement an unsuccessful respo
nse handler. The request should fail |
319 /// fails (when the token is invalid). | 318 /// when the token is invalid. |
320 /// </summary> | 319 /// </summary> |
321 [Test] | 320 [Test] |
322 public void Test_Authentication() | 321 public void Test_Authentication() |
323 { | 322 { |
324 var handler = new MockAuthenticationMessageHandler(); | 323 var handler = new MockAuthenticationMessageHandler(); |
325 var authenticator = new Authenticator(); | 324 var authenticator = new Authenticator(); |
326 using (var service = new MockClientService(new BaseClientService.Ini
tializer() | 325 var initializer = new BaseClientService.Initializer() |
327 { | 326 { |
328 HttpClientFactory = new MockHttpClientFactory(handler), | 327 HttpClientFactory = new MockHttpClientFactory(handler), |
329 Authenticator = authenticator | 328 Authenticator = authenticator |
330 })) | 329 }; |
| 330 |
| 331 using (var service = new MockClientService(initializer)) |
331 { | 332 { |
332 var response = service.HttpClient.SendAsync( | 333 var response = service.HttpClient.SendAsync( |
333 new HttpRequestMessage(HttpMethod.Get, "https://test")).Resu
lt; | 334 new HttpRequestMessage(HttpMethod.Get, "https://test")).Resu
lt; |
334 // the authenticator doesn't implement unsuccessful response han
dler, so the request fails | 335 // The authenticator doesn't implement unsuccessful response han
dler, so the request fails. |
335 Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unaut
horized)); | 336 Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unaut
horized)); |
336 Assert.That(handler.Calls, Is.EqualTo(1)); | 337 Assert.That(handler.Calls, Is.EqualTo(1)); |
337 Assert.That(authenticator.ApplyCalls, Is.EqualTo(1)); | 338 Assert.That(authenticator.ApplyCalls, Is.EqualTo(1)); |
338 } | 339 } |
339 } | 340 } |
340 | 341 |
341 #endregion | 342 #endregion |
342 | 343 |
343 #region Constructor | 344 #region Constructor |
344 | 345 |
| 346 /// <summary> |
| 347 /// Tests the default values of <seealso cref="Google.Apis.Services.Base
ClientService"/> |
| 348 /// </summary> |
345 [Test] | 349 [Test] |
346 public void Constructor_DefaultValues() | 350 public void Constructor_DefaultValues() |
347 { | 351 { |
348 var service = new MockClientService(new BaseClientService.Initialize
r()); | 352 var service = new MockClientService(new BaseClientService.Initialize
r()); |
349 Assert.NotNull(service.HttpClient); | 353 Assert.NotNull(service.HttpClient); |
350 Assert.Null(service.HttpClientInitializer); | 354 Assert.Null(service.HttpClientInitializer); |
351 Assert.That(service.Authenticator, Is.EqualTo(NullAuthenticator.Inst
ance)); | 355 Assert.That(service.Authenticator, Is.EqualTo(NullAuthenticator.Inst
ance)); |
352 Assert.True(service.GZipEnabled); | 356 Assert.True(service.GZipEnabled); |
353 | 357 |
354 // back-off handler for unsuccessful response (503) is added by defa
ult | 358 // Back-off handler for unsuccessful response (503) is added by defa
ult. |
355 Assert.That(service.HttpClient.MessageHandler.UnsuccessfulResponseHa
ndlers.Count, Is.EqualTo(1)); | 359 Assert.That(service.HttpClient.MessageHandler.UnsuccessfulResponseHa
ndlers.Count, Is.EqualTo(1)); |
356 Assert.That(service.HttpClient.MessageHandler.UnsuccessfulResponseHa
ndlers[0], | 360 Assert.That(service.HttpClient.MessageHandler.UnsuccessfulResponseHa
ndlers[0], |
357 Is.InstanceOf<BackOffHandler>()); | 361 Is.InstanceOf<BackOffHandler>()); |
358 | 362 |
359 // one execute interceptor (for adding the "Authenticate" header | 363 // One execute interceptor (for adding the "Authenticate" header, |
360 Assert.That(service.HttpClient.MessageHandler.ExecuteInterceptors.Co
unt, Is.EqualTo(1)); | 364 Assert.That(service.HttpClient.MessageHandler.ExecuteInterceptors.Co
unt, Is.EqualTo(1)); |
361 Assert.That(service.HttpClient.MessageHandler.ExecuteInterceptors[0]
, | 365 Assert.That(service.HttpClient.MessageHandler.ExecuteInterceptors[0]
, |
362 Is.InstanceOf<AuthenticatorInterceptor>()); | 366 Is.InstanceOf<AuthenticatorInterceptor>()); |
363 } | 367 } |
364 | 368 |
365 #endregion | 369 #endregion |
366 } | 370 } |
367 } | 371 } |
LEFT | RIGHT |