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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 /// <summary>Tests that download works in case the server returns a sing
le chunk to the client.</summary> | 123 /// <summary>Tests that download works in case the server returns a sing
le chunk to the client.</summary> |
124 [Test] | 124 [Test] |
125 public void Download_SingleChunk() | 125 public void Download_SingleChunk() |
126 { | 126 { |
127 Subtest_Download_Chunks((int)StreamContent.Length); | 127 Subtest_Download_Chunks((int)StreamContent.Length); |
128 Subtest_Download_Chunks((int)StreamContent.Length 1); | 128 Subtest_Download_Chunks((int)StreamContent.Length 1); |
129 Subtest_Download_Chunks(100); | 129 Subtest_Download_Chunks(100); |
130 } | 130 } |
131 | 131 |
| 132 |
| 133 /// <summary>Tests that download works in case the URI download contains
query parameters.</summary> |
| 134 [Test] |
| 135 public void Download_SingleChunk_UriContainsQueryParameters() |
| 136 { |
| 137 Subtest_Download_Chunks((int)StreamContent.Length, true, 0, "https:/
/www.sample.com?a=1&b=2"); |
| 138 } |
| 139 |
132 /// <summary> | 140 /// <summary> |
133 /// Tests that download asynchronously works in case the server returns
multiple chunks to the client. | 141 /// Tests that download asynchronously works in case the server returns
multiple chunks to the client. |
134 /// </summary> | 142 /// </summary> |
135 [Test] | 143 [Test] |
136 public void DownloadAsync_MultipleChunks() | 144 public void DownloadAsync_MultipleChunks() |
137 { | 145 { |
138 Subtest_Download_Chunks(2, false); | 146 Subtest_Download_Chunks(2, false); |
139 Subtest_Download_Chunks((int)StreamContent.Length - 1, false); | 147 Subtest_Download_Chunks((int)StreamContent.Length - 1, false); |
140 } | 148 } |
141 | 149 |
(...skipping 16 matching lines...) Expand all Loading... |
158 public void DownloadAsync_Cancel() | 166 public void DownloadAsync_Cancel() |
159 { | 167 { |
160 Subtest_Download_Chunks(2, false, 3); | 168 Subtest_Download_Chunks(2, false, 3); |
161 Subtest_Download_Chunks((int)StreamContent.Length - 1, false, 1); | 169 Subtest_Download_Chunks((int)StreamContent.Length - 1, false, 1); |
162 } | 170 } |
163 | 171 |
164 /// <summary>A helper test to test sync and async downloads.</summary> | 172 /// <summary>A helper test to test sync and async downloads.</summary> |
165 /// <param name="chunkSize">The chunk size for each part.</param> | 173 /// <param name="chunkSize">The chunk size for each part.</param> |
166 /// <param name="sync">Indicates if this download should be synchronousl
y or asynchronously.</param> | 174 /// <param name="sync">Indicates if this download should be synchronousl
y or asynchronously.</param> |
167 /// <param name="cancelRequest">Defines the request index to cancel the
download request.</param> | 175 /// <param name="cancelRequest">Defines the request index to cancel the
download request.</param> |
168 private void Subtest_Download_Chunks(int chunkSize, bool sync = true, in
t cancelRequest = 0) | 176 /// <param name="downloadUri"The URI which contains the media to downloa
d.</param> |
| 177 private void Subtest_Download_Chunks(int chunkSize, bool sync = true, in
t cancelRequest = 0, |
| 178 string downloadUri = "http://www.sample.com") |
169 { | 179 { |
170 // reset the steam | 180 // reset the steam |
171 StreamContent.Position = 0; | 181 StreamContent.Position = 0; |
172 | 182 |
173 string downloadUri = "http://www.sample.com"; | |
174 var handler = new MultipleChunksMessageHandler(); | 183 var handler = new MultipleChunksMessageHandler(); |
175 handler.ChunkSize = chunkSize; | 184 handler.ChunkSize = chunkSize; |
176 handler.DownloadUri = new Uri(downloadUri "?alt=media"); | 185 handler.DownloadUri = new Uri(downloadUri |
| 186 (downloadUri.Contains("?") ? "&" : "?") "alt=media"); |
177 | 187 |
178 // support cancellation | 188 // support cancellation |
179 if (cancelRequest > 0) | 189 if (cancelRequest > 0) |
180 { | 190 { |
181 handler.CancelRequestNum = cancelRequest; | 191 handler.CancelRequestNum = cancelRequest; |
182 } | 192 } |
183 handler.CancellationTokenSource = new CancellationTokenSource(); | 193 handler.CancellationTokenSource = new CancellationTokenSource(); |
184 | 194 |
185 int expectedCalls = (int)Math.Ceiling((double)StreamContent.Length /
chunkSize); | 195 int expectedCalls = (int)Math.Ceiling((double)StreamContent.Length /
chunkSize); |
186 using (var service = new MockClientService(new BaseClientService.Ini
tializer() | 196 using (var service = new MockClientService(new BaseClientService.Ini
tializer() |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 251 |
242 byte[] read = new byte[1000]; | 252 byte[] read = new byte[1000]; |
243 outputStream.Position = 0; | 253 outputStream.Position = 0; |
244 int length = outputStream.Read(read, 0, 1000); | 254 int length = outputStream.Read(read, 0, 1000); |
245 Assert.That(Encoding.UTF8.GetString(read, 0, length), Is.Equ
alTo(MediaContent)); | 255 Assert.That(Encoding.UTF8.GetString(read, 0, length), Is.Equ
alTo(MediaContent)); |
246 } | 256 } |
247 } | 257 } |
248 } | 258 } |
249 } | 259 } |
250 } | 260 } |
OLD | NEW |