-
Notifications
You must be signed in to change notification settings - Fork 351
Test Formatting assemblies w/ net6.0
#384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "2.1.818", | ||
"version": "6.0.405", | ||
"rollForward": "major" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<Stream> and should confirm this Stream is not closed. Also adds an | ||
// additional check of the written text. | ||
Comment on lines
+581
to
+584
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stephentoub this relates to one of our email conversations. Thanks for your pointer to dotnet/runtime#45152 and helping me understand what's happening. Thoughts from all reviewers much appreciated: Should I simply replace MediaTypeFormatterTestBase.WriteToStreamAsync_WhenObjectIsNull_WritesDataButDoesNotCloseStream along these lines❔ Would need a |
||
[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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MattGal this is pretty much what you suggested in dotnet/arcade#12402. Incorporating it in build.cmd was the only bit I added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.