From 0586fd136f0a4238b8b0e545d147ff8a60e3d897 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Thu, 23 Mar 2017 00:28:49 -0700 Subject: [PATCH] Converted samples and test projects to run on netcoreapp2.0 --- build/dependencies.props | 1 + samples/HotAddSample/HotAddSample.csproj | 2 +- samples/SelfHostServer/SelfHostServer.csproj | 2 +- .../HttpsTests.cs | 8 ++++++-- .../Listener/HttpsTests.cs | 8 ++++++-- .../Listener/RequestBodyTests.cs | 3 +++ .../Listener/ResponseBodyTests.cs | 15 +++++++++++++-- .../Listener/ResponseHeaderTests.cs | 12 ++++++++---- .../Listener/ResponseSendFileTests.cs | 6 ++++++ .../Listener/ServerTests.cs | 5 ++++- .../Listener/SkipOffDomainAttribute.cs | 3 +++ .../Listener/Utilities.cs | 4 +++- ...pNetCore.Server.HttpSys.FunctionalTests.csproj | 6 +++--- .../RequestBodyTests.cs | 5 ++++- .../ResponseBodyTests.cs | 7 ++++++- .../ResponseHeaderTests.cs | 12 ++++++++---- ...crosoft.AspNetCore.Server.HttpSys.Tests.csproj | 4 ++-- 17 files changed, 78 insertions(+), 25 deletions(-) diff --git a/build/dependencies.props b/build/dependencies.props index 5a4c06ce33..12a50aa67f 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -3,6 +3,7 @@ 1.2.0-* 4.3.0 1.6.1 + 2.0.0-* 15.0.0 2.2.0 diff --git a/samples/HotAddSample/HotAddSample.csproj b/samples/HotAddSample/HotAddSample.csproj index 07c9191526..10f656a63b 100644 --- a/samples/HotAddSample/HotAddSample.csproj +++ b/samples/HotAddSample/HotAddSample.csproj @@ -3,7 +3,7 @@ - net451;netcoreapp1.1 + net451;netcoreapp2.0 Exe true diff --git a/samples/SelfHostServer/SelfHostServer.csproj b/samples/SelfHostServer/SelfHostServer.csproj index 07c9191526..10f656a63b 100644 --- a/samples/SelfHostServer/SelfHostServer.csproj +++ b/samples/SelfHostServer/SelfHostServer.csproj @@ -3,7 +3,7 @@ - net451;netcoreapp1.1 + net451;netcoreapp2.0 Exe true diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/HttpsTests.cs index 0a240f86fb..b0bcb6e612 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/HttpsTests.cs @@ -104,8 +104,10 @@ namespace Microsoft.AspNetCore.Server.HttpSys { #if NET452 var handler = new WebRequestHandler(); -#else +#elif NETCOREAPP2_0 var handler = new WinHttpHandler(); +#else +#error Target framework needs to be updated #endif handler.ServerCertificateValidationCallback = (a, b, c, d) => true; if (cert != null) @@ -122,8 +124,10 @@ namespace Microsoft.AspNetCore.Server.HttpSys { #if NET452 var handler = new WebRequestHandler(); -#else +#elif NETCOREAPP2_0 var handler = new WinHttpHandler(); +#else +#error Target framework needs to be updated #endif handler.ServerCertificateValidationCallback = (a, b, c, d) => true; using (HttpClient client = new HttpClient(handler)) diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/HttpsTests.cs index d2c536ff41..b7a05b5e1f 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/HttpsTests.cs @@ -111,8 +111,10 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener { #if NET452 WebRequestHandler handler = new WebRequestHandler(); -#else +#elif NETCOREAPP2_0 WinHttpHandler handler = new WinHttpHandler(); +#else +#error Target framework needs to be updated #endif handler.ServerCertificateValidationCallback = (a, b, c, d) => true; if (cert != null) @@ -129,8 +131,10 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener { #if NET452 WebRequestHandler handler = new WebRequestHandler(); -#else +#elif NETCOREAPP2_0 WinHttpHandler handler = new WinHttpHandler(); +#else +#error Target framework needs to be updated #endif handler.ServerCertificateValidationCallback = (a, b, c, d) => true; using (HttpClient client = new HttpClient(handler)) diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/RequestBodyTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/RequestBodyTests.cs index e4ff4abaed..1c4da2210f 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/RequestBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/RequestBodyTests.cs @@ -72,6 +72,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener Assert.Equal("Hello World", response); } } +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif [ConditionalFact] diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseBodyTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseBodyTests.cs index 52f5994b74..d129e7fbfc 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseBodyTests.cs @@ -100,8 +100,10 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener var stream = context.Response.Body; #if NET452 stream.EndWrite(stream.BeginWrite(new byte[10], 0, 10, null, null)); -#else +#elif NETCOREAPP2_0 await stream.WriteAsync(new byte[10], 0, 10); +#else +#error Target framework needs to be updated #endif stream.Write(new byte[10], 0, 10); await stream.WriteAsync(new byte[10], 0, 10); @@ -129,11 +131,14 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener var context = await server.AcceptAsync(Utilities.DefaultTimeout); context.Response.Headers["Content-lenGth"] = " 20 "; context.Dispose(); -#if !NETCOREAPP1_1 +#if NET452 // HttpClient retries the request because it didn't get a response. context = await server.AcceptAsync(Utilities.DefaultTimeout); context.Response.Headers["Content-lenGth"] = " 20 "; context.Dispose(); +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif await Assert.ThrowsAsync(() => responseTask); } @@ -291,6 +296,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener writeTask = context.Response.Body.WriteAsync(new byte[10], 0, 10, cts.Token); Assert.True(writeTask.IsCanceled); context.Dispose(); +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif await Assert.ThrowsAsync(() => responseTask); } @@ -320,6 +328,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener writeTask = context.Response.Body.WriteAsync(new byte[10], 0, 10, cts.Token); Assert.True(writeTask.IsCanceled); context.Dispose(); +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif await Assert.ThrowsAsync(() => responseTask); } diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseHeaderTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseHeaderTests.cs index 83e9b126ef..4b0c5b8f48 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseHeaderTests.cs @@ -221,10 +221,12 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener Assert.Equal(0, response.ContentLength); Assert.NotNull(response.Headers["Date"]); Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]); -#if NETCOREAPP1_1 // WebHeaderCollection.GetValues() not available in CoreCLR. +#if NETCOREAPP2_0 // WebHeaderCollection.GetValues() not available in CoreCLR. Assert.Equal("custom1, and custom2, custom3", response.Headers["WWW-Authenticate"]); -#else +#elif NET452 Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("WWW-Authenticate")); +#else +#error Target framework needs to be updated #endif } } @@ -250,10 +252,12 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener Assert.Equal(0, response.ContentLength); Assert.NotNull(response.Headers["Date"]); Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]); -#if NETCOREAPP1_1 // WebHeaderCollection.GetValues() not available in CoreCLR. +#if NETCOREAPP2_0 // WebHeaderCollection.GetValues() not available in CoreCLR. Assert.Equal("custom1, and custom2, custom3", response.Headers["Custom-Header1"]); -#else +#elif NET452 Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("Custom-Header1")); +#else +#error Target framework needs to be updated #endif } } diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseSendFileTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseSendFileTests.cs index 7a2e861b13..2172157489 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseSendFileTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ResponseSendFileTests.cs @@ -371,6 +371,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener writeTask = context.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); Assert.True(writeTask.IsCanceled); context.Dispose(); +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif await Assert.ThrowsAsync(() => responseTask); } @@ -400,6 +403,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener writeTask = context.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); Assert.True(writeTask.IsCanceled); context.Dispose(); +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif await Assert.ThrowsAsync(() => responseTask); } diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ServerTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ServerTests.cs index 6400b7f202..fa6a81246e 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ServerTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/ServerTests.cs @@ -186,10 +186,13 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener context.Abort(); Assert.True(canceled.WaitOne(interval), "Aborted"); Assert.True(ct.IsCancellationRequested, "IsCancellationRequested"); -#if !NETCOREAPP1_1 +#if NET452 // HttpClient re-tries the request because it doesn't know if the request was received. context = await server.AcceptAsync(Utilities.DefaultTimeout); context.Abort(); +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif await Assert.ThrowsAsync(() => responseTask); } diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/SkipOffDomainAttribute.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/SkipOffDomainAttribute.cs index 941425bdc3..75b956a1b2 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/SkipOffDomainAttribute.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/SkipOffDomainAttribute.cs @@ -20,6 +20,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener { #if NET452 return !string.IsNullOrEmpty(System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().Name); +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif } catch diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/Utilities.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/Utilities.cs index 9bcf76d333..6b35ade3df 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/Utilities.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/Utilities.cs @@ -28,8 +28,10 @@ namespace Microsoft.AspNetCore.Server.HttpSys.Listener #if NET452 IsWin8orLater = (Environment.OSVersion.Version >= win8Version); -#else +#elif NETCOREAPP2_0 IsWin8orLater = (new Version(RuntimeEnvironment.OperatingSystemVersion) >= win8Version); +#else +#error Target framework needs to be updated #endif } diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests.csproj index 34d602e0a3..e717078d1b 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests.csproj @@ -3,8 +3,8 @@ - netcoreapp1.1;net452 - netcoreapp1.1 + netcoreapp2.0;net452 + netcoreapp2.0 @@ -24,7 +24,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/RequestBodyTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/RequestBodyTests.cs index f2da4d3baf..790434bc33 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/RequestBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/RequestBodyTests.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys Assert.Equal("Hello World", response); } } -#if !NETCOREAPP1_1 +#if NET452 [ConditionalFact] public async Task RequestBody_ReadBeginEnd_Success() { @@ -68,6 +68,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys Assert.Equal("Hello World", response); } } +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif [ConditionalFact] diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/ResponseBodyTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/ResponseBodyTests.cs index 199948dab8..a55c2aa1d0 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/ResponseBodyTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/ResponseBodyTests.cs @@ -89,8 +89,10 @@ namespace Microsoft.AspNetCore.Server.HttpSys Stream stream = httpContext.Response.Body; #if NET452 stream.EndWrite(stream.BeginWrite(new byte[10], 0, 10, null, null)); -#else +#elif NETCOREAPP2_0 await stream.WriteAsync(new byte[10], 0, 10); +#else +#error Target framework needs to be updated #endif stream.Write(new byte[10], 0, 10); await stream.WriteAsync(new byte[10], 0, 10); @@ -249,6 +251,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys Assert.Equal(new byte[10], await response.Content.ReadAsByteArrayAsync()); } } +#elif NETCOREAPP2_0 +#else +#error Target framework needs to be updated #endif [ConditionalFact] public async Task ResponseBody_WriteAsync_TriggersOnStarting() diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/ResponseHeaderTests.cs b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/ResponseHeaderTests.cs index 3631fc769b..cd041e15c1 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/ResponseHeaderTests.cs +++ b/test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/ResponseHeaderTests.cs @@ -81,10 +81,12 @@ namespace Microsoft.AspNetCore.Server.HttpSys Assert.Equal(0, response.ContentLength); Assert.NotNull(response.Headers["Date"]); Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]); -#if NETCOREAPP1_1 // WebHeaderCollection.GetValues() not available in CoreCLR. +#if NETCOREAPP2_0 // WebHeaderCollection.GetValues() not available in CoreCLR. Assert.Equal("custom1, and custom2, custom3", response.Headers["WWW-Authenticate"]); -#else +#elif NET452 Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("WWW-Authenticate")); +#else +#error Target framework needs to be updated #endif } } @@ -109,10 +111,12 @@ namespace Microsoft.AspNetCore.Server.HttpSys Assert.Equal(0, response.ContentLength); Assert.NotNull(response.Headers["Date"]); Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]); -#if NETCOREAPP1_1 // WebHeaderCollection.GetValues() not available in CoreCLR. +#if NETCOREAPP2_0 // WebHeaderCollection.GetValues() not available in CoreCLR. Assert.Equal("custom1, and custom2, custom3", response.Headers["Custom-Header1"]); -#else +#elif NET452 Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("Custom-Header1")); +#else +#error Target framework needs to be updated #endif } } diff --git a/test/Microsoft.AspNetCore.Server.HttpSys.Tests/Microsoft.AspNetCore.Server.HttpSys.Tests.csproj b/test/Microsoft.AspNetCore.Server.HttpSys.Tests/Microsoft.AspNetCore.Server.HttpSys.Tests.csproj index c681773b02..cd0c882e6f 100644 --- a/test/Microsoft.AspNetCore.Server.HttpSys.Tests/Microsoft.AspNetCore.Server.HttpSys.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.HttpSys.Tests/Microsoft.AspNetCore.Server.HttpSys.Tests.csproj @@ -3,8 +3,8 @@ - netcoreapp1.1;net452 - netcoreapp1.1 + netcoreapp2.0;net452 + netcoreapp2.0