Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ public async Task RestoreNetCore_SetProjectStyleWithProperty_ProjectJsonAsync()
'x': '1.0.0'
},
'frameworks': {
'net45': { }
'net45': { }
}
}");

Expand Down Expand Up @@ -5728,7 +5728,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
configuration.Add(disabledPackageSources);
File.WriteAllText(configPath, doc.ToString());

// Act
// Act
var r2 = Util.RestoreSolution(pathContext);

// Assert
Expand Down Expand Up @@ -5817,7 +5817,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(

File.WriteAllText(configPath2, doc2.ToString());

// Act
// Act
var r2 = Util.RestoreSolution(pathContext);

// Assert
Expand Down Expand Up @@ -6484,7 +6484,7 @@ public async Task RestoreNetCore_NoOp_EnableRestorePackagesWithLockFile_BySetPro
// Related issue: https://github.com/NuGet/Home/issues/7807
// First senario : Enable RestorePackagesWithLockFile by only setting property.
// First restore should fail the No-op, generate the package lock file. After deleting the package lock file, run the second restore.
// The second restore should fail the No-op, and generate the package lock file.
// The second restore should fail the No-op, and generate the package lock file.

// Arrange
using (var pathContext = new SimpleTestPathContext())
Expand Down Expand Up @@ -6521,7 +6521,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
var packageLockFileName = project.NuGetLockFileOutputPath;
var noOpFailedMsg = "The lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore.";

// Act
// Act
var result1 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed");

// Assert
Expand Down Expand Up @@ -6588,7 +6588,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
var noOpFailedMsg = "The lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore.";
var noOpSucceedMsg = "No-Op restore. The cache will not be updated.";

// Act
// Act
var result1 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed");

// Assert
Expand All @@ -6613,7 +6613,7 @@ public async Task RestoreNetCore_NoOp_EnableRestorePackagesWithLockFile_ByAddLoc
// Related issue: https://github.com/NuGet/Home/issues/7807
// Second senario : Enable RestorePackagesWithLockFile by only adding a lock file.
// First restore should fail the No-op, regenerate the package lock file. After deleting the package lock file, run the second restore.
// The second restore: since there is no property set and no lock file exists, no lockfile will be generated. And no-op succeed.
// The second restore: since there is no property set and no lock file exists, no lockfile will be generated. And no-op succeed.

// Arrange
using (var pathContext = new SimpleTestPathContext())
Expand Down Expand Up @@ -7904,7 +7904,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
public void RestoreNetCore_PackagesLockFile_ProjectReferenceChange_UpdatesLockFile()
{
// Arrange
// A -> B -> C and
// A -> B -> C and
// A -> B, A -> C
// should have different lock files
using (var pathContext = new SimpleTestPathContext())
Expand Down Expand Up @@ -8274,7 +8274,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
// Act
var result = Util.RestoreSolution(pathContext);

// Assert
// Assert
result.Success.Should().BeTrue();
Assert.True(File.Exists(projectA.AssetsFileOutputPath));
Assert.True(File.Exists(projectB.AssetsFileOutputPath));
Expand Down Expand Up @@ -8840,12 +8840,11 @@ public void RestoreNetCore_PackagesLockFile_WithDependentProjectChangeOfNotCompa
{
// Set up solution, project, and packages
var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot);
var netcoreapp20 = mainProjectFramework;

var projectA = SimpleTestProjectContext.CreateNETCore(
"a",
pathContext.SolutionRoot,
NuGetFramework.Parse(netcoreapp20));
NuGetFramework.Parse(mainProjectFramework));

projectA.Properties.Add("RestorePackagesWithLockFile", "true");

Expand Down Expand Up @@ -8897,12 +8896,11 @@ public void RestoreNetCore_PackagesLockFile_WithDependentProjectChangeOfCompatib
{
// Set up solution, project, and packages
var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot);
var netcoreapp20 = mainProjectFramework;

var projectA = SimpleTestProjectContext.CreateNETCore(
"a",
pathContext.SolutionRoot,
NuGetFramework.Parse(netcoreapp20));
NuGetFramework.Parse(mainProjectFramework));

projectA.Properties.Add("RestorePackagesWithLockFile", "true");

Expand Down Expand Up @@ -9123,14 +9121,14 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
Assert.True(File.Exists(projectA.AssetsFileOutputPath));
Assert.True(File.Exists(projectA.NuGetLockFileOutputPath));
Assert.Equal(expectedVersion, projectA.AssetsFile.Libraries.Single().Version.ToString());
// Set-up again.
// Set-up again.
projectA.Properties.Add("RestoreLockedMode", "true");
projectA.Save();

// Act
result = Util.RestoreSolution(pathContext);

// Assert
// Assert
result.Success.Should().BeTrue();
Assert.True(File.Exists(projectA.AssetsFileOutputPath));
Assert.True(File.Exists(projectA.NuGetLockFileOutputPath));
Expand Down Expand Up @@ -9337,7 +9335,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(

Assert.True(File.Exists(projectA.NuGetLockFileOutputPath));

// Update the transitive dependency in cpvm
// Update the transitive dependency in cpvm
cpvmFile.UpdatePackageVersion("y", "2.0.0");
cpvmFile.Save();

Expand Down Expand Up @@ -9667,8 +9665,8 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
/// Project A -> PackageX 100
/// -> PackageY 200 -> PackageX 200
/// -> ProjectB -> ProjectC -> PackageX 100
/// All projects CPVM enabled; PackageX 100 and PackageY 200 in cpvm file
/// Expected NU1605
/// All projects CPVM enabled; PackageX 100 and PackageY 200 in cpvm file
/// Expected NU1605
/// </summary>
[Fact]
public async Task RestoreNetCore_CPVMProject_DowngradedByCentralDirectDependencyWithP2P_IsWarningNU1605()
Expand Down Expand Up @@ -9759,16 +9757,16 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(

/// <summary>
/// A more complex graph with linked central transitive dependecies
///
///
/// A -> B 1.0.0 -> C 1.0.0 -> D 1.0.0 -> E 1.0.0
/// -> P 2.0.0
/// -> P 2.0.0
/// -> F 1.0.0 -> C 2.0.0 -> H 2.0.0 -> M 2.0.0 -> N 2.0.0
/// -> G 1.0.0 -> H 1.0.0 -> D 1.0.0
/// -> X 1.0.0 -> Y 1.0.0 -> Z 1.0.0
/// -> T 1.0.0
/// -> U 1.0.0 -> V 1.0.0
/// -> O 1.0.0 -> R 1.0.0 -> S 1.0.0 -> SS 1.0.0
///
///
/// D has version defined centrally 2.0.0
/// E has version defined centrally 3.0.0
/// M has version defined centrally 2.0.0
Expand All @@ -9777,7 +9775,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
/// T has version defined centrally 3.0.0
/// R has version defined centrally 3.0.0
/// S has version defined centrally 3.0.0
///
///
/// D 2.0.0 -> I 2.0.0 -> E 2.0.0
/// M 2.0.0 -> N 2.0.0
/// P 3.0.0 -> H 3.0.0
Expand All @@ -9787,15 +9785,15 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
/// T 3.0.0 -> W 3.0.0
/// -> C 1.0.0
/// S 3.0.0 -> SS 3.0.0
///
///
/// D will be rejected (because its parents C 1.0.0, H 1.0.0 are rejected)
/// E will be rejected (because its parent D was rejected)
/// M will be rejected (because its parent lost the dispute with H 3.0.0)
/// T will be rejected (because its parent lost the dispute with Y 3.0.0)
/// Z will be rejected (because its parent lost the dispute with Y 3.0.0)
///
///
/// P will be accepted (because its parent B is Accepted)
/// S will be accepted (because its parent O 300 is Accepted)
/// S will be accepted (because its parent O 300 is Accepted)
/// </summary>
[Fact]
public async Task RestoreNetCore_CPVMProject_MultipleLinkedCentralTransitiveDepenencies()
Expand Down Expand Up @@ -9831,7 +9829,7 @@ SimpleTestPackageContext createTestPackage(string name, string version, List<Sim
NuGetFramework.Parse("netcoreapp2.0"));
projectA.Properties.Add("ManagePackageVersionsCentrally", "true");

// the package references defined in the project should not have version
// the package references defined in the project should not have version
var packageBNoVersion = createTestPackage("B", null, packagesForProject);
var packageFNoVersion = createTestPackage("F", null, packagesForProject);
var packageGNoVersion = createTestPackage("G", null, packagesForProject);
Expand Down
44 changes: 24 additions & 20 deletions test/NuGet.Clients.Tests/NuGet.CommandLine.Test/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
using NuGet.Versioning;
using Xunit;

using PackageDependency_V2 = NuGet.PackageDependency;
using PackageDependency_V3 = NuGet.Packaging.Core.PackageDependency;

namespace NuGet.CommandLine.Test
{
public static class Util
Expand Down Expand Up @@ -53,9 +56,10 @@ public static CommandRunnerResult RestoreSolution(SimpleTestPathContext pathCont
/// </summary>
public static CommandRunnerResult Restore(SimpleTestPathContext pathContext, string inputPath, int expectedExitCode = 0, params string[] additionalArgs)
{
var nugetexe = GetNuGetExePath();
var nugetExe = GetNuGetExePath();

var args = new string[] {
var args = new string[]
{
"restore",
inputPath,
"-Verbosity",
Expand All @@ -64,7 +68,7 @@ public static CommandRunnerResult Restore(SimpleTestPathContext pathContext, str

args = args.Concat(additionalArgs).ToArray();

return RunCommand(pathContext, nugetexe, expectedExitCode, args);
return RunCommand(pathContext, nugetExe, expectedExitCode, args);
}

public static CommandRunnerResult RunCommand(SimpleTestPathContext pathContext, string nugetExe, int expectedExitCode = 0, params string[] arguments)
Expand Down Expand Up @@ -100,10 +104,9 @@ public static string CreateTestPackage(
string dependencyPackageId,
string dependencyPackageVersion)
{
var group = new PackageDependencyGroup(NuGetFramework.AnyFramework,
new List<Packaging.Core.PackageDependency>()
var group = new PackageDependencyGroup(NuGetFramework.AnyFramework, new List<PackageDependency_V3>()
{
new Packaging.Core.PackageDependency(dependencyPackageId, VersionRange.Parse(dependencyPackageVersion))
new PackageDependency_V3(dependencyPackageId, VersionRange.Parse(dependencyPackageVersion))
});

return CreateTestPackage(packageId, version, path,
Expand Down Expand Up @@ -146,7 +149,7 @@ public static string CreateTestPackage(
var set = new PackageDependencySet(
null,
group.Packages.Select(package =>
new PackageDependency(package.Id,
new PackageDependency_V2(package.Id,
VersionUtility.ParseVersionSpec(package.VersionRange.ToNormalizedString()))));

packageBuilder.DependencySets.Add(set);
Expand Down Expand Up @@ -481,22 +484,23 @@ public static MockServer CreateMockServer(IList<IPackage> packages)
/// </summary>
public static string GetNuGetExePath()
{
return _nuGetExePath.Value;
}

private static readonly Lazy<string> _nuGetExePath = new Lazy<string>(GetNuGetExePathCore);

private static string GetNuGetExePathCore()
{
const string fileName = "NuGet.exe";
var targetDir = ConfigurationManager.AppSettings["TestTargetDir"] ?? Directory.GetCurrentDirectory();
var nugetexe = Path.Combine(targetDir, "NuGet", "NuGet.exe");
return nugetexe;
var nugetExe = Path.Combine(targetDir, "NuGet", fileName);
// Revert to parent dir if not found under layout dir.
if (!File.Exists(nugetExe)) nugetExe = Path.Combine(targetDir, fileName);
if (!File.Exists(nugetExe)) throw new FileNotFoundException($"The NuGet executable is not present in '{targetDir}'", fileName);
return nugetExe;
}

public static string GetTestablePluginPath()
{
const string fileName = "CredentialProvider.Testable.exe";
var targetDir = ConfigurationManager.AppSettings["TestTargetDir"] ?? Directory.GetCurrentDirectory();
var plugin = Path.Combine(targetDir, "TestableCredentialProvider", "CredentialProvider.Testable.exe");
var plugin = Path.Combine(targetDir, "TestableCredentialProvider", fileName);
// Revert to parent dir if not found under layout dir.
if (!File.Exists(plugin)) plugin = Path.Combine(targetDir, fileName);
if (!File.Exists(plugin)) throw new FileNotFoundException($"The CredentialProvider executable is not present in '{targetDir}'", fileName);
return plugin;
}

Expand Down Expand Up @@ -857,7 +861,7 @@ public static void VerifyResultSuccess(CommandRunnerResult result, string expect

/// <summary>
/// Utility for asserting faulty executions of nuget.exe
///
///
/// Asserts a non-zero status code and a message on stderr.
/// </summary>
/// <param name="result">An instance of <see cref="CommandRunnerResult"/> with command execution results</param>
Expand Down Expand Up @@ -1059,10 +1063,10 @@ public static string GetCSProjXML(string projectName)

public static void ClearWebCache()
{
var nugetexe = Util.GetNuGetExePath();
var nugetExe = Util.GetNuGetExePath();

var r = CommandRunner.Run(
nugetexe,
nugetExe,
".",
"locals http-cache -Clear",
waitForExit: true);
Expand Down
Loading