-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle no nomination info in VS GetInstalledPackagesAsync API (#3959)
- Loading branch information
Showing
6 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...t.Clients/NuGet.PackageManagement.VisualStudio/Exceptions/ProjectNotNominatedException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace NuGet.PackageManagement.VisualStudio.Exceptions | ||
{ | ||
[Serializable] | ||
public class ProjectNotNominatedException : InvalidOperationException | ||
{ | ||
public ProjectNotNominatedException() : base() | ||
{ | ||
} | ||
|
||
public ProjectNotNominatedException(string message) | ||
: base(message) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ts.Tests/NuGet.VisualStudio.Implementation.Test/Extensibility/NuGetProjectServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Moq; | ||
using NuGet.Configuration; | ||
using NuGet.PackageManagement.VisualStudio; | ||
using NuGet.PackageManagement.VisualStudio.Exceptions; | ||
using NuGet.ProjectManagement; | ||
using NuGet.ProjectManagement.Projects; | ||
using NuGet.VisualStudio.Contracts; | ||
using NuGet.VisualStudio.Implementation.Extensibility; | ||
using NuGet.VisualStudio.Telemetry; | ||
using Xunit; | ||
|
||
namespace NuGet.VisualStudio.Implementation.Test.Extensibility | ||
{ | ||
public class NuGetProjectServiceTests | ||
{ | ||
[Fact] | ||
public async Task GetInstalledPackagesAsync_CpsProjectNotNominated_ReturnsProjectNotReadyResult() | ||
{ | ||
// Arrange | ||
var projectGuid = Guid.NewGuid(); | ||
|
||
var settings = new Mock<ISettings>(); | ||
var telemetryProvider = new Mock<INuGetTelemetryProvider>(MockBehavior.Strict); | ||
|
||
var project = new Mock<BuildIntegratedNuGetProject>(); | ||
project.Setup(p => p.GetPackageSpecsAndAdditionalMessagesAsync(It.IsAny<DependencyGraphCacheContext>())) | ||
.Throws<ProjectNotNominatedException>(); | ||
|
||
var solutionManager = new Mock<IVsSolutionManager>(); | ||
solutionManager.Setup(sm => sm.GetNuGetProjectAsync(projectGuid.ToString())) | ||
.Returns(() => Task.FromResult<NuGetProject>(project.Object)); | ||
|
||
// Act | ||
var target = new NuGetProjectService(solutionManager.Object, settings.Object, telemetryProvider.Object); | ||
InstalledPackagesResult actual = await target.GetInstalledPackagesAsync(projectGuid, CancellationToken.None); | ||
|
||
// Assert | ||
Assert.NotNull(actual); | ||
Assert.Equal(InstalledPackageResultStatus.ProjectNotReady, actual.Status); | ||
} | ||
} | ||
} |