From 11309866e3a50a9e302fe843bee51a0fe8b7d609 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 30 Jan 2024 11:49:23 -0800 Subject: [PATCH 1/4] Update dependencies and targets --- .github/workflows/pr-build.yml | 22 ++---------- AzureRelayServer.sln | 14 ++------ Directory.Build.props | 2 +- Directory.Packages.props | 16 +++++++++ samples/MVCServerApp/MVCServerApp.csproj | 7 +--- samples/MVCServerApp/Startup.cs | 18 +++------- samples/SelfHostServer/SelfHostServer.csproj | 7 ++-- .../AzureRelayListener.cs | 1 + .../Microsoft.Azure.Relay.AspNetCore.csproj | 24 +++++-------- test/Directory.Build.props | 11 ++---- .../HttpsTests.cs | 36 +++++++++++-------- .../LaunchSettingsFixture.cs | 23 +++++------- .../Listener/HttpsTests.cs | 32 ++++++++++------- .../Listener/ResponseBodyTests.cs | 9 ----- .../Listener/ResponseHeaderTests.cs | 12 ------- ...re.Relay.AspNetCore.FunctionalTests.csproj | 8 +---- .../OpaqueUpgradeTests.cs | 6 ++-- .../RequestBodyLimitTests.cs | 20 +++++------ .../RequestBodyTests.cs | 8 ++--- .../RequestHeaderTests.cs | 4 +-- .../RequestTests.cs | 12 +++---- .../ResponseBodyTests.cs | 14 ++++---- .../ResponseHeaderTests.cs | 26 ++++---------- .../ResponseSendFileTests.cs | 28 +++++++-------- .../ResponseTests.cs | 22 ++++++------ .../ServerTests.cs | 8 ++--- 26 files changed, 159 insertions(+), 231 deletions(-) create mode 100644 Directory.Packages.props diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 853a2dad..8839fccd 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -6,18 +6,10 @@ jobs: build-windows: name: Build 'azure-relay-aspnetserver' on windows-latest - runs-on: 'windows-2019' + runs-on: 'windows-latest' steps: - - uses: actions/checkout@v1 - - name: Setup .NET Core 2.2 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '2.2.x' - - name: Setup .NET Core 3.1 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '3.1.x' + - uses: actions/checkout@v4 - run: dotnet --info - name: Restore run: .\restore.cmd @@ -34,15 +26,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v1 - - name: Setup .NET Core 2.2 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '2.2.x' - - name: Setup .NET Core 3.1 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '3.1.x' + - uses: actions/checkout@v4 - run: dotnet --info - name: Restore run: ./restore.sh diff --git a/AzureRelayServer.sln b/AzureRelayServer.sln index 851963df..7e5b9c7b 100644 --- a/AzureRelayServer.sln +++ b/AzureRelayServer.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29503.13 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34511.98 MinimumVisualStudioVersion = 15.0.26730.03 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{99D5E5F3-88F5-4CCF-8D8C-717C8925DF09}" ProjectSection(SolutionItems) = preProject @@ -16,13 +16,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3A1E EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5E9B546C-17AC-4BDF-BCB3-5955D4755ED8}" ProjectSection(SolutionItems) = preProject - .appveyor.yml = .appveyor.yml .gitignore = .gitignore - .travis.yml = .travis.yml build.cmd = build.cmd build.sh = build.sh Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets + Directory.Packages.props = Directory.Packages.props NuGet.config = NuGet.config README.md = README.md EndProjectSection @@ -33,12 +32,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Relay.AspNe EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Relay.AspNetCore", "src\Microsoft.Azure.Relay.AspNetCore\Microsoft.Azure.Relay.AspNetCore.csproj", "{B9F45F9D-D206-47F0-8E5F-54CE2F0BDF92}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{85914BA9-4168-48C5-9C3F-E2E8B1479A6E}" - ProjectSection(SolutionItems) = preProject - build\dependencies.props = build\dependencies.props - build\Key.snk = build\Key.snk - EndProjectSection -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVCServerApp", "samples\MVCServerApp\MVCServerApp.csproj", "{E9ED2DA2-BFAF-4ABF-B045-63B787CA6CCE}" EndProject Global @@ -101,7 +94,6 @@ Global {1236F93A-AC5C-4A77-9477-C88F040151CA} = {3A1E31E3-2794-4CA3-B8E2-253E96BDE514} {4492FF4C-9032-411D-853F-46B01755E504} = {E183C826-1360-4DFF-9994-F33CED5C8525} {B9F45F9D-D206-47F0-8E5F-54CE2F0BDF92} = {99D5E5F3-88F5-4CCF-8D8C-717C8925DF09} - {85914BA9-4168-48C5-9C3F-E2E8B1479A6E} = {5E9B546C-17AC-4BDF-BCB3-5955D4755ED8} {E9ED2DA2-BFAF-4ABF-B045-63B787CA6CCE} = {3A1E31E3-2794-4CA3-B8E2-253E96BDE514} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/Directory.Build.props b/Directory.Build.props index ce22d272..3fc9aa13 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -8,7 +8,7 @@ - 2.0.1 + 3.0.1 diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 00000000..2846b151 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,16 @@ + + + + true + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/MVCServerApp/MVCServerApp.csproj b/samples/MVCServerApp/MVCServerApp.csproj index e364a2d1..94c8f6ca 100644 --- a/samples/MVCServerApp/MVCServerApp.csproj +++ b/samples/MVCServerApp/MVCServerApp.csproj @@ -1,14 +1,9 @@  - netcoreapp2.1 + net6.0 - - - - - diff --git a/samples/MVCServerApp/Startup.cs b/samples/MVCServerApp/Startup.cs index f03733c4..2259a3db 100644 --- a/samples/MVCServerApp/Startup.cs +++ b/samples/MVCServerApp/Startup.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace MVCServerApp { @@ -21,11 +18,11 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc(); + services.AddMvc(options => options.EnableEndpointRouting = false); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { @@ -39,12 +36,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseStaticFiles(); - app.UseMvc(routes => - { - routes.MapRoute( - name: "default", - template: "{controller=Home}/{action=Index}/{id?}"); - }); + app.UseMvcWithDefaultRoute(); } } } diff --git a/samples/SelfHostServer/SelfHostServer.csproj b/samples/SelfHostServer/SelfHostServer.csproj index 54faeb54..ccae2ba5 100644 --- a/samples/SelfHostServer/SelfHostServer.csproj +++ b/samples/SelfHostServer/SelfHostServer.csproj @@ -1,8 +1,8 @@  - netcoreapp3.1;netcoreapp2.1 - $(TargetFrameworks);net461 + net6.0 + Exe true @@ -12,8 +12,7 @@ - - + diff --git a/src/Microsoft.Azure.Relay.AspNetCore/AzureRelayListener.cs b/src/Microsoft.Azure.Relay.AspNetCore/AzureRelayListener.cs index f0b438ee..5ae1c9d6 100644 --- a/src/Microsoft.Azure.Relay.AspNetCore/AzureRelayListener.cs +++ b/src/Microsoft.Azure.Relay.AspNetCore/AzureRelayListener.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; using Microsoft.Extensions.Logging; +using Microsoft.Azure.Relay; namespace Microsoft.Azure.Relay.AspNetCore { diff --git a/src/Microsoft.Azure.Relay.AspNetCore/Microsoft.Azure.Relay.AspNetCore.csproj b/src/Microsoft.Azure.Relay.AspNetCore/Microsoft.Azure.Relay.AspNetCore.csproj index 94f0693c..b77b8d12 100644 --- a/src/Microsoft.Azure.Relay.AspNetCore/Microsoft.Azure.Relay.AspNetCore.csproj +++ b/src/Microsoft.Azure.Relay.AspNetCore/Microsoft.Azure.Relay.AspNetCore.csproj @@ -3,8 +3,8 @@ ASP.NET Core HTTP server that uses Azure Relay. Microsoft - © Microsoft Corporation. All rights reserved. - netstandard2.0;netstandard2.1 + © Microsoft Corporation. All rights reserved. + net6.0 $(NoWarn);CS1591 true true @@ -14,25 +14,17 @@ https://raw.githubusercontent.com/Azure/azure-relay-dotnet/master/relay.png https://github.com/Azure/azure-relay-aspnetserver True + latest - - - - - - - - - - - - + + - - + + + diff --git a/test/Directory.Build.props b/test/Directory.Build.props index b373456d..6b9ef916 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -1,15 +1,8 @@ - - netcoreapp2.1;netcoreapp3.1 - $(DeveloperBuildTestTfms) - $(StandardTestTfms) - $(StandardTestTfms);net461 - - - - + + diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/HttpsTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/HttpsTests.cs index a92e0186..79622804 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/HttpsTests.cs @@ -28,7 +28,7 @@ public async Task Https_200OK_Success() { using (Utilities.CreateHttpsServer(httpContext => { - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(Address); @@ -61,7 +61,7 @@ public async Task Https_EchoHelloWorld_Success() byte[] body = Encoding.UTF8.GetBytes("Hello World"); httpContext.Response.ContentLength = body.Length; httpContext.Response.Body.Write(body, 0, body.Length); - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(Address, "Hello World"); @@ -108,28 +108,34 @@ public async Task Https_ClientCertRequested_ClientCertPresent() private async Task SendRequestAsync(string uri, X509Certificate cert = null) { - var handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback = (a, b, c, d) => true; + var handler = new HttpClientHandler + { + ClientCertificateOptions = ClientCertificateOption.Manual, + ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true + }; + if (cert != null) { handler.ClientCertificates.Add(cert); } - using (HttpClient client = new HttpClient(handler)) - { - return await client.GetStringAsync(uri); - } + + using HttpClient client = new HttpClient(handler); + return await client.GetStringAsync(uri); } private async Task SendRequestAsync(string uri, string upload) { - var handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback = (a, b, c, d) => true; - using (HttpClient client = new HttpClient(handler)) + var handler = new HttpClientHandler { - HttpResponseMessage response = await client.PostAsync(uri, new StringContent(upload)); - response.EnsureSuccessStatusCode(); - return await response.Content.ReadAsStringAsync(); - } + ClientCertificateOptions = ClientCertificateOption.Manual, + ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true + }; + + using HttpClient client = new HttpClient(handler); + + HttpResponseMessage response = await client.PostAsync(uri, new StringContent(upload)); + response.EnsureSuccessStatusCode(); + return await response.Content.ReadAsStringAsync(); } private X509Certificate2 FindClientCert() diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/LaunchSettingsFixture.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/LaunchSettingsFixture.cs index 223adeb2..df33dae5 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/LaunchSettingsFixture.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/LaunchSettingsFixture.cs @@ -1,10 +1,7 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; +using System; using System.IO; using System.Linq; -using System.Text; +using System.Text.Json; namespace Microsoft.Azure.Relay.AspNetCore { @@ -15,23 +12,21 @@ public LaunchSettingsFixture() string filename = "Properties\\launchSettings.json"; if (File.Exists(filename)) { - using (var file = File.OpenText(filename)) + using (var file = File.Open(filename, FileMode.Open)) { - var reader = new JsonTextReader(file); - var jObject = JObject.Load(reader); + var json = JsonDocument.Parse(file).RootElement; - var variables = jObject - .GetValue("profiles") + var variables = json. + GetProperty("profiles").EnumerateObject() //select a proper profile here - .SelectMany(profiles => profiles.Children()) - .SelectMany(profile => profile.Children()) + .SelectMany(profile => profile.Value.EnumerateObject()) .Where(prop => prop.Name == "environmentVariables") - .SelectMany(prop => prop.Value.Children()) + .SelectMany(prop => prop.Value.EnumerateObject()) .ToList(); foreach (var variable in variables) { - Environment.SetEnvironmentVariable(variable.Name, variable.Value.ToString()); + Environment.SetEnvironmentVariable(variable.Name, variable.Value.GetString()); } } } diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/HttpsTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/HttpsTests.cs index f989f528..d09e1ea0 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/HttpsTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/HttpsTests.cs @@ -3,6 +3,7 @@ using System.IO; using System.Net.Http; +using System.Runtime.ConstrainedExecution; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; @@ -114,28 +115,33 @@ public async Task Https_ClientCertRequested_ClientCertPresent() private async Task SendRequestAsync(string uri, X509Certificate cert = null) { - WinHttpHandler handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback = (a, b, c, d) => true; + var handler = new HttpClientHandler + { + ClientCertificateOptions = ClientCertificateOption.Manual, + ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true + }; + if (cert != null) { handler.ClientCertificates.Add(cert); } - using (HttpClient client = new HttpClient(handler)) - { - return await client.GetStringAsync(uri); - } + + using HttpClient client = new HttpClient(handler); + return await client.GetStringAsync(uri); } private async Task SendRequestAsync(string uri, string upload) { - WinHttpHandler handler = new WinHttpHandler(); - handler.ServerCertificateValidationCallback = (a, b, c, d) => true; - using (HttpClient client = new HttpClient(handler)) + var handler = new HttpClientHandler { - HttpResponseMessage response = await client.PostAsync(uri, new StringContent(upload)); - response.EnsureSuccessStatusCode(); - return await response.Content.ReadAsStringAsync(); - } + ClientCertificateOptions = ClientCertificateOption.Manual, + ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true + }; + + using HttpClient client = new HttpClient(handler); + HttpResponseMessage response = await client.PostAsync(uri, new StringContent(upload)); + response.EnsureSuccessStatusCode(); + return await response.Content.ReadAsStringAsync(); } private X509Certificate2 FindClientCert() diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/ResponseBodyTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/ResponseBodyTests.cs index 8d930deb..acc98657 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/ResponseBodyTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/ResponseBodyTests.cs @@ -133,15 +133,6 @@ public async Task ResponseBody_WriteContentLengthNoneWritten_Aborts() var context = await server.AcceptAsync(Utilities.DefaultTimeout); context.Response.Headers["Content-lenGth"] = " 20 "; context.Dispose(); -#if NET461 - // 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 || NETCOREAPP2_1 -#else -#error Target framework needs to be updated -#endif await Assert.ThrowsAsync(() => responseTask); } } diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/ResponseHeaderTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/ResponseHeaderTests.cs index d4ff3d88..cc2cbe6d 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/ResponseHeaderTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Listener/ResponseHeaderTests.cs @@ -259,13 +259,7 @@ public async Task ResponseHeaders_ServerSendsMultiValueKnownHeaders_Success() Assert.Equal(0, response.ContentLength); Assert.NotNull(response.Headers["Date"]); Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]); -#if NETCOREAPP2_0 || NETCOREAPP2_1 // WebHeaderCollection.GetValues() not available in CoreCLR. Assert.Equal("custom1, and custom2, custom3", response.Headers["WWW-Authenticate"]); -#elif NET461 - Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("WWW-Authenticate")); -#else -#error Target framework needs to be updated -#endif } } @@ -290,13 +284,7 @@ public async Task ResponseHeaders_ServerSendsCustomHeaders_Success() Assert.Equal(0, response.ContentLength); Assert.NotNull(response.Headers["Date"]); Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]); -#if NETCOREAPP2_0 || NETCOREAPP2_1 // WebHeaderCollection.GetValues() not available in CoreCLR. - Assert.Equal("custom1, and custom2, custom3", response.Headers["Custom-Header1"]); -#elif NET461 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.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj index 4653e3a6..05533978 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj @@ -1,17 +1,11 @@  - $(StandardTestTfms) + net6.0;net8.0 - - - - - - diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/OpaqueUpgradeTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/OpaqueUpgradeTests.cs index f02f3f0d..a6cda859 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/OpaqueUpgradeTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/OpaqueUpgradeTests.cs @@ -42,7 +42,7 @@ public async Task OpaqueUpgrade_DownLevel_FeatureIsAbsent() { return httpContext.Response.WriteAsync(ex.ToString()); } - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); @@ -69,7 +69,7 @@ public async Task OpaqueUpgrade_SupportKeys_Present() { return httpContext.Response.WriteAsync(ex.ToString()); } - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); @@ -187,7 +187,7 @@ public async Task OpaqueUpgrade_WithOnStarting_CallbackCalled() httpContext.Response.OnStarting(_ => { callbackCalled = true; - return Task.FromResult(0); + return Task.CompletedTask; }, null); httpContext.Response.Headers["Upgrade"] = "websocket"; // Win8.1 blocks anything but WebSockets var opaqueFeature = httpContext.Features.Get(); diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestBodyLimitTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestBodyLimitTests.cs index 48bb07cf..0e13b568 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestBodyLimitTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestBodyLimitTests.cs @@ -38,7 +38,7 @@ public async Task ContentLengthEqualsLimit_ReadSync_Success() int read = httpContext.Request.Body.Read(input, 0, input.Length); httpContext.Response.ContentLength = read; httpContext.Response.Body.Write(input, 0, read); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address, "Hello World"); @@ -84,7 +84,7 @@ public async Task ContentLengthEqualsLimit_ReadBeginEnd_Success() int read = httpContext.Request.Body.EndRead(httpContext.Request.Body.BeginRead(input, 0, input.Length, null, null)); httpContext.Response.ContentLength = read; httpContext.Response.Body.EndWrite(httpContext.Response.Body.BeginWrite(input, 0, read, null, null)); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address, "Hello World"); @@ -109,7 +109,7 @@ public async Task ChunkedEqualsLimit_ReadSync_Success() int read = httpContext.Request.Body.Read(input, 0, input.Length); httpContext.Response.ContentLength = read; httpContext.Response.Body.Write(input, 0, read); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address, "Hello World", chunked: true); @@ -156,7 +156,7 @@ public async Task ChunkedEqualsLimit_ReadBeginEnd_Success() int read = httpContext.Request.Body.EndRead(httpContext.Request.Body.BeginRead(input, 0, input.Length, null, null)); httpContext.Response.ContentLength = read; httpContext.Response.Body.EndWrite(httpContext.Response.Body.BeginWrite(input, 0, read, null, null)); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address, "Hello World", chunked: true); @@ -183,7 +183,7 @@ public async Task ContentLengthExceedsLimit_ReadSync_ThrowsImmediately() Assert.Equal("The request's Content-Length 11 is larger than the request body size limit 10.", ex.Message); ex = Assert.Throws(() => httpContext.Request.Body.Read(input, 0, input.Length)); Assert.Equal("The request's Content-Length 11 is larger than the request body size limit 10.", ex.Message); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address, "Hello World"); @@ -208,7 +208,7 @@ public async Task ContentLengthExceedsLimit_ReadAsync_ThrowsImmediately() Assert.Equal("The request's Content-Length 11 is larger than the request body size limit 10.", ex.Message); ex = Assert.Throws(() => { var t = httpContext.Request.Body.ReadAsync(input, 0, input.Length); }); Assert.Equal("The request's Content-Length 11 is larger than the request body size limit 10.", ex.Message); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address, "Hello World"); @@ -231,7 +231,7 @@ public async Task ContentLengthExceedsLimit_ReadBeginEnd_ThrowsImmediately() Assert.Equal("The request's Content-Length 11 is larger than the request body size limit 10.", ex.Message); ex = Assert.Throws(() => httpContext.Request.Body.BeginRead(input, 0, input.Length, null, null)); Assert.Equal("The request's Content-Length 11 is larger than the request body size limit 10.", ex.Message); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address, "Hello World"); @@ -255,7 +255,7 @@ public async Task ChunkedExceedsLimit_ReadSync_ThrowsAtLimit() Assert.Equal("The total number of bytes read 11 has exceeded the request body size limit 10.", ex.Message); ex = Assert.Throws(() => httpContext.Request.Body.Read(input, 0, input.Length)); Assert.Equal("The total number of bytes read 11 has exceeded the request body size limit 10.", ex.Message); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address, "Hello World", chunked: true); @@ -301,7 +301,7 @@ public async Task ChunkedExceedsLimit_ReadBeginEnd_ThrowsAtLimit() Assert.Equal("The total number of bytes read 11 has exceeded the request body size limit 10.", ex.Message); ex = Assert.Throws(() => body.EndRead(body.BeginRead(input, 0, input.Length, null, null))); Assert.Equal("The total number of bytes read 11 has exceeded the request body size limit 10.", ex.Message); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address, "Hello World", chunked: true); @@ -329,7 +329,7 @@ public async Task Chunked_ReadSyncPartialBodyUnderLimit_ThrowsAfterLimit() content.Block.Release(); var ex = Assert.Throws(() => httpContext.Request.Body.Read(input, 0, input.Length)); Assert.Equal("The total number of bytes read 20 has exceeded the request body size limit 10.", ex.Message); - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(address, content, chunked: true); diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestBodyTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestBodyTests.cs index 9b7a3002..2c292d5c 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestBodyTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestBodyTests.cs @@ -35,7 +35,7 @@ public async Task RequestBody_ReadSync_Success() int read = httpContext.Request.Body.Read(input, 0, input.Length); httpContext.Response.ContentLength = read; httpContext.Response.Body.Write(input, 0, read); - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(address, "Hello World"); @@ -70,7 +70,7 @@ public async Task RequestBody_ReadBeginEnd_Success() int read = httpContext.Request.Body.EndRead(httpContext.Request.Body.BeginRead(input, 0, input.Length, null, null)); httpContext.Response.ContentLength = read; httpContext.Response.Body.EndWrite(httpContext.Response.Body.BeginWrite(input, 0, read, null, null)); - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(address, "Hello World"); @@ -93,7 +93,7 @@ public async Task RequestBody_InvalidBuffer_ArgumentException() Assert.Throws("size", () => httpContext.Request.Body.Read(input, 0, 0)); Assert.Throws("size", () => httpContext.Request.Body.Read(input, 1, input.Length)); Assert.Throws("size", () => httpContext.Request.Body.Read(input, 0, input.Length + 1)); - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(address, "Hello World"); @@ -116,7 +116,7 @@ public async Task RequestBody_ReadSyncPartialBody_Success() content.Block.Release(); read = httpContext.Request.Body.Read(input, 0, input.Length); Assert.Equal(5, read); - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(address, content); diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestHeaderTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestHeaderTests.cs index 7bbc28d0..de30b0f0 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestHeaderTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestHeaderTests.cs @@ -34,7 +34,7 @@ public async Task RequestHeaders_ClientSendsDefaultHeaders_Success() // Assert.Equal("Keep-Alive", requestHeaders.Get("Connection")); Assert.False(StringValues.IsNullOrEmpty(requestHeaders["Host"])); Assert.True(StringValues.IsNullOrEmpty(requestHeaders["Accept"])); - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(address); @@ -57,7 +57,7 @@ public async Task RequestHeaders_ClientSendsCustomHeaders_Success() Assert.Equal("custom1, and custom2, custom3", requestHeaders["Custom-Header"]); Assert.Single(requestHeaders["Spacer-Header"]); Assert.Equal("spacervalue, spacervalue", requestHeaders["Spacer-Header"]); - return Task.FromResult(0); + return Task.CompletedTask; })) { string[] customValues = new string[] { "custom1, and custom2", "custom3" }; diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestTests.cs index 8f2cd165..5164a6ab 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/RequestTests.cs @@ -72,7 +72,7 @@ public async Task Request_SimpleGet_ExpectedFieldsSet() byte[] body = Encoding.ASCII.GetBytes(ex.ToString()); httpContext.Response.Body.Write(body, 0, body.Length); } - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(root + "/basepath/SomePath?SomeQuery"); @@ -138,7 +138,7 @@ public async Task Request_FieldsCanBeSet_Set() byte[] body = Encoding.ASCII.GetBytes(ex.ToString()); httpContext.Response.Body.Write(body, 0, body.Length); } - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(root + "/basepath/SomePath?SomeQuery"); @@ -203,7 +203,7 @@ public async Task Request_FieldsCanBeSetToNull_Set() byte[] body = Encoding.ASCII.GetBytes(ex.ToString()); httpContext.Response.Body.Write(body, 0, body.Length); } - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(root + "/basepath/SomePath?SomeQuery=foo"); @@ -248,7 +248,7 @@ public async Task Request_PathSplitting(string pathBase, string requestPath, str byte[] body = Encoding.ASCII.GetBytes(ex.ToString()); httpContext.Response.Body.Write(body, 0, body.Length); } - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(root + requestPath); @@ -267,7 +267,7 @@ public async Task Request_DoubleEscapingAllowed() var requestInfo = httpContext.Features.Get(); Assert.Equal("/%2F", requestInfo.Path); Assert.Equal("/%252F", requestInfo.RawTarget); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendSocketRequestAsync(root, "/%252F"); @@ -351,7 +351,7 @@ public async Task Request_MultiplePrefixes(string requestPath, string expectedPa byte[] body = Encoding.ASCII.GetBytes(ex.ToString()); httpContext.Response.Body.Write(body, 0, body.Length); } - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(root + requestPath); diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseBodyTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseBodyTests.cs index 9a3223e8..8d6405cc 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseBodyTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseBodyTests.cs @@ -126,7 +126,7 @@ public async Task ResponseBody_WriteContentLengthNoneWritten_Throws() using (Utilities.CreateHttpServer(out address, httpContext => { httpContext.Response.Headers["Content-lenGth"] = " 20 "; - return Task.FromResult(0); + return Task.CompletedTask; })) { await Assert.ThrowsAsync(() => SendRequestAsync(address)); @@ -187,7 +187,7 @@ public async Task ResponseBody_WriteContentLengthExtraWritten_Throws() appThrew = true; } waitHandle.Set(); - return Task.FromResult(0); + return Task.CompletedTask; })) { // The full response is received. @@ -218,10 +218,10 @@ public async Task ResponseBody_Write_TriggersOnStarting() { onStartingCalled = true; Assert.Same(state, httpContext); - return Task.FromResult(0); + return Task.CompletedTask; }, httpContext); httpContext.Response.Body.Write(new byte[10], 0, 10); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address); @@ -246,10 +246,10 @@ public async Task ResponseBody_BeginWrite_TriggersOnStarting() { onStartingCalled = true; Assert.Same(state, httpContext); - return Task.FromResult(0); + return Task.CompletedTask; }, httpContext); httpContext.Response.Body.EndWrite(httpContext.Response.Body.BeginWrite(new byte[10], 0, 10, null, null)); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address); @@ -274,7 +274,7 @@ public async Task ResponseBody_WriteAsync_TriggersOnStarting() { onStartingCalled = true; Assert.Same(state, httpContext); - return Task.FromResult(0); + return Task.CompletedTask; }, httpContext); return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); })) diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseHeaderTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseHeaderTests.cs index 7925b610..955023b9 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseHeaderTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseHeaderTests.cs @@ -31,7 +31,7 @@ public async Task ResponseHeaders_ServerSendsDefaultHeaders_Success() string address; using (Utilities.CreateHttpServer(out address, httpContext => { - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); @@ -54,7 +54,7 @@ public async Task ResponseHeaders_ServerSendsSingleValueKnownHeaders_Success() var responseInfo = httpContext.Features.Get(); var responseHeaders = responseInfo.Headers; responseHeaders["WWW-Authenticate"] = new string[] { "custom1" }; - return Task.FromResult(0); + return Task.CompletedTask; })) { // HttpClient would merge the headers no matter what @@ -78,7 +78,7 @@ public async Task ResponseHeaders_ServerSendsMultiValueKnownHeaders_Success() var responseInfo = httpContext.Features.Get(); var responseHeaders = responseInfo.Headers; responseHeaders["WWW-Authenticate"] = new string[] { "custom1, and custom2", "custom3" }; - return Task.FromResult(0); + return Task.CompletedTask; })) { // HttpClient would merge the headers no matter what @@ -89,13 +89,7 @@ public async Task ResponseHeaders_ServerSendsMultiValueKnownHeaders_Success() Assert.Equal(0, response.ContentLength); Assert.NotNull(response.Headers["Date"]); Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]); -#if NETCOREAPP2_0 || NETCOREAPP2_1 // WebHeaderCollection.GetValues() not available in CoreCLR. - Assert.Equal("custom1, and custom2, custom3", response.Headers["WWW-Authenticate"]); -#elif NET461 Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("WWW-Authenticate")); -#else -#error Target framework needs to be updated -#endif } } @@ -108,7 +102,7 @@ public async Task ResponseHeaders_ServerSendsCustomHeaders_Success() var responseInfo = httpContext.Features.Get(); var responseHeaders = responseInfo.Headers; responseHeaders["Custom-Header1"] = new string[] { "custom1, and custom2", "custom3" }; - return Task.FromResult(0); + return Task.CompletedTask; })) { // HttpClient would merge the headers no matter what @@ -119,13 +113,7 @@ public async Task ResponseHeaders_ServerSendsCustomHeaders_Success() Assert.Equal(0, response.ContentLength); Assert.NotNull(response.Headers["Date"]); Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]); -#if NETCOREAPP2_0 || NETCOREAPP2_1 // WebHeaderCollection.GetValues() not available in CoreCLR. - Assert.Equal("custom1, and custom2, custom3", response.Headers["Custom-Header1"]); -#elif NET461 Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("Custom-Header1")); -#else -#error Target framework needs to be updated -#endif } } @@ -159,7 +147,7 @@ public async Task ResponseHeaders_HTTP10Request_Gets11Close() string address; using (Utilities.CreateHttpServer(out address, httpContext => { - return Task.FromResult(0); + return Task.CompletedTask; })) { using (HttpClient client = new HttpClient()) @@ -222,7 +210,7 @@ public async Task Headers_FlushSendsHeaders_Success() Assert.True(responseInfo.HasStarted); Assert.Throws(() => responseInfo.StatusCode = 404); Assert.Throws(() => responseHeaders.Add("Custom3", new string[] { "value3a, value3b", "value3c" })); - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); @@ -275,7 +263,7 @@ public async Task Headers_IgnoreNullHeaders(string headerName, StringValues head { var responseHeaders = httpContext.Response.Headers; responseHeaders.Add(headerName, headerValue); - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseSendFileTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseSendFileTests.cs index 2f0b4039..f491fc5b 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseSendFileTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseSendFileTests.cs @@ -51,11 +51,7 @@ public async Task ResponseSendFile_SupportKeys_Present() Assert.Equal("Overlapped", support.Get("sendfile.Concurrency")); */ -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 var sendFile = httpContext.Features.Get(); -#else - var sendFile = httpContext.Features.Get(); -#endif Assert.NotNull(sendFile); } catch (Exception ex) @@ -63,7 +59,7 @@ public async Task ResponseSendFile_SupportKeys_Present() byte[] body = Encoding.UTF8.GetBytes(ex.ToString()); httpContext.Response.Body.Write(body, 0, body.Length); } - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address); @@ -101,7 +97,7 @@ public async Task ResponseSendFile_MissingFile_Throws() { waitHandle.Set(); } - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); @@ -119,7 +115,7 @@ public async Task ResponseSendFile_NoHeaders_DefaultsToChunked() string address; using (Utilities.CreateHttpServer(out address, httpContext => { -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); #else var sendFile = httpContext.Features.Get(); @@ -142,7 +138,7 @@ public async Task ResponseSendFile_RelativeFile_Success() string address; using (Utilities.CreateHttpServer(out address, httpContext => { -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); #else var sendFile = httpContext.Features.Get(); @@ -165,7 +161,7 @@ public async Task ResponseSendFile_Unspecified_Chunked() string address; using (Utilities.CreateHttpServer(out address, httpContext => { -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); #else var sendFile = httpContext.Features.Get(); @@ -188,7 +184,7 @@ public async Task ResponseSendFile_MultipleWrites_Chunked() string address; using (Utilities.CreateHttpServer(out address, httpContext => { -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); #else var sendFile = httpContext.Features.Get(); @@ -212,7 +208,7 @@ public async Task ResponseSendFile_HalfOfFile_Chunked() string address; using (Utilities.CreateHttpServer(out address, httpContext => { -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); #else var sendFile = httpContext.Features.Get(); @@ -236,7 +232,7 @@ public async Task ResponseSendFile_OffsetOutOfRange_Throws() string address; using (Utilities.CreateHttpServer(out address, async httpContext => { -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); #else var sendFile = httpContext.Features.Get(); @@ -259,7 +255,7 @@ public async Task ResponseSendFile_CountOutOfRange_Throws() string address; using (Utilities.CreateHttpServer(out address, async httpContext => { -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); #else var sendFile = httpContext.Features.Get(); @@ -347,7 +343,7 @@ public async Task ResponseSendFile_ContentLength0_PassedThrough() string address; using (Utilities.CreateHttpServer(out address, httpContext => { -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); #else var sendFile = httpContext.Features.Get(); @@ -377,9 +373,9 @@ public async Task ResponseSendFile_TriggersOnStarting() { onStartingCalled = true; Assert.Same(state, httpContext); - return Task.FromResult(0); + return Task.CompletedTask; }, httpContext); -#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NET461 +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); #else var sendFile = httpContext.Features.Get(); diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseTests.cs index 1630ed19..1f73667b 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseTests.cs @@ -30,7 +30,7 @@ public async Task Response_ServerSendsDefaultResponse_ServerProvidesStatusCodeAn { Assert.Equal(200, httpContext.Response.StatusCode); Assert.False(httpContext.Response.HasStarted); - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); @@ -49,7 +49,7 @@ public async Task Response_ServerSendsSpecificStatus_ServerProvidesReasonPhrase( { httpContext.Response.StatusCode = 201; // TODO: httpContext["owin.ResponseProtocol"] = "HTTP/1.0"; // Http.Sys ignores this value - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); @@ -69,7 +69,7 @@ public async Task Response_ServerSendsSpecificStatusAndReasonPhrase_PassedThroug httpContext.Response.StatusCode = 201; httpContext.Features.Get().ReasonPhrase = "CustomReasonPhrase"; // TODO? // TODO: httpContext["owin.ResponseProtocol"] = "HTTP/1.0"; // Http.Sys ignores this value - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); @@ -88,7 +88,7 @@ public async Task Response_ServerSendsCustomStatus_NoReasonPhrase() using (Utilities.CreateHttpServer(out address, httpContext => { httpContext.Response.StatusCode = 901; - return Task.FromResult(0); + return Task.CompletedTask; })) { HttpResponseMessage response = await SendRequestAsync(address); @@ -111,15 +111,15 @@ public async Task Response_Empty_CallsOnStartingAndOnCompleted() { Assert.Same(state, httpContext); onStartingCalled.Set(); - return Task.FromResult(0); + return Task.CompletedTask; }, httpContext); httpContext.Response.OnCompleted(state => { Assert.Same(state, httpContext); onCompletedCalled.Set(); - return Task.FromResult(0); + return Task.CompletedTask; }, httpContext); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address); @@ -148,9 +148,9 @@ public async Task Response_OnStartingThrows_StillCallsOnCompleted() { Assert.Same(state, httpContext); onCompletedCalled.Set(); - return Task.FromResult(0); + return Task.CompletedTask; }, httpContext); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address); @@ -179,10 +179,10 @@ public async Task Response_OnStartingThrowsAfterWrite_WriteThrowsAndStillCallsOn { Assert.Same(state, httpContext); onCompletedCalled.Set(); - return Task.FromResult(0); + return Task.CompletedTask; }, httpContext); Assert.Throws(() => httpContext.Response.Body.Write(new byte[10], 0, 10)); - return Task.FromResult(0); + return Task.CompletedTask; })) { var response = await SendRequestAsync(address); diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ServerTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ServerTests.cs index 3de432f4..516c98ef 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ServerTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ServerTests.cs @@ -34,7 +34,7 @@ public async Task Server_200OK_Success() string address; using (Utilities.CreateHttpServer(out address, httpContext => { - return Task.FromResult(0); + return Task.CompletedTask; })) { string response = await SendRequestAsync(address); @@ -179,7 +179,7 @@ public void Server_MultipleOutstandingSyncRequests_Success() tcs.Task.Wait(); } - return Task.FromResult(0); + return Task.CompletedTask; })) { List requestTasks = new List(); @@ -242,7 +242,7 @@ public async Task Server_ClientDisconnects_CallCanceled() Assert.True(aborted.WaitOne(interval), "Aborted"); Assert.True(ct.WaitHandle.WaitOne(interval), "CT Wait"); Assert.True(ct.IsCancellationRequested, "IsCancellationRequested"); - return Task.FromResult(0); + return Task.CompletedTask; })) { // Note: System.Net.Sockets does not RST the connection by default, it just FINs. @@ -278,7 +278,7 @@ public async Task Server_Abort_CallCanceled() httpContext.Abort(); Assert.True(canceled.WaitOne(interval), "Aborted"); Assert.True(ct.IsCancellationRequested, "IsCancellationRequested"); - return Task.FromResult(0); + return Task.CompletedTask; })) { using (var client = await SendHungRequestAsync("GET", address)) From 446a24f953a2191f0671beb47fc5a6d0c0b554cc Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 30 Jan 2024 14:57:03 -0800 Subject: [PATCH 2/4] Add netstandard2.0 target --- Directory.Packages.props | 6 ++++++ .../Microsoft.Azure.Relay.AspNetCore.csproj | 10 ++++++++-- ...osoft.Azure.Relay.AspNetCore.FunctionalTests.csproj | 4 +++- .../ResponseSendFileTests.cs | 4 ++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 2846b151..986d19fe 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,12 +3,18 @@ true + + + + + + diff --git a/src/Microsoft.Azure.Relay.AspNetCore/Microsoft.Azure.Relay.AspNetCore.csproj b/src/Microsoft.Azure.Relay.AspNetCore/Microsoft.Azure.Relay.AspNetCore.csproj index b77b8d12..9abb5654 100644 --- a/src/Microsoft.Azure.Relay.AspNetCore/Microsoft.Azure.Relay.AspNetCore.csproj +++ b/src/Microsoft.Azure.Relay.AspNetCore/Microsoft.Azure.Relay.AspNetCore.csproj @@ -4,7 +4,7 @@ ASP.NET Core HTTP server that uses Azure Relay. Microsoft © Microsoft Corporation. All rights reserved. - net6.0 + netstandard2.0;net6.0 $(NoWarn);CS1591 true true @@ -17,10 +17,16 @@ latest - + + + + + + + diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj index 05533978..58925ee0 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj @@ -1,7 +1,9 @@  - net6.0;net8.0 + net462;net6.0;net8.0 + $(TargetFrameworks);net461 + latest diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseSendFileTests.cs b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseSendFileTests.cs index f491fc5b..71dbae49 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseSendFileTests.cs +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/ResponseSendFileTests.cs @@ -51,7 +51,11 @@ public async Task ResponseSendFile_SupportKeys_Present() Assert.Equal("Overlapped", support.Get("sendfile.Concurrency")); */ +#if NET6_0_OR_GREATER var sendFile = httpContext.Features.Get(); +#else + var sendFile = httpContext.Features.Get(); +#endif Assert.NotNull(sendFile); } catch (Exception ex) From 0398cdfd6f90ad36af6e3c9cca91f30671d1b4bf Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 30 Jan 2024 15:01:17 -0800 Subject: [PATCH 3/4] Fix full framework target --- .../Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj index 58925ee0..ce59400d 100644 --- a/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj +++ b/test/Microsoft.Azure.Relay.AspNetCore.FunctionalTests/Microsoft.Azure.Relay.AspNetCore.FunctionalTests.csproj @@ -1,8 +1,8 @@  - net462;net6.0;net8.0 - $(TargetFrameworks);net461 + net6.0;net8.0 + $(TargetFrameworks);net462 latest From 832b3a184d33e26f1d6364c6272752fd36e2ca68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Tue, 20 Feb 2024 10:01:54 -0800 Subject: [PATCH 4/4] Update SelfHostServer.csproj --- samples/SelfHostServer/SelfHostServer.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/SelfHostServer/SelfHostServer.csproj b/samples/SelfHostServer/SelfHostServer.csproj index ccae2ba5..328c62c6 100644 --- a/samples/SelfHostServer/SelfHostServer.csproj +++ b/samples/SelfHostServer/SelfHostServer.csproj @@ -2,7 +2,6 @@ net6.0 - Exe true