Index: Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs =================================================================== --- a/Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs +++ b/Src/GoogleApis.Tests/Apis/Requests/ClientServiceRequestTest.cs @@ -74,6 +74,11 @@ var other = obj as MockResponse; return (other != null && other.ETag == ETag && other.Name == Name && other.Id == Id); } + + public override int GetHashCode() + { + return (ETag ?? string.Empty).GetHashCode() ^ (Name ?? string.Empty).GetHashCode() + Id; + } } /// A mock request class. @@ -90,6 +95,11 @@ var other = obj as MockRequest; return (other != null && other.ETag == ETag && other.Name == Name); } + + public override int GetHashCode() + { + return (ETag ?? string.Empty).GetHashCode() ^ (Name ?? string.Empty).GetHashCode(); + } } /// A mock service request which returns . @@ -135,10 +145,9 @@ public string ExpectedError = @"Message[Login Required] Location[Authorization - header] Reason[required] Domain[global]"; - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { - var response = new HttpResponseMessage(); var error = @"{ ""error"": { ""errors"": [ @@ -154,9 +163,16 @@ ""message"": ""Login Required"" } }"; - response.Content = new StringContent(error); - response.StatusCode = System.Net.HttpStatusCode.Unauthorized; - return response; + + var response = new HttpResponseMessage + { + Content = new StringContent(error), + StatusCode = System.Net.HttpStatusCode.Unauthorized + }; + + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(response); + return tcs.Task; } } @@ -244,14 +260,17 @@ ThrowException = throwException; } - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { if (ThrowException) { throw new InvalidOperationMockException("INVALID"); } - return new HttpResponseMessage(); + + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(new HttpResponseMessage()); + return tcs.Task; } } @@ -264,7 +283,7 @@ /// The request index we are going to cancel. public int CancelRequestNum { get; set; } - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { if (Calls == CancelRequestNum) @@ -277,7 +296,10 @@ RequestMessage = request }; response.Headers.Location = new Uri("http://www.test.com"); - return response; + + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(response); + return tcs.Task; } } @@ -290,7 +312,7 @@ /// Gets or sets the Serializer which is used to serialize and deserialize messages. public ISerializer Serializer { get; set; } - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { var response = new HttpResponseMessage(); @@ -307,7 +329,10 @@ var serializedObject = Serializer.Serialize(mockObject); response.Content = new StringContent(serializedObject, Encoding.UTF8, "application/json"); } - return response; + + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(response); + return tcs.Task; } /// Unsuccessful response handler which "handles" service unavailable responses. @@ -814,41 +839,41 @@ public ClientServiceRequestWithQueryParameters(IClientService service, string method, object body) : base(service, method, body) { - RequestParameters.Add("required", new MockParameter + RequestParameters.Add("required", new Parameter { Name = "required", IsRequired = true, ParameterType = "query" }); - RequestParameters.Add("optionalWithValue", new MockParameter + RequestParameters.Add("optionalWithValue", new Parameter { Name = "optionalWithValue", IsRequired = false, ParameterType = "query", DefaultValue = "DoesNotDisplay" }); - RequestParameters.Add("optionalWithValue2", new MockParameter + RequestParameters.Add("optionalWithValue2", new Parameter { Name = "optionalWithValue", IsRequired = false, ParameterType = "query", DefaultValue = "DoesNotDisplay" }); - RequestParameters.Add("optionalWithNull", new MockParameter + RequestParameters.Add("optionalWithNull", new Parameter { Name = "optionalWithNull", IsRequired = false, ParameterType = "query", DefaultValue = "c" }); - RequestParameters.Add("optionalEmpty", new MockParameter + RequestParameters.Add("optionalEmpty", new Parameter { Name = "optionalEmpty", IsRequired = false, ParameterType = "query", DefaultValue = "d" }); - RequestParameters.Add("optionalNotPressent", new MockParameter + RequestParameters.Add("optionalNotPressent", new Parameter { Name = "optionalNotPressent", IsRequired = false, @@ -915,12 +940,12 @@ public ClientServiceRequestWithPathParameters(IClientService service, string method, object body) : base(service, method, body) { - RequestParameters.Add("path1", new MockParameter + RequestParameters.Add("path1", new Parameter { Name = "path1", ParameterType = "path" }); - RequestParameters.Add("path2", new MockParameter + RequestParameters.Add("path2", new Parameter { Name = "path2", ParameterType = "path",