-
Notifications
You must be signed in to change notification settings - Fork 731
Move Utf8JsonStreamReader & extensions to NuGet Shared #6834
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
base: dev
Are you sure you want to change the base?
Conversation
src/NuGet.Core/NuGet.ProjectModel/LockFile/Utf8JsonStreamLockFileConverter.cs
Outdated
Show resolved
Hide resolved
...Get.Clients/NuGet.PackageManagement.VisualStudio/NuGet.PackageManagement.VisualStudio.csproj
Outdated
Show resolved
Hide resolved
} | ||
|
||
internal bool ReadNextTokenAsBoolOrThrowAnException(byte[] propertyName) | ||
internal bool ReadNextTokenAsBoolOrThrowAnException(byte[] propertyName, string invalidAttributeString) |
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.
I know that you are simply moving the file to NuGet Shared in this PR, but out of curiosity, I am wondering why this method only throws an error when reading the boolean value from the JSON object and the other methods don't. When I checked the callers of this method, they are not handling the exception as a special case. That makes me think: do we really need this method? Can we simply call the ReadNextTokenAsBoolOrFalse
method instead and delete this method?
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.
It's a good point. I see that it was discussed in the PR introducing it and the decision was to rename it to be distinct from ReadNextTokenAsBoolOrFalse
.
I agree it's unclear why this is important, but there are 2 tests explicitly checking for an exception. Therefore, this could be a behavior change which I don't want to take on in this refactoring. See:
Lines 1737 to 1790 in 32dcbfb
public async Task GetPackageSpec_WithInvalidSdkAnalysisLevel_ThrowsAnException() | |
{ | |
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); | |
// Arrange | |
using var testDirectory = TestDirectory.Create(); | |
var projectBuildProperties = new Mock<IVsProjectBuildProperties>(); | |
projectBuildProperties.Setup(b => b.GetPropertyValue(ProjectBuildProperties.SdkAnalysisLevel)) | |
.Returns("9.ainvlaid"); | |
var projectAdapter = CreateProjectAdapter(testDirectory, projectBuildProperties); | |
Mock<IVsProjectAdapter> projectAdapterMock = Mock.Get(projectAdapter); | |
var projectServices = new TestProjectSystemServices(); | |
var testProject = new LegacyPackageReferenceProject( | |
projectAdapter, | |
Guid.NewGuid().ToString(), | |
projectServices, | |
_threadingService); | |
var settings = NullSettings.Instance; | |
var testDependencyGraphCacheContext = new DependencyGraphCacheContext(NullLogger.Instance, settings); | |
// Act & Assert | |
await Assert.ThrowsAsync<ArgumentException>(async () => await testProject.GetPackageSpecsAsync(testDependencyGraphCacheContext)); | |
} | |
[Fact] | |
public async Task GetPackageSpec_WithInvalidUsingMicrosoftNetSdk_ThrowsAnException() | |
{ | |
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); | |
// Arrange | |
using var testDirectory = TestDirectory.Create(); | |
var projectBuildProperties = new Mock<IVsProjectBuildProperties>(); | |
projectBuildProperties.Setup(b => b.GetPropertyValue(ProjectBuildProperties.UsingMicrosoftNETSdk)) | |
.Returns("falsetrue"); | |
var projectAdapter = CreateProjectAdapter(testDirectory, projectBuildProperties); | |
Mock<IVsProjectAdapter> projectAdapterMock = Mock.Get(projectAdapter); | |
var projectServices = new TestProjectSystemServices(); | |
var testProject = new LegacyPackageReferenceProject( | |
projectAdapter, | |
Guid.NewGuid().ToString(), | |
projectServices, | |
_threadingService); | |
var settings = NullSettings.Instance; | |
var testDependencyGraphCacheContext = new DependencyGraphCacheContext(NullLogger.Instance, settings); | |
// Act & Assert | |
await Assert.ThrowsAsync<ArgumentException>(async () => await testProject.GetPackageSpecsAsync(testDependencyGraphCacheContext)); | |
} |
c453148
to
0edef0c
Compare
Bug
Fixes: NuGet/Home#14579
Description
Moves the Utf8Json helper classes into NuGet Shared.
PR Checklist
Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.