Index: GoogleApisClient.sln =================================================================== --- a/GoogleApisClient.sln +++ b/GoogleApisClient.sln @@ -1,14 +1,12 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleApis.Tests", "Src\GoogleApis.Tests\GoogleApis.Tests.csproj", "{9A8AA9EF-6904-43D8-8A26-0AB62069C2DC}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleApis.Authentication.OAuth2", "Src\GoogleApis.Authentication.OAuth2\GoogleApis.Authentication.OAuth2.csproj", "{76106493-68EF-4E44-AF2E-971ABF29B300}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleApis.Authentication.OAuth2.Tests", "Src\GoogleApis.Authentication.OAuth2.Tests\GoogleApis.Authentication.OAuth2.Tests.csproj", "{E0B6A4D3-FDBD-4A1F-B592-4CEDB8001FB5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleApis.Tests.Utility", "Src\GoogleApis.Tests.Utility\GoogleApis.Tests.Utility.csproj", "{F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoogleApis", "Src\GoogleApis\GoogleApis.csproj", "{826CF988-EEE8-4B75-8F53-B7E851A17BAA}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{D962DE0D-98E4-4E01-88BF-CEE63DF67585}" @@ -60,16 +58,6 @@ {E0B6A4D3-FDBD-4A1F-B592-4CEDB8001FB5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {E0B6A4D3-FDBD-4A1F-B592-4CEDB8001FB5}.Release|Mixed Platforms.Build.0 = Release|Any CPU {E0B6A4D3-FDBD-4A1F-B592-4CEDB8001FB5}.Release|Win32.ActiveCfg = Release|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Debug|Win32.ActiveCfg = Debug|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Release|Any CPU.Build.0 = Release|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95}.Release|Win32.ActiveCfg = Release|Any CPU {826CF988-EEE8-4B75-8F53-B7E851A17BAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {826CF988-EEE8-4B75-8F53-B7E851A17BAA}.Debug|Any CPU.Build.0 = Debug|Any CPU {826CF988-EEE8-4B75-8F53-B7E851A17BAA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU Index: Src/GoogleApis.Authentication.OAuth2.Tests/GoogleApis.Authentication.OAuth2.Tests.csproj =================================================================== --- a/Src/GoogleApis.Authentication.OAuth2.Tests/GoogleApis.Authentication.OAuth2.Tests.csproj +++ b/Src/GoogleApis.Authentication.OAuth2.Tests/GoogleApis.Authentication.OAuth2.Tests.csproj @@ -38,6 +38,16 @@ ..\..\ThirdParty\DotNetOpenAuth.dll + + False + ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.dll + + + ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.dll + + + ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll + ..\..\packages\Newtonsoft.Json.5.0.5\lib\net40\Newtonsoft.Json.dll @@ -48,6 +58,27 @@ + + False + ..\..\packages\Microsoft.Net.Http.2.1.10\lib\net40\System.Net.Http.dll + + + ..\..\packages\Microsoft.Net.Http.2.1.10\lib\net40\System.Net.Http.Extensions.dll + + + False + ..\..\packages\Microsoft.Net.Http.2.1.10\lib\net40\System.Net.Http.Primitives.dll + + + False + ..\..\packages\Microsoft.Net.Http.2.1.10\lib\net40\System.Net.Http.WebRequest.dll + + + ..\..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Runtime.dll + + + ..\..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Threading.Tasks.dll + @@ -85,4 +116,5 @@ + \ No newline at end of file Index: Src/GoogleApis.Authentication.OAuth2.Tests/packages.config =================================================================== --- a/Src/GoogleApis.Authentication.OAuth2.Tests/packages.config +++ b/Src/GoogleApis.Authentication.OAuth2.Tests/packages.config @@ -1,5 +1,9 @@  + + + + \ No newline at end of file Index: Src/GoogleApis.Authentication.OAuth2/DotNetOpenAuth/NativeApplicationClient.cs =================================================================== --- a/Src/GoogleApis.Authentication.OAuth2/DotNetOpenAuth/NativeApplicationClient.cs +++ b/Src/GoogleApis.Authentication.OAuth2/DotNetOpenAuth/NativeApplicationClient.cs @@ -42,21 +42,21 @@ public NativeApplicationClient(AuthorizationServerDescription authorizationServer, string clientIdentifier, string clientSecret) - : base(authorizationServer, clientIdentifier, clientSecret) {} - + : base(authorizationServer, clientIdentifier, clientSecret) { } + // /// Initializes a new instance of the class. /// /// The token issuer. public NativeApplicationClient(AuthorizationServerDescription authorizationServer) - : this(authorizationServer, null, null) {} + : this(authorizationServer, null, null) { } /// /// Initializes a new instance of the class. /// /// The authorization endpoint. public NativeApplicationClient(Uri authorizationEndpoint) - : base(new AuthorizationServerDescription { AuthorizationEndpoint = authorizationEndpoint }) {} + : base(new AuthorizationServerDescription { AuthorizationEndpoint = authorizationEndpoint }) { } /// /// Creates the URL which should be used by the user to request the initial authorization. @@ -70,13 +70,13 @@ state.Callback = new Uri(OutOfBandCallbackUrl); return RequestUserAuthorization(state); } - + /// /// Creates the URL which should be used by the user to request the initial authorization. /// Uses the default Out-of-band-URI as a callback. /// /// URI pointing to the authorization server - public new Uri RequestUserAuthorization() + public Uri RequestUserAuthorization() { return RequestUserAuthorization((IEnumerable)null); } @@ -101,7 +101,7 @@ string url = "http://example.com/?code=" + authCode; return ProcessUserAuthorization(new Uri(url), authorizationState); } - + /// /// Uses the provided authorization code to create an authorization state. /// Index: Src/GoogleApis.Authentication.OAuth2/GoogleApis.Authentication.OAuth2.csproj =================================================================== --- a/Src/GoogleApis.Authentication.OAuth2/GoogleApis.Authentication.OAuth2.csproj +++ b/Src/GoogleApis.Authentication.OAuth2/GoogleApis.Authentication.OAuth2.csproj @@ -40,6 +40,18 @@ ..\..\ThirdParty\DotNetOpenAuth.dll + + ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.dll + True + + + ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.dll + True + + + ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll + True + ..\..\packages\Newtonsoft.Json.5.0.5\lib\net40\Newtonsoft.Json.dll @@ -87,7 +99,7 @@ - + - \ No newline at end of file Index: Src/GoogleApis.Tests.Utility/MockParameter.cs =================================================================== deleted file mode 100644 --- a/Src/GoogleApis.Tests.Utility/MockParameter.cs +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2010 Google Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -using System.Collections.Generic; -using Google.Apis.Discovery; - -namespace Google.Apis.Testing -{ - /// A mock class for testing purposes - public class MockParameter : IParameter - { - #region IParameter Members - - public string Name { get; set; } - public string Pattern { get; set; } - public bool IsRequired { get; set; } - public string DefaultValue { get; set; } - public string ParameterType { get; set; } - - #endregion - } -} \ No newline at end of file Index: Src/GoogleApis.Tests.Utility/MoreAsserts.cs =================================================================== deleted file mode 100644 --- a/Src/GoogleApis.Tests.Utility/MoreAsserts.cs +++ /dev/null @@ -1,74 +0,0 @@ -/* -Copyright 2010 Google Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -using System.Collections; -using System.Collections.Generic; - -using NUnit.Framework; - -namespace Google.Apis.Testing -{ - /// Assertion helper methods - public class MoreAsserts - { - /// - /// Asserts whether both enumerables have the equal content, and whether it is in the same order - /// - public static void ContentsEqualAndInOrder(IEnumerable expected, IEnumerable actual) - { - var expectedEnum = expected.GetEnumerator(); - var actualEnum = actual.GetEnumerator(); - int index = 0; - while (expectedEnum.MoveNext()) - { - if (actualEnum.MoveNext() == false) - { - Assert.Fail("Actual has less items then Expected at index " + index); - } - Assert.AreEqual(expectedEnum.Current, actualEnum.Current, "Found different elements at index " + index); - index++; - } - if (actualEnum.MoveNext()) - { - Assert.Fail("Actual has more items then Expected at index " + index); - } - } - - /// Asserts that the list is empty - public static void IsEmpty(IList list) - { - if (list == null) - { - Assert.Fail("List Was null"); - } - if (list.Count > 0) - { - Assert.Fail("List had a count of " + list.Count + " and was expected to be empty."); - } - } - - /// Asserts that the enumerable is empty - public static void IsEmpty(IEnumerable collection) - { - if (collection == null) - { - Assert.Fail("Collection was null"); - } - - Assert.False(collection.GetEnumerator().MoveNext(), "Collection had an element as was expected to be empty"); - } - } -} \ No newline at end of file Index: Src/GoogleApis.Tests.Utility/Properties/AssemblyInfo.cs =================================================================== deleted file mode 100644 --- a/Src/GoogleApis.Tests.Utility/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright 2010 Google Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("GoogleApis.Tests.Utility")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Google Inc")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("Copyright © Google Inc 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("1.4.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] Index: Src/GoogleApis.Tests.Utility/packages.config =================================================================== deleted file mode 100644 --- a/Src/GoogleApis.Tests.Utility/packages.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file Index: Src/GoogleApis.Tests/Apis/Download/MediaDownloaderTest.cs =================================================================== --- a/Src/GoogleApis.Tests/Apis/Download/MediaDownloaderTest.cs +++ b/Src/GoogleApis.Tests/Apis/Download/MediaDownloaderTest.cs @@ -75,9 +75,10 @@ /// The number of bytes this "server" has sent so far. private long bytesRead; - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { + TaskCompletionSource tcs = new TaskCompletionSource(); ThreadId = Thread.CurrentThread.ManagedThreadId; if (Calls == CancelRequestNum && CancellationTokenSource != null) @@ -105,7 +106,9 @@ bytesRead + currentRead - 1, contentLength); bytesRead += currentRead; - return response; + + tcs.SetResult(response); + return tcs.Task; } } Index: Src/GoogleApis.Tests/Apis/Http/ConfigurableMessageHandlerTest.cs =================================================================== --- a/Src/GoogleApis.Tests/Apis/Http/ConfigurableMessageHandlerTest.cs +++ b/Src/GoogleApis.Tests/Apis/Http/ConfigurableMessageHandlerTest.cs @@ -51,10 +51,12 @@ /// Message handler which returns a new successful (and empty) response. private class MockMessageHandler : HttpMessageHandler { - protected override async Task SendAsync(HttpRequestMessage request, + protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { - return new HttpResponseMessage(); + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(new HttpResponseMessage()); + return tcs.Task; } } @@ -180,11 +182,14 @@ const string InjectedHeader = "Some-Header"; const string InjectedValue = "123"; - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { Assert.That(request.Headers.GetValues(InjectedHeader).First(), Is.EqualTo(InjectedValue)); - return InjectedResponseMessage; + + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(InjectedResponseMessage); + return tcs.Task; } /// A mock interceptor which inject a header to a request. @@ -288,7 +293,7 @@ /// public int CancelRequestNum { get; set; } - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { if (Calls == CancelRequestNum) @@ -296,7 +301,9 @@ CancellationTokenSource.Cancel(); } - return new HttpResponseMessage { StatusCode = ResponseStatusCode }; + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(new HttpResponseMessage { StatusCode = ResponseStatusCode }); + return tcs.Task; } /// Unsuccessful response handler which "handles" only service unavailable responses. @@ -416,7 +423,7 @@ /// public const string ExceptionMessage = "Exception from execute"; - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { if (ThrowException) @@ -424,7 +431,9 @@ throw Exception; } - return new HttpResponseMessage(); + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(new HttpResponseMessage()); + return tcs.Task; } /// Mock Exception handler which "handles" the exception. Index: Src/GoogleApis.Tests/Apis/Json/JsonReaderTests.cs =================================================================== rename from Src/GoogleApis.Tests/JSON/JsonReaderTests.cs rename to Src/GoogleApis.Tests/Apis/Json/JsonReaderTests.cs Index: Src/GoogleApis.Tests/Apis/Json/JsonTokenTests.cs =================================================================== rename from Src/GoogleApis.Tests/JSON/JsonTokenTests.cs rename to Src/GoogleApis.Tests/Apis/Json/JsonTokenTests.cs Index: Src/GoogleApis.Tests/Apis/Json/TokenStreamTest.cs =================================================================== rename from Src/GoogleApis.Tests/JSON/TokenStreamTest.cs rename to Src/GoogleApis.Tests/Apis/Json/TokenStreamTest.cs 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", Index: Src/GoogleApis.Tests/Apis/Requests/ParameterValidatorTest.cs =================================================================== --- a/Src/GoogleApis.Tests/Apis/Requests/ParameterValidatorTest.cs +++ b/Src/GoogleApis.Tests/Apis/Requests/ParameterValidatorTest.cs @@ -32,7 +32,7 @@ [Test] public void ValidateRegexEmptyNeedsDataTest() { - var parameter = new MockParameter() { Pattern = ".+", Name = "test" }; + var parameter = new Parameter() { Pattern = ".+", Name = "test" }; Assert.IsFalse(ParameterValidator.ValidateRegex(parameter, "")); } @@ -40,7 +40,7 @@ [Test] public void ValidateRegexTest() { - var parameter = new MockParameter() { Pattern = ".+", Name = "test" }; + var parameter = new Parameter() { Pattern = ".+", Name = "test" }; Assert.IsTrue(ParameterValidator.ValidateRegex(parameter, "Test")); } } Index: Src/GoogleApis.Tests/Apis/Services/BaseClientServiceTest.cs =================================================================== --- a/Src/GoogleApis.Tests/Apis/Services/BaseClientServiceTest.cs +++ b/Src/GoogleApis.Tests/Apis/Services/BaseClientServiceTest.cs @@ -224,22 +224,30 @@ internal static string FirstToken = "invalid"; internal static string SecondToken = "valid"; - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { + TaskCompletionSource tcs = new TaskCompletionSource(); switch (Calls) { case 1: Assert.That(request.Headers.GetValues("Authorization").Count(), Is.EqualTo(1)); Assert.That(request.Headers.GetValues("Authorization").First(), Is.EqualTo(FirstToken)); - return new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.Unauthorized }; + tcs.SetResult(new HttpResponseMessage + { + StatusCode = System.Net.HttpStatusCode.Unauthorized + }); + break; case 2: Assert.That(request.Headers.GetValues("Authorization").Count(), Is.EqualTo(1)); Assert.That(request.Headers.GetValues("Authorization").First(), Is.EqualTo(SecondToken)); - return new HttpResponseMessage(); + tcs.SetResult(new HttpResponseMessage()); + break; default: throw new Exception("There should be only two calls"); } + + return tcs.Task; } } Index: Src/GoogleApis.Tests/Apis/Testing/MoreAssertsTests.cs =================================================================== deleted file mode 100644 --- a/Src/GoogleApis.Tests/Apis/Testing/MoreAssertsTests.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2010 Google Inc - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -using System.Collections.Generic; -using System.Linq; -using NUnit.Framework; -using Google.Apis.Testing; - -namespace Google.Apis.Tests.Apis.Testing -{ - /// - /// Tests the "MoreAsserts"-class - /// - [TestFixture] - public class MoreAssertsTests - { - /// - /// Tests that the Assert helper method works correctly (lets assert the asserts!) - /// - [Test] - public void TestCase() - { - var actual = new List { "a", "b", "c", "d" }; - MoreAsserts.ContentsEqualAndInOrder(actual.Select(x => x.ToString()), actual); - Assert.Throws( - () => MoreAsserts.ContentsEqualAndInOrder(actual.Select(x => x).Reverse(), actual)); - Assert.Throws( - () => MoreAsserts.ContentsEqualAndInOrder(new List { "a", "b", "c" }, actual)); - Assert.Throws( - () => MoreAsserts.ContentsEqualAndInOrder(new List { "b", "c", "d" }, actual)); - Assert.Throws( - () => MoreAsserts.ContentsEqualAndInOrder(new List { "a", "b", "c", "d", "e" }, actual)); - Assert.Throws( - () => MoreAsserts.ContentsEqualAndInOrder(new List { "a", "b", "c", "e" }, actual)); - Assert.Throws( - () => MoreAsserts.ContentsEqualAndInOrder(new List { "b", "b", "c", "d" }, actual)); - } - } -} \ No newline at end of file Index: Src/GoogleApis.Tests/Apis/Upload/ResumableUploadTest.cs =================================================================== --- a/Src/GoogleApis.Tests/Apis/Upload/ResumableUploadTest.cs +++ b/Src/GoogleApis.Tests/Apis/Upload/ResumableUploadTest.cs @@ -75,7 +75,7 @@ /// A handler which handles uploading an empty file. private class EmptyFileMessageHandler : BaseMockMessageHandler { - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { var response = new HttpResponseMessage(); @@ -99,7 +99,9 @@ break; } - return response; + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(response); + return tcs.Task; } } @@ -172,7 +174,7 @@ /// Gets or sets the path parameters which should be part of the initialize request. public string PathParameters { get; set; } - protected override async Task SendAsyncCore(HttpRequestMessage request, + protected override Task SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) { var response = new HttpResponseMessage(); @@ -206,7 +208,9 @@ break; } - return response; + TaskCompletionSource tcs = new TaskCompletionSource(); + tcs.SetResult(response); + return tcs.Task; } } @@ -1039,7 +1043,7 @@ upload.ChunkSize = -1; Assert.Fail(); } - catch (ArgumentOutOfRangeException ex) + catch (ArgumentOutOfRangeException) { // expected } @@ -1050,7 +1054,7 @@ upload.ChunkSize = MockResumableUpload.MinimumChunkSize - 1; Assert.Fail(); } - catch (ArgumentOutOfRangeException ex) + catch (ArgumentOutOfRangeException) { // expected } Index: Src/GoogleApis.Tests/GoogleApis.Tests.csproj =================================================================== --- a/Src/GoogleApis.Tests/GoogleApis.Tests.csproj +++ b/Src/GoogleApis.Tests/GoogleApis.Tests.csproj @@ -118,6 +118,9 @@ + + + @@ -130,22 +133,18 @@ - - - - + + + + {c4da0abe-2c2e-4bb8-9881-5ff80b0c1afd} GoogleApis.FullProfile - - {F3A416DF-6268-47AD-9D6B-08EA2C8FFF95} - GoogleApis.Tests.Utility - {826cf988-eee8-4b75-8f53-b7e851a17baa} GoogleApis @@ -183,5 +182,5 @@ - + \ No newline at end of file Index: Src/GoogleApis.Tests/[Mock]/CountableMessageHandler.cs =================================================================== rename from Src/GoogleApis.Tests.Utility/CountableMessageHandler.cs rename to Src/GoogleApis.Tests/[Mock]/CountableMessageHandler.cs Index: Src/GoogleApis.Tests/[Mock]/MockBackOffHandler.cs =================================================================== rename from Src/GoogleApis.Tests.Utility/MockBackOffHandler.cs rename to Src/GoogleApis.Tests/[Mock]/MockBackOffHandler.cs Index: Src/GoogleApis.Tests/[Mock]/MockClientService.cs =================================================================== rename from Src/GoogleApis.Tests.Utility/MockClientService.cs rename to Src/GoogleApis.Tests/[Mock]/MockClientService.cs Index: Src/GoogleApis.Tests/[Mock]/MockHttpClientFactory.cs =================================================================== rename from Src/GoogleApis.Tests.Utility/MockHttpClientFactory.cs rename to Src/GoogleApis.Tests/[Mock]/MockHttpClientFactory.cs Index: Src/GoogleApis.Tests/packages.config =================================================================== --- a/Src/GoogleApis.Tests/packages.config +++ b/Src/GoogleApis.Tests/packages.config @@ -3,7 +3,7 @@ - + Index: Src/GoogleApis/Apis/Requests/ClientServiceRequest.cs =================================================================== --- a/Src/GoogleApis/Apis/Requests/ClientServiceRequest.cs +++ b/Src/GoogleApis/Apis/Requests/ClientServiceRequest.cs @@ -90,10 +90,14 @@ return ParseResponse(response).Result; } } - catch (AggregateException ex) + catch (AggregateException aex) { // if an exception was thrown during the tasks, unwrap and throw it - throw ex.InnerException; + throw aex.InnerException; + } + catch (Exception ex) + { + throw ex; } } @@ -106,10 +110,14 @@ var response = ExecuteUnparsed(CancellationToken.None).Result; return response.Content.ReadAsStreamAsync().Result; } - catch (AggregateException ex) + catch (AggregateException aex) { // if an exception was thrown during the tasks, unwrap and throw it - throw ex.InnerException; + throw aex.InnerException; + } + catch (Exception ex) + { + throw ex; } } @@ -155,6 +163,9 @@ /// Async executes the request without parsing the result. private Task ExecuteAsyncUnparsed(CancellationToken cancellationToken) { + // TODO(peleyal): remove the creation of a new Task (it's not necessary). + // It should also be removed from ResumableMediaUpload and MediaDownloader! + // create a new task completion source and return its task. In additional task we actually send the request // using ExecuteUnparsed and setting the result or the exception on the completion source TaskCompletionSource tcs = new TaskCompletionSource(); Index: Src/GoogleApis/GoogleApis.csproj =================================================================== --- a/Src/GoogleApis/GoogleApis.csproj +++ b/Src/GoogleApis/GoogleApis.csproj @@ -132,7 +132,7 @@ - + - - - - - false - - - $(ProjectConfigFileName) - - - - - - <_FullFrameworkReferenceAssemblyPaths>$(TargetFrameworkDirectory) - - - - - - <__IntermediateAppConfig>$(IntermediateOutputPath)$(MSBuildProjectFile).App.config - - - - - - - - - <_EnsureBindingRedirectReference Include="@(Reference)" - Condition="'%(Reference.HintPath)' != '' and Exists('$([System.IO.Path]::GetDirectoryName("%(Reference.HintPath)"))\\ensureRedirect.xml')" /> - - - - - - - - - - - - - - - $(__IntermediateAppConfig) - - - - - $(TargetFileName).config - - - - - - - - - - - <_BclBuildProjectReferenceProperties>BclBuildReferencingProject=$(MSBuildProjectFullPath);BclBuildReferencingProjectConfig=$(MSBuildProjectDirectory)\packages.config - <_BclBuildProjectReferenceProperties Condition="'$(SkipValidatePackageReferences)' != ''">$(_BclBuildProjectReferenceProperties);SkipValidatePackageReferences=$(SkipValidatePackageReferences) - - - - - $(_BclBuildProjectReferenceProperties);%(ProjectReference.AdditionalProperties) - - - - - - - - true - - - - - - - - - - false - - - - - - - - - - - - - - - - \ No newline at end of file Index: packages/Microsoft.Bcl.Build.1.0.8/tools/Microsoft.Bcl.Build.targets =================================================================== new file mode 100644 --- /dev/null +++ b/packages/Microsoft.Bcl.Build.1.0.8/tools/Microsoft.Bcl.Build.targets @@ -0,0 +1,227 @@ + + + + + + false + + + $(ProjectConfigFileName) + + + + + + <_FullFrameworkReferenceAssemblyPaths>$(TargetFrameworkDirectory) + + + + + + <__IntermediateAppConfig>$(IntermediateOutputPath)$(MSBuildProjectFile).App.config + + + + + + + + + <_EnsureBindingRedirectReference Include="@(Reference)" + Condition="'%(Reference.HintPath)' != '' and Exists('$([System.IO.Path]::GetDirectoryName("%(Reference.HintPath)"))\\ensureRedirect.xml')" /> + + + + + + + + + + + + + + + $(__IntermediateAppConfig) + + + + + $(TargetFileName).config + + + + + + + + + + + <_BclBuildProjectReferenceProperties>BclBuildReferencingProject=$(MSBuildProjectFullPath);BclBuildReferencingProjectConfig=$(MSBuildProjectDirectory)\packages.config + <_BclBuildProjectReferenceProperties Condition="'$(SkipValidatePackageReferences)' != ''">$(_BclBuildProjectReferenceProperties);SkipValidatePackageReferences=$(SkipValidatePackageReferences) + + + + + $(_BclBuildProjectReferenceProperties);%(ProjectReference.AdditionalProperties) + + + + + + + + true + + + + + + + + + + false + + + + + + + + + + + + + + + + \ No newline at end of file