OLD | NEW |
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 111 } |
112 | 112 |
113 /// <summary> Tests that the message handler handles redirect messages s
uccessfully. </summary> | 113 /// <summary> Tests that the message handler handles redirect messages s
uccessfully. </summary> |
114 [Test] | 114 [Test] |
115 public void SendAsync_Redirect() | 115 public void SendAsync_Redirect() |
116 { | 116 { |
117 var location = "https://google.com"; | 117 var location = "https://google.com"; |
118 var redirectHandler = new RedirectMessageHandler(location); | 118 var redirectHandler = new RedirectMessageHandler(location); |
119 var configurableHanlder = new ConfigurableMessageHandler(redirectHan
dler) | 119 var configurableHanlder = new ConfigurableMessageHandler(redirectHan
dler) |
120 { | 120 { |
121 NumTries = 8 | 121 NumRedirects = 5 |
122 }; | 122 }; |
123 using (var client = new HttpClient(configurableHanlder)) | 123 using (var client = new HttpClient(configurableHanlder)) |
124 { | 124 { |
125 var request = new HttpRequestMessage(HttpMethod.Get, location); | 125 var request = new HttpRequestMessage(HttpMethod.Get, location); |
126 request.Headers.IfModifiedSince = new DateTimeOffset(DateTime.No
w); | 126 request.Headers.IfModifiedSince = new DateTimeOffset(DateTime.No
w); |
127 request.Headers.IfUnmodifiedSince = new DateTimeOffset(DateTime.
Now); | 127 request.Headers.IfUnmodifiedSince = new DateTimeOffset(DateTime.
Now); |
128 request.Headers.IfMatch.Add(new EntityTagHeaderValue("\"a\"")); | 128 request.Headers.IfMatch.Add(new EntityTagHeaderValue("\"a\"")); |
129 request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue("\"b\""
)); | 129 request.Headers.IfNoneMatch.Add(new EntityTagHeaderValue("\"b\""
)); |
130 | 130 |
131 HttpResponseMessage response = client.SendAsync(request).Result; | 131 HttpResponseMessage response = client.SendAsync(request).Result; |
132 | 132 |
133 Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Redir
ect)); | 133 Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Redir
ect)); |
134 Assert.That(response.Headers.Location, Is.EqualTo(new Uri(locati
on + configurableHanlder.NumTries))); | 134 Assert.That(response.Headers.Location, Is.EqualTo( |
135 Assert.That(redirectHandler.Calls, Is.EqualTo(configurableHanlde
r.NumTries)); | 135 new Uri(location + (configurableHanlder.NumRedirects + 1))))
; |
| 136 Assert.That(redirectHandler.Calls, Is.EqualTo(configurableHanlde
r.NumRedirects + 1)); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 /// <summary>· | 140 /// <summary>· |
140 /// Tests that the message handler doesn't handle redirect messages when
follow redirect is <c>false</c>.· | 141 /// Tests that the message handler doesn't handle redirect messages when
follow redirect is <c>false</c>.· |
141 /// </summary> | 142 /// </summary> |
142 [Test] | 143 [Test] |
143 public void SendAsync_Redirect_FollowRedirectFalse() | 144 public void SendAsync_Redirect_FollowRedirectFalse() |
144 { | 145 { |
145 const int tries = 12; | 146 const int tries = 12; |
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 // with application name | 1012 // with application name |
1012 configurableHanlder.ApplicationName = applicationName; | 1013 configurableHanlder.ApplicationName = applicationName; |
1013 request = new HttpRequestMessage(HttpMethod.Get, "https://test-u
ser-agent"); | 1014 request = new HttpRequestMessage(HttpMethod.Get, "https://test-u
ser-agent"); |
1014 response = client.SendAsync(request).Result; | 1015 response = client.SendAsync(request).Result; |
1015 userAgent = string.Join(" ", request.Headers.GetValues("User-Age
nt").ToArray()); | 1016 userAgent = string.Join(" ", request.Headers.GetValues("User-Age
nt").ToArray()); |
1016 Assert.That(userAgent, Is.EqualTo(applicationName + " " + apiVer
sion)); | 1017 Assert.That(userAgent, Is.EqualTo(applicationName + " " + apiVer
sion)); |
1017 } | 1018 } |
1018 } | 1019 } |
1019 } | 1020 } |
1020 } | 1021 } |
OLD | NEW |