diff --git a/.gitignore b/.gitignore index 6cd7bfb72..9f67f0ee8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,20 @@ -[Bb]in -[Oo]bj -[Tt]est[Rr]esults -*.suo -*.user +.msbuild/ +.vs/ +bin/ +obj/ +packages/ + *.[Cc]ache -*[Rr]esharper* -packages -NuGet.exe -_[Ss]cripts *.binlog -*.exe *.dll -*.nupkg *.dot[Cc]over -*.vsp -*.psess +*.exe +*.nupkg *.orig +*.psess *.sln.ide -.vs/ -project.lock.json +*.suo +*.user +*.vsp +*[Rr]esharper* *launchSettings.json diff --git a/Runtime.msbuild b/Runtime.msbuild index ac847731a..e02860a28 100644 --- a/Runtime.msbuild +++ b/Runtime.msbuild @@ -115,12 +115,12 @@ XmlPath=$(TestResultsDirectory)%(_TestDLLsXunit.FileName)-XunitResults.xml - <_VSTestDLLs Include="bin\$(Configuration)\test\*\netcoreapp*\*.Test.dll" - Condition=" '$(BuildPortable)' == 'true' "/> - <_XunitProject Include="tools\WebStack.testing.targets" - Condition=" '$(BuildPortable)' == 'true' "> + <_VSTestDLLs Include="bin\$(Configuration)\test\NetCore\**\*.Test.dll; + bin\$(Configuration)\test\NetStandard\**\*.Test.dll" + Exclude="bin\$(Configuration)\test\Net*\net4*\*.Test.dll" /> + <_XunitProject Include="tools\WebStack.testing.targets" Condition=" '$(BuildPortable)' == 'true' "> TestAssembly=%(_VSTestDLLs.FullPath); - XmlPath=$(TestResultsDirectory)%(_VSTestDLLs.FileName)-NetCoreApp-XunitResults.xml; + XmlPath=$(TestResultsDirectory)%(_VSTestDLLs.FileName)-$([System.String]::Copy('%(_VSTestDLLs.RecursiveDir)').Trim('\\'))-XunitResults.xml; UseVSTest=true diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 820089f1c..2da1d8ad2 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -60,10 +60,16 @@ jobs: - checkout: self clean: true displayName: Checkout + - task: UseDotNet@2 displayName: Get .NET SDK inputs: useGlobalJson: true + - task: UseDotNet@2 + displayName: Get .NET 2.1 runtime + inputs: + packageType: runtime + version: '2.1.x' - script: .\build.cmd EnableSkipStrongNames displayName: Enable SkipStrongNames diff --git a/build.cmd b/build.cmd index 798507f17..500eb973a 100644 --- a/build.cmd +++ b/build.cmd @@ -2,13 +2,12 @@ pushd %~dp0 setlocal -if exist bin goto build +if exist bin goto Build mkdir bin :Build -REM Find the most recent 32bit MSBuild.exe on the system. Require v16.0 (installed with VS2019) or later. -REM Use `vswhere` for the search because it can find all VS installations. +REM Require VS2019 (v16.0) on the system. Use `vswhere` for the search because it can find all VS installations. set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" if not exist %vswhere% ( set vswhere="%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" @@ -24,28 +23,33 @@ if not exist %vswhere% ( goto BuildFail ) -REM We're fine w/ any .NET SDK newer than 2.1.500 but also need a 2.1.x runtime. Microsoft.Net.Core.Component.SDK.2.1 -REM actually checks for only the runtime these days. set InstallDir= for /f "usebackq tokens=*" %%i in (`%vswhere% -version 16 -latest -prerelease -products * ^ - -requires Microsoft.Component.MSBuild ^ - -requires Microsoft.NetCore.Component.SDK ^ - -requires Microsoft.Net.Core.Component.SDK.2.1 ^ + -requires Microsoft.Net.Component.4.5.TargetingPack ^ + -requires Microsoft.Net.Component.4.5.2.TargetingPack ^ + -requires Microsoft.Net.Component.4.6.2.TargetingPack ^ -property installationPath`) do ( set InstallDir="%%i" ) if not DEFINED InstallDir ( - echo "Could not find a VS2019 installation with the necessary components (MSBuild, .NET Core 2.1 Runtime, .NET SDK). Please install VS2019 or the missing components." -) - -if exist %InstallDir%\MSBuild\Current\Bin\MSBuild.exe ( - set MSBuild=%InstallDir%\MSBuild\Current\Bin\MSBuild.exe -) else ( - echo Could not find MSBuild.exe. Please install the VS2019 BuildTools component or a workload that includes it. + echo "Could not find a VS2019 installation with the necessary components (targeting packs for v4.5, v4.5.2, and v4.6.2)." + echo Please install VS2019 or the missing components. goto BuildFail ) +REM Find or install MSBuild. Need v17.4 due to our .NET SDK choice. +set "MSBuildVersion=17.4.1" +set "Command=[System.Threading.Thread]::CurrentThread.CurrentCulture = ''" +set "Command=%Command%; [System.Threading.Thread]::CurrentThread.CurrentUICulture = ''" +set "Command=%Command%; try { & '%~dp0eng\GetXCopyMSBuild.ps1' %MSBuildVersion%; exit $LASTEXITCODE }" +set "Command=%Command% catch { write-host $_; exit 1 }" +PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command "%Command%" +if %ERRORLEVEL% neq 0 goto BuildFail + +REM Add MSBuild to the path. +set "PATH=%CD%\.msbuild\%MSBuildVersion%\tools\MSBuild\Current\Bin\;%PATH%" + REM Configure NuGet operations to work w/in this repo i.e. do not pollute system packages folder. REM Note this causes two copies of packages restored using packages.config to land in this folder e.g. REM StyleCpy.5.0.0/ and stylecop/5.0.0/. @@ -56,13 +60,13 @@ if DEFINED CI (set Desktop=false) else if DEFINED TEAMCITY_VERSION (set Desktop= if "%1" == "" goto BuildDefaults -%MSBuild% Runtime.msbuild /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^ +MSBuild Runtime.msbuild /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^ /fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary /t:%* if %ERRORLEVEL% neq 0 goto BuildFail goto BuildSuccess :BuildDefaults -%MSBuild% Runtime.msbuild /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^ +MSBuild Runtime.msbuild /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^ /fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary if %ERRORLEVEL% neq 0 goto BuildFail goto BuildSuccess diff --git a/eng/GetXCopyMSBuild.ps1 b/eng/GetXCopyMSBuild.ps1 new file mode 100644 index 000000000..6ab853c30 --- /dev/null +++ b/eng/GetXCopyMSBuild.ps1 @@ -0,0 +1,42 @@ +# Lifted from https://github.com/dotnet/arcade/blob/main/eng/common/tools.ps1 + +[CmdletBinding(DefaultParameterSetName='Groups')] +param( + [string]$Version = '17.4.1' +) + +Set-StrictMode -Version 2 +$ErrorActionPreference = 'Stop' + +function Create-Directory ([string[]] $path) { + New-Item -Path $path -Force -ItemType 'Directory' | Out-Null +} + +function Unzip([string]$zipfile, [string]$outpath) { + Add-Type -AssemblyName System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) +} + +function InitializeXCopyMSBuild([string]$packageVersion, [bool]$install, [string]$ToolsDir) { + $packageName = 'RoslynTools.MSBuild' + $packageDir = Join-Path $ToolsDir $packageVersion + $packagePath = Join-Path $packageDir "$packageName.$packageVersion.nupkg" + + if (!(Test-Path $packageDir)) { + if (!$install) { + return $null + } + + Create-Directory $packageDir + + Write-Host "Downloading $packageName $packageVersion" + $ProgressPreference = 'SilentlyContinue' # Don't display the console progress UI - it's a huge perf hit + Invoke-WebRequest "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/flat2/$packageName/$packageVersion/$packageName.$packageVersion.nupkg" -OutFile $packagePath + + Unzip $packagePath $packageDir + } + + return Join-Path $packageDir 'tools' +} + +InitializeXCopyMSBuild -packageVersion $Version -install $true -ToolsDir (join-path $PWD .msbuild) diff --git a/global.json b/global.json index 053fd617a..0f75e8a6f 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "2.1.818", + "version": "6.0.405", "rollForward": "major" } } diff --git a/src/System.Net.Http.Formatting/Internal/TranscodingStream.cs b/src/System.Net.Http.Formatting/Internal/TranscodingStream.cs index 9d392d469..f279b73ad 100644 --- a/src/System.Net.Http.Formatting/Internal/TranscodingStream.cs +++ b/src/System.Net.Http.Formatting/Internal/TranscodingStream.cs @@ -119,7 +119,7 @@ protected override void Dispose(bool disposing) } } -#if NETCOREAPP3_1 || NET5_0_OR_GREATER || NETSTANDARD2_1 +#if NETCOREAPP3_1_OR_GREATER || NETSTANDARD2_1 public override ValueTask DisposeAsync() { if (_innerStream is null) diff --git a/test/Microsoft.TestCommon/ExceptionAssertions.cs b/test/Microsoft.TestCommon/ExceptionAssertions.cs index 5cca7e7c8..0b43f6627 100644 --- a/test/Microsoft.TestCommon/ExceptionAssertions.cs +++ b/test/Microsoft.TestCommon/ExceptionAssertions.cs @@ -297,7 +297,7 @@ public static async Task ThrowsArgumentNullAsync(FuncThrown when an exception was not thrown, or when an exception of the incorrect type is thrown public static ArgumentException ThrowsArgumentNullOrEmpty(Action testCode, string paramName) { - return Throws(testCode, "Value cannot be null or empty.\r\nParameter name: " + paramName, allowDerivedExceptions: false); + return Throws(testCode, "Value cannot be null or empty." + GetParameterMessage(paramName), allowDerivedExceptions: false); } /// @@ -327,7 +327,7 @@ public static ArgumentOutOfRangeException ThrowsArgumentOutOfRange(Action testCo { if (exceptionMessage != null) { - exceptionMessage = exceptionMessage + "\r\nParameter name: " + paramName; + exceptionMessage = exceptionMessage + GetParameterMessage(paramName); if (actualValue != null) { exceptionMessage += String.Format(CultureReplacer.DefaultCulture, "\r\nActual value was {0}.", actualValue); @@ -360,7 +360,7 @@ public static async Task ThrowsArgumentOutOfRangeAs { if (exceptionMessage != null) { - exceptionMessage = exceptionMessage + "\r\nParameter name: " + paramName; + exceptionMessage = exceptionMessage + GetParameterMessage(paramName); if (actualValue != null) { exceptionMessage += String.Format(CultureReplacer.DefaultCulture, "\r\nActual value was {0}.", actualValue); @@ -500,8 +500,8 @@ public static HttpException ThrowsHttpException(Action testCode, string exceptio public static ArgumentException ThrowsInvalidEnumArgument(Action testCode, string paramName, int invalidValue, Type enumType, bool allowDerivedExceptions = false) { string message = String.Format(CultureReplacer.DefaultCulture, - "The value of argument '{0}' ({1}) is invalid for Enum type '{2}'.{3}Parameter name: {0}", - paramName, invalidValue, enumType.Name, Environment.NewLine); + "The value of argument '{0}' ({1}) is invalid for Enum type '{2}'.{3}", + paramName, invalidValue, enumType.Name, GetParameterMessage(paramName)); #if NETFX_CORE // InvalidEnumArgumentException not available in netstandard1.3. return Throws(testCode, message, allowDerivedExceptions); @@ -581,6 +581,15 @@ public static async Task ThrowsAsync( return ex; } + private static string GetParameterMessage(string parameterName) + { +#if NETCOREAPP3_1_OR_GREATER + return " (Parameter '" + parameterName + "')"; +#else + return Environment.NewLine + "Parameter name: " + parameterName; +#endif + } + // We've re-implemented all the xUnit.net Throws code so that we can get this // updated implementation of RecordException which silently unwraps any instances // of AggregateException. In addition to unwrapping exceptions, this method ensures diff --git a/test/Microsoft.TestCommon/Microsoft.TestCommon.csproj b/test/Microsoft.TestCommon/Microsoft.TestCommon.csproj index 65c984aff..593a10e13 100644 --- a/test/Microsoft.TestCommon/Microsoft.TestCommon.csproj +++ b/test/Microsoft.TestCommon/Microsoft.TestCommon.csproj @@ -1,7 +1,7 @@  - net462;netcoreapp2.1 + net462;netcoreapp2.1;net6.0 $(Configurations);CodeAnalysis $(DefineConstants);NETFX_CORE diff --git a/test/System.Net.Http.Formatting.NetCore.Test/System.Net.Http.Formatting.NetCore.Test.csproj b/test/System.Net.Http.Formatting.NetCore.Test/System.Net.Http.Formatting.NetCore.Test.csproj index 68179da3e..1a2fc91cd 100644 --- a/test/System.Net.Http.Formatting.NetCore.Test/System.Net.Http.Formatting.NetCore.Test.csproj +++ b/test/System.Net.Http.Formatting.NetCore.Test/System.Net.Http.Formatting.NetCore.Test.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1;net462 + net462;netcoreapp2.1;net6.0 System.Net.Http ..\..\bin\$(Configuration)\Test\NetCore\ $(Configurations);CodeAnalysis diff --git a/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj b/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj index bdcc1288d..dc96f8c4c 100644 --- a/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj +++ b/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1;net462 + net462;netcoreapp2.1;net6.0 System.Net.Http ..\..\bin\$(Configuration)\Test\NetStandard\ $(Configurations);CodeAnalysis diff --git a/test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs b/test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs index 3082b265d..8b49dba47 100644 --- a/test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs +++ b/test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs @@ -330,7 +330,12 @@ public async Task FormatterThrowsOnReadWithInvalidContent() // Act & Assert await Assert.ThrowsAsync( () => formatter.ReadFromStreamAsync(variationType, stream, content, null), - "Could not convert to decimal: 7.92281625142643E+28. Path 'Value'."); +#if NETCOREAPP3_1_OR_GREATER + "Could not convert to decimal: 7.922816251426434E+28. Path 'Value'." +#else + "Could not convert to decimal: 7.92281625142643E+28. Path 'Value'." +#endif + ); } [Theory] diff --git a/test/System.Net.Http.Formatting.Test/Formatting/JsonMediaTypeFormatterTests.cs b/test/System.Net.Http.Formatting.Test/Formatting/JsonMediaTypeFormatterTests.cs index 76a497182..9b52fdf8e 100644 --- a/test/System.Net.Http.Formatting.Test/Formatting/JsonMediaTypeFormatterTests.cs +++ b/test/System.Net.Http.Formatting.Test/Formatting/JsonMediaTypeFormatterTests.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.TestCommon; +using Moq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -576,6 +577,29 @@ public override Task WriteToStreamAsync_UsesCorrectCharacterEncoding(string cont formatter, content, formattedContent, mediaType, encoding, isDefaultEncoding); } +#if NET6_0_OR_GREATER + // Cannot Mock a Stream and let JsonWriter write to it. Writer will use ReadOnlySpan in this case and such + // parameters are not currently mockable. See moq/moq4#829, moq/moq4#979, and dotnet/runtime#45152. + // Override here avoids the Mock and should confirm this Stream is not closed. Also adds an + // additional check of the written text. + [Fact] + public override async Task WriteToStreamAsync_WhenObjectIsNull_WritesDataButDoesNotCloseStream() + { + // Arrange + JsonMediaTypeFormatter formatter = CreateFormatter(); + Stream stream = new MemoryStream(); + HttpContent content = new StringContent(String.Empty); + + // Act + await formatter.WriteToStreamAsync(typeof(SampleType), null, stream, content, null); + + // Assert (stream will throw if it has been closed) + stream.Position = 0; + using var reader = new StreamReader(stream); + Assert.Equal("null", reader.ReadToEnd()); + } +#endif + public class TestJsonMediaTypeFormatter : JsonMediaTypeFormatter { public TestJsonMediaTypeFormatter() diff --git a/test/System.Net.Http.Formatting.Test/Handlers/ProgressMessageHandlerTest.cs b/test/System.Net.Http.Formatting.Test/Handlers/ProgressMessageHandlerTest.cs index 36f50cde6..0947270c3 100644 --- a/test/System.Net.Http.Formatting.Test/Handlers/ProgressMessageHandlerTest.cs +++ b/test/System.Net.Http.Formatting.Test/Handlers/ProgressMessageHandlerTest.cs @@ -56,8 +56,10 @@ public async Task SendAsync_DoesNotInsertSendProgressWithoutEntityOrHandlerPrese } [Theory] +#if !NET6_0_OR_GREATER // https://github.com/aspnet/AspNetWebStack/issues/386 [InlineData(false, false)] [InlineData(false, true)] +#endif [InlineData(true, false)] [InlineData(true, true)] public async Task SendAsync_InsertsReceiveProgressWhenResponseEntityPresent(bool insertResponseEntity, bool addReceiveProgressHandler) diff --git a/test/System.Net.Http.Formatting.Test/HttpClientExtensionsTest.cs b/test/System.Net.Http.Formatting.Test/HttpClientExtensionsTest.cs index a12ab0383..5007ff4ac 100644 --- a/test/System.Net.Http.Formatting.Test/HttpClientExtensionsTest.cs +++ b/test/System.Net.Http.Formatting.Test/HttpClientExtensionsTest.cs @@ -14,6 +14,12 @@ namespace System.Net.Http { public class HttpClientExtensionsTest { + private const string InvalidUriMessage = +#if NET6_0_OR_GREATER + "An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set."; +#else + "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."; +#endif private readonly MediaTypeFormatter _formatter = new MockMediaTypeFormatter { CallBase = true }; private readonly HttpClient _client; private readonly MediaTypeHeaderValue _mediaTypeHeader = MediaTypeHeaderValue.Parse("foo/bar; charset=utf-16"); @@ -40,7 +46,7 @@ public void PostAsJsonAsync_String_WhenClientIsNull_ThrowsException() public void PostAsJsonAsync_String_WhenUriIsNull_ThrowsException() { Assert.Throws(() => _client.PostAsJsonAsync((string)null, new object()), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -64,7 +70,7 @@ public void PostAsXmlAsync_String_WhenClientIsNull_ThrowsException() public void PostAsXmlAsync_String_WhenUriIsNull_ThrowsException() { Assert.Throws(() => _client.PostAsXmlAsync((string)null, new object()), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -88,7 +94,7 @@ public void PostAsync_String_WhenClientIsNull_ThrowsException() public void PostAsync_String_WhenRequestUriIsNull_ThrowsException() { Assert.Throws(() => _client.PostAsync((string)null, new object(), new JsonMediaTypeFormatter(), "text/json"), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -169,7 +175,7 @@ public void PutAsJsonAsync_String_WhenClientIsNull_ThrowsException() public void PutAsJsonAsync_String_WhenUriIsNull_ThrowsException() { Assert.Throws(() => _client.PutAsJsonAsync((string)null, new object()), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -193,7 +199,7 @@ public void PutAsXmlAsync_String_WhenClientIsNull_ThrowsException() public void PutAsXmlAsync_String_WhenUriIsNull_ThrowsException() { Assert.Throws(() => _client.PutAsXmlAsync((string)null, new object()), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -217,7 +223,7 @@ public void PutAsync_String_WhenClientIsNull_ThrowsException() public void PutAsync_String_WhenRequestUriIsNull_ThrowsException() { Assert.Throws(() => _client.PutAsync((string)null, new object(), new JsonMediaTypeFormatter(), "text/json"), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -298,7 +304,7 @@ public void PostAsJsonAsync_Uri_WhenClientIsNull_ThrowsException() public void PostAsJsonAsync_Uri_WhenUriIsNull_ThrowsException() { Assert.Throws(() => _client.PostAsJsonAsync((Uri)null, new object()), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -322,7 +328,7 @@ public void PostAsXmlAsync_Uri_WhenClientIsNull_ThrowsException() public void PostAsXmlAsync_Uri_WhenUriIsNull_ThrowsException() { Assert.Throws(() => _client.PostAsXmlAsync((Uri)null, new object()), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -346,7 +352,7 @@ public void PostAsync_Uri_WhenClientIsNull_ThrowsException() public void PostAsync_Uri_WhenRequestUriIsNull_ThrowsException() { Assert.Throws(() => _client.PostAsync((Uri)null, new object(), new JsonMediaTypeFormatter(), "text/json"), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -427,7 +433,7 @@ public void PutAsJsonAsync_Uri_WhenClientIsNull_ThrowsException() public void PutAsJsonAsync_Uri_WhenUriIsNull_ThrowsException() { Assert.Throws(() => _client.PutAsJsonAsync((Uri)null, new object()), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -451,7 +457,7 @@ public void PutAsXmlAsync_Uri_WhenClientIsNull_ThrowsException() public void PutAsXmlAsync_Uri_WhenUriIsNull_ThrowsException() { Assert.Throws(() => _client.PutAsXmlAsync((Uri)null, new object()), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] @@ -475,7 +481,7 @@ public void PutAsync_Uri_WhenClientIsNull_ThrowsException() public void PutAsync_Uri_WhenRequestUriIsNull_ThrowsException() { Assert.Throws(() => _client.PutAsync((Uri)null, new object(), new JsonMediaTypeFormatter(), "text/json"), - "An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); + InvalidUriMessage); } [Fact] diff --git a/test/System.Net.Http.Formatting.Test/HttpMessageContentTests.cs b/test/System.Net.Http.Formatting.Test/HttpMessageContentTests.cs index a8b41b562..f5a60b5e0 100644 --- a/test/System.Net.Http.Formatting.Test/HttpMessageContentTests.cs +++ b/test/System.Net.Http.Formatting.Test/HttpMessageContentTests.cs @@ -164,6 +164,7 @@ public async Task SerializeRequestMultipleTimes() } } +#if !NET6_0_OR_GREATER // https://github.com/aspnet/AspNetWebStack/issues/386 [Fact] public async Task SerializeResponse() { @@ -185,6 +186,7 @@ public async Task SerializeResponseMultipleTimes() await ValidateResponse(instance, false); } } +#endif [Fact] public async Task SerializeRequestWithEntity() @@ -241,6 +243,7 @@ public async Task SerializeRequestAsync() } } +#if !NET6_0_OR_GREATER // https://github.com/aspnet/AspNetWebStack/issues/386 [Fact] public async Task SerializeResponseAsync() { @@ -251,6 +254,7 @@ public async Task SerializeResponseAsync() await ValidateResponse(instance, false); } } +#endif [Fact] public async Task SerializeRequestWithPortAndQueryAsync() diff --git a/test/System.Net.Http.Formatting.Test/Internal/TranscodingStreamTests.cs b/test/System.Net.Http.Formatting.Test/Internal/TranscodingStreamTests.cs index 7d6e0a506..4e50d4381 100644 --- a/test/System.Net.Http.Formatting.Test/Internal/TranscodingStreamTests.cs +++ b/test/System.Net.Http.Formatting.Test/Internal/TranscodingStreamTests.cs @@ -174,7 +174,7 @@ public void Dispose_WithLeaveOpenFalse_DisposesInnerStream() // Async -#if NETCOREAPP3_1 || NET5_0_OR_GREATER || NETSTANDARD2_1 +#if NETCOREAPP3_1_OR_GREATER || NETSTANDARD2_1 innerStream = new MemoryStream(); transcodingStream = new TranscodingStream(innerStream, Encoding.UTF8, Encoding.UTF8, leaveOpen: false); transcodingStream.DisposeAsync().GetAwaiter().GetResult(); @@ -196,7 +196,7 @@ public void Dispose_WithLeaveOpenTrue_DoesNotDisposeInnerStream() // Async -#if NETCOREAPP3_1 || NET5_0_OR_GREATER || NETSTANDARD2_1 +#if NETCOREAPP3_1_OR_GREATER || NETSTANDARD2_1 innerStream = new MemoryStream(); transcodingStream = new TranscodingStream(innerStream, Encoding.UTF8, Encoding.UTF8, leaveOpen: true); transcodingStream.DisposeAsync().GetAwaiter().GetResult(); diff --git a/test/System.Net.Http.Formatting.Test/System.Net.Http.Formatting.Test.csproj b/test/System.Net.Http.Formatting.Test/System.Net.Http.Formatting.Test.csproj index ab9d953a1..efadbbb6a 100644 --- a/test/System.Net.Http.Formatting.Test/System.Net.Http.Formatting.Test.csproj +++ b/test/System.Net.Http.Formatting.Test/System.Net.Http.Formatting.Test.csproj @@ -20,7 +20,7 @@ ..\..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll False - False + True