Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Dec 12, 2024
1 parent d698659 commit f394370
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,60 @@ namespace NuGet.Commands.FuncTest
{
public partial class RestoreCommandTests
{
[Fact]
// Project 1 -> a 1.0.0 -> b 1.0.0
// -> b 2.0.0
// Does not install b 1.0.0 since it is eclipsed by a direct package reference
public async Task RestoreCommand_WithDirectDependency_DoesNotDownloadOtherVersions()
{
// Arrange
using var pathContext = new SimpleTestPathContext();
await SimpleTestPackageUtility.CreateFolderFeedV3Async(
pathContext.PackageSource,
PackageSaveMode.Defaultv3,
new SimpleTestPackageContext("a", "1.0.0")
{
Dependencies =
[
new SimpleTestPackageContext("b", "1.0.0"),
]
},
new SimpleTestPackageContext("b", "2.0.0"));

var project1spec = ProjectTestHelpers.GetPackageSpecWithProjectNameAndSpec(
"Project1",
pathContext.SolutionRoot,
@"
{
""frameworks"": {
""net472"": {
""dependencies"": {
""a"": ""1.0.0"",
""b"": ""2.0.0""
}
}
}
}");

// Act & Assert
(var result, _) = await ValidateRestoreAlgorithmEquivalency(pathContext, project1spec);

// Additional assert
result.Success.Should().BeTrue();
result.LockFile.Targets.Should().HaveCount(1);
result.LockFile.Targets[0].Libraries.Should().HaveCount(2);
result.LockFile.Targets[0].Libraries[0].Name.Should().Be("a");
result.LockFile.Targets[0].Libraries[0].Version.Should().Be(new NuGetVersion("1.0.0"));

result.LockFile.Targets[0].Libraries[1].Name.Should().Be("b");
result.LockFile.Targets[0].Libraries[1].Version.Should().Be(new NuGetVersion("2.0.0"));

result.RestoreGraphs.Should().HaveCount(1);
result.RestoreGraphs.First().Install.Should().HaveCount(2);

string.Join(" ", result.RestoreGraphs.First().Install.Select(i => $"{i.Library.Name}/{i.Library.Version}")).Should().Be("a/1.0.0 b/2.0.0");
}

[Fact]
// Project 1 -> a 1.0.0 -> b 1.0.0
// -> c 1.0.0 -> b 2.0.0
Expand Down

0 comments on commit f394370

Please sign in to comment.