Index: Src/GoogleApis.Tests/Apis/Download/MediaDownloaderTest.cs
===================================================================
--- a/Src/GoogleApis.Tests/Apis/Download/MediaDownloaderTest.cs
+++ b/Src/GoogleApis.Tests/Apis/Download/MediaDownloaderTest.cs
@@ -69,9 +69,6 @@
/// Gets or sets the download Uri.
public Uri DownloadUri { get; set; }
- /// Gets the thread Id.
- public int ThreadId { get; private set; }
-
/// The number of bytes this "server" has sent so far.
private long bytesRead;
@@ -79,7 +76,6 @@
CancellationToken cancellationToken)
{
TaskCompletionSource tcs = new TaskCompletionSource();
- ThreadId = Thread.CurrentThread.ManagedThreadId;
if (Calls == CancelRequestNum && CancellationTokenSource != null)
{
@@ -200,23 +196,19 @@
if (sync)
{
downloader.Download(downloadUri, outputStream);
- Assert.AreEqual(handler.ThreadId, Thread.CurrentThread.ManagedThreadId);
}
else
{
- var task = downloader.DownloadAsync(downloadUri, outputStream,
- handler.CancellationTokenSource.Token);
try
{
- task.Wait();
- Assert.AreEqual(cancelRequest, 0);
+ var result = downloader.DownloadAsync(downloadUri, outputStream,
+ handler.CancellationTokenSource.Token).Result;
+ Assert.AreEqual(0, handler.CancelRequestNum);
}
catch (AggregateException ex)
{
- Assert.That(ex.InnerException, Is.InstanceOf());
- Assert.AreNotEqual(cancelRequest, 0);
+ Assert.IsInstanceOf(ex.InnerException);
}
- Assert.AreNotEqual(handler.ThreadId, Thread.CurrentThread.ManagedThreadId);
}
var lastProgress = progressList.LastOrDefault();
@@ -224,7 +216,7 @@
{
// the download was interrupted in the middle
Assert.That(handler.Calls, Is.EqualTo(cancelRequest));
- // last request should be failed
+ // last request should fail
Assert.NotNull(lastProgress);
Assert.NotNull(lastProgress.Exception);
Assert.That(lastProgress.Status, Is.EqualTo(DownloadStatus.Failed));
Index: Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs
===================================================================
--- a/Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs
+++ b/Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs
@@ -191,15 +191,11 @@
/// Gets or sets the Serializer which is used to serialize and deserialize messages.
public ISerializer Serializer { get; set; }
- /// Gets the thread id in which this handler was invoked.
- public int ThreadId { get; private set; }
-
public string ResponseETag = "\"some-etag-here\"";
protected override async Task SendAsyncCore(HttpRequestMessage request,
CancellationToken cancellationToken)
{
- ThreadId = Thread.CurrentThread.ManagedThreadId;
var mediaType = "application/json";
string strObject = null;
@@ -467,12 +463,10 @@
{
var task = request.ExecuteAsync();
response = task.Result;
- Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, handler.ThreadId);
}
else
{
response = request.Execute();
- Assert.AreEqual(Thread.CurrentThread.ManagedThreadId, handler.ThreadId);
}
// Note: Even if GZipEnabled is true, we don't need to extract the real string from the GZip stream,
@@ -786,12 +780,10 @@
{
stream = t.Result;
}, TaskContinuationOptions.OnlyOnRanToCompletion).Wait();
- Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, handler.ThreadId);
}
else
{
stream = request.ExecuteAsStream();
- Assert.AreEqual(Thread.CurrentThread.ManagedThreadId, handler.ThreadId);
}
// Read the object.
Index: Src/GoogleApis.Tests/Apis/Upload/ResumableUploadTest.cs
===================================================================
--- a/Src/GoogleApis.Tests/Apis/Upload/ResumableUploadTest.cs
+++ b/Src/GoogleApis.Tests/Apis/Upload/ResumableUploadTest.cs
@@ -26,7 +26,6 @@
using NUnit.Framework;
-using Google.Apis.Http;
using Google.Apis.Json;
using Google.Apis.Services;
using Google.Apis.Testing;
@@ -38,7 +37,7 @@
[TestFixture]
class ResumableUploadTest
{
- ///
+ ///
/// Mock string to upload to the media server. It contains 453 bytes, and in most cases we will use a chunk
/// size of 100.
///
@@ -51,7 +50,7 @@
[TestFixtureSetUp]
public void SetUp()
{
- // change the false parameter to true if you want to enable logging during tests
+ // Change the false parameter to true if you want to enable logging during tests
SetUp(false);
}
@@ -65,14 +64,14 @@
#region Handlers
- /// Base mock handler which contains the upload Uri.
+ /// Base mock handler which contains the upload Uri.
private abstract class BaseMockMessageHandler : CountableMessageHandler
{
- /// The upload Uri for uploading the media.
+ /// The upload Uri for uploading the media.
protected static Uri uploadUri = new Uri("http://upload.com");
}
- /// A handler which handles uploading an empty file.
+ /// A handler which handles uploading an empty file.
private class EmptyFileMessageHandler : BaseMockMessageHandler
{
protected override Task SendAsyncCore(HttpRequestMessage request,
@@ -82,7 +81,7 @@
switch (Calls)
{
case 1:
- // First call is initialization
+ // First call is initialization.
Assert.That(request.RequestUri.Query, Is.EqualTo("?uploadType=resumable"));
Assert.That(request.Headers.GetValues("X-Upload-Content-Type").First(),
Is.EqualTo("text/plain"));
@@ -91,7 +90,7 @@
response.Headers.Location = uploadUri;
break;
case 2:
- // Receiving an empty stream
+ // Receiving an empty stream.
Assert.That(request.RequestUri, Is.EqualTo(uploadUri));
var range = String.Format("bytes */0");
Assert.That(request.Content.Headers.GetValues("Content-Range").First(), Is.EqualTo(range));
@@ -105,10 +104,10 @@
}
}
- /// A handler which handles a request object on the initialization request.
+ /// A handler which handles a request object on the initialization request.
private class RequestResponseMessageHandler : BaseMockMessageHandler
{
- ///
+ ///
/// Gets or sets the expected request object. Server checks that the initialization request contains that
/// object in the request.
///
@@ -119,7 +118,7 @@
///
public object ExpectedResponse { get; set; }
- /// Gets or sets the Serializer which is used to serialize and deserialize objects.
+ /// Gets or sets the Serializer which is used to serialize and deserialize objects.
public ISerializer Serializer { get; set; }
protected override async Task SendAsyncCore(HttpRequestMessage request,
@@ -130,7 +129,7 @@
{
case 1:
{
- // initialization and receiving the request object
+ // Initialization and receiving the request object.
Assert.That(request.RequestUri.Query, Is.EqualTo("?uploadType=resumable"));
Assert.That(request.Headers.GetValues("X-Upload-Content-Type").First(),
Is.EqualTo("text/plain"));
@@ -145,13 +144,13 @@
}
case 2:
{
- // check that the server received the media
+ // Check that the server received the media.
Assert.That(request.RequestUri, Is.EqualTo(uploadUri));
var range = String.Format("bytes 0-{0}/{1}", UploadTestData.Length - 1,
UploadTestData.Length);
Assert.That(request.Content.Headers.GetValues("Content-Range").First(), Is.EqualTo(range));
- // Send the response-body
+ // Send the response-body.
var responseObject = Serializer.Serialize(ExpectedResponse);
response.Content = new StringContent(responseObject, Encoding.UTF8, "application/json");
break;
@@ -162,16 +161,16 @@
}
}
- /// A handler which handles a request for single chunk.
+ /// A handler which handles a request for single chunk.
private class SingleChunkMessageHandler : BaseMockMessageHandler
{
- /// Gets or sets the expected stream length.
+ /// Gets or sets the expected stream length.
public long StreamLength { get; set; }
- /// Gets or sets the query parameters which should be part of the initialize request.
+ /// Gets or sets the query parameters which should be part of the initialize request.
public string QueryParameters { get; set; }
- /// Gets or sets the path parameters which should be part of the initialize request.
+ /// Gets or sets the path parameters which should be part of the initialize request.
public string PathParameters { get; set; }
protected override Task SendAsyncCore(HttpRequestMessage request,
@@ -214,13 +213,13 @@
}
}
- ///
+ ///
/// A handler which demonstrate a server which reads partial data (e.g. on the first upload request the client
/// sends X bytes, but the server actually read only Y of them)
///
private class ReadPartialMessageHandler : BaseMockMessageHandler
{
- /// Received stream which contains the data that the server reads.
+ /// Received stream which contains the data that the server reads.
public MemoryStream ReceivedData = new MemoryStream();
private bool knownSize;
@@ -249,7 +248,7 @@
switch (Calls)
{
case 1:
- // initialization request
+ // Initialization request.
Assert.That(request.RequestUri.Query, Is.EqualTo("?uploadType=resumable"));
Assert.That(request.Headers.GetValues("X-Upload-Content-Type").First(),
Is.EqualTo("text/plain"));
@@ -265,8 +264,8 @@
response.Headers.Location = uploadUri;
break;
case 2:
- // first client upload request. server reads only readInFirstRequest bytes and returns
- // a response with Range header - "bytes 0-readInFirstRequest"
+ // First client upload request. server reads only readInFirstRequest bytes and returns
+ // a response with Range header - "bytes 0-readInFirstRequest".
Assert.That(request.RequestUri, Is.EqualTo(uploadUri));
var range = String.Format("bytes {0}-{1}/{2}", 0, chunkSize - 1,
knownSize ? len.ToString() : "*");
@@ -279,7 +278,7 @@
ReceivedData.Write(bytes, 0, readInFirstRequest);
break;
case 3:
- // server reads the rest of bytes
+ // Server reads the rest of bytes.
Assert.That(request.RequestUri, Is.EqualTo(uploadUri));
Assert.That(request.Content.Headers.GetValues("Content-Range").First(), Is.EqualTo(
string.Format("bytes {0}-{1}/{2}", readInFirstRequest, len - 1, len)));
@@ -301,22 +300,22 @@
NotFound
}
- /// A handler which demonstrate a client upload which contains multiple chunks.
+ /// A handler which demonstrate a client upload which contains multiple chunks.
private class MultipleChunksMessageHandler : BaseMockMessageHandler
{
public MemoryStream ReceivedData = new MemoryStream();
- /// The cancellation token we are going to use to cancel a request.
+ /// The cancellation token we are going to use to cancel a request.
public CancellationTokenSource CancellationTokenSource { get; set; }
- /// The request index we are going to cancel.
+ /// The request index we are going to cancel.
public int CancelRequestNum { get; set; }
// on the 4th request - server returns error (if supportedError isn't none)
// on the 5th request - server returns 308 with "Range" header is "bytes 0-299" (depends on supportedError)
internal const int ErrorOnCall = 4;
- ///
+ ///
/// Gets or sets the number of bytes the server reads when error occurred. The default value is 0,
/// meaning that on server error it won't read any bytes from the stream.
///
@@ -355,7 +354,7 @@
var response = new HttpResponseMessage();
if (Calls == 1)
{
- // initialization request
+ // Initialization request.
Assert.That(request.RequestUri.Query, Is.EqualTo("?uploadType=resumable"));
Assert.That(request.Headers.GetValues("X-Upload-Content-Type").First(), Is.EqualTo("text/plain"));
if (knownSize)
@@ -490,7 +489,7 @@
}
}
- /// A resumable upload class which contains query and path parameters.
+ /// A resumable upload class which contains query and path parameters.
private class MockResumableWithParameters : ResumableUpload