Skip to content
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

Use .NET SDK 9.0.2xx for integration tests #6216

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion build/DotNetSdkTestVersions.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Each line represents arguments for the .NET SDK installer script (https://learn.microsoft.com/dotnet/core/tools/dotnet-install-script)
-Channel 9.0.1xx -Quality daily
-Channel 9.0.2xx -Quality daily
-Channel 8.0 -Runtime dotnet
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ internal CommandRunnerResult RunDotnetExpectSuccess(string workingDirectory, str
/// <param name="args">The command-line arguments to pass to dotnet.</param>
/// <param name="environmentVariables">An optional <see cref="IReadOnlyDictionary{TKey, TValue}" /> containing environment variables to use when executing the command.</param>
internal CommandRunnerResult RunDotnetExpectFailure(string workingDirectory, string args = "", IReadOnlyDictionary<string, string> environmentVariables = null, ITestOutputHelper testOutputHelper = null)
=> RunDotnet(workingDirectory, args, expectSuccess: false, environmentVariables);
=> RunDotnet(workingDirectory, args, expectSuccess: false, environmentVariables, testOutputHelper);

private CommandRunnerResult RunDotnet(string workingDirectory, string args = "", bool expectSuccess = true, IReadOnlyDictionary<string, string> environmentVariables = null, ITestOutputHelper testOutputHelper = null)
{
Expand Down
113 changes: 54 additions & 59 deletions test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetWhyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NuGet.Test.Utility;
using NuGet.XPlat.FuncTest;
using Xunit;
using Xunit.Abstractions;

namespace Dotnet.Integration.Test
{
Expand All @@ -18,39 +19,40 @@ public class DotnetWhyTests
private static readonly string ProjectName = "Test.Project.DotnetNugetWhy";

private readonly DotnetIntegrationTestFixture _testFixture;
private readonly ITestOutputHelper _testOutputHelper;

public DotnetWhyTests(DotnetIntegrationTestFixture testFixture)
public DotnetWhyTests(DotnetIntegrationTestFixture testFixture, ITestOutputHelper testOutputHelper)
{
_testFixture = testFixture;
_testOutputHelper = testOutputHelper;
}

[Fact]
public async Task WhyCommand_ProjectHasTransitiveDependency_DependencyPathExists()
{
// Arrange
var pathContext = new SimpleTestPathContext();
var projectFramework = "net7.0";
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, projectFramework);
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, Constants.ProjectTargetFramework);

var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", projectFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", projectFramework);
var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", Constants.ProjectTargetFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", Constants.ProjectTargetFramework);

packageX.Dependencies.Add(packageY);

project.AddPackageToFramework(projectFramework, packageX);
project.AddPackageToFramework(Constants.ProjectTargetFramework, packageX);

await SimpleTestPackageUtility.CreatePackagesAsync(
pathContext.PackageSource,
packageX,
packageY);

string addPackageCommandArgs = $"add {project.ProjectPath} package {packageX.Id}";
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs);
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs, testOutputHelper: _testOutputHelper);

string whyCommandArgs = $"nuget why {project.ProjectPath} {packageY.Id}";

// Act
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
Assert.Equal(ExitCodes.Success, result.ExitCode);
Expand All @@ -62,26 +64,25 @@ public async Task WhyCommand_ProjectHasNoDependencyOnTargetPackage_PathDoesNotEx
{
// Arrange
var pathContext = new SimpleTestPathContext();
var projectFramework = "net7.0";
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, projectFramework);
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, Constants.ProjectTargetFramework);

var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", projectFramework);
project.AddPackageToFramework(projectFramework, packageX);
var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", Constants.ProjectTargetFramework);
project.AddPackageToFramework(Constants.ProjectTargetFramework, packageX);

var packageZ = XPlatTestUtils.CreatePackage("PackageZ", "1.0.0", projectFramework);
var packageZ = XPlatTestUtils.CreatePackage("PackageZ", "1.0.0", Constants.ProjectTargetFramework);

await SimpleTestPackageUtility.CreatePackagesAsync(
pathContext.PackageSource,
packageX,
packageZ);

string addPackageCommandArgs = $"add {project.ProjectPath} package {packageX.Id}";
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs);
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs, testOutputHelper: _testOutputHelper);

string whyCommandArgs = $"nuget why {project.ProjectPath} {packageZ.Id}";

// Act
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
Assert.Equal(ExitCodes.Success, result.ExitCode);
Expand All @@ -93,28 +94,27 @@ public async Task WhyCommand_WithFrameworksOption_OptionParsedSuccessfully()
{
// Arrange
var pathContext = new SimpleTestPathContext();
var projectFramework = "net7.0";
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, projectFramework);
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, Constants.ProjectTargetFramework);

var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", projectFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", projectFramework);
var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", Constants.ProjectTargetFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", Constants.ProjectTargetFramework);

packageX.Dependencies.Add(packageY);

project.AddPackageToFramework(projectFramework, packageX);
project.AddPackageToFramework(Constants.ProjectTargetFramework, packageX);

await SimpleTestPackageUtility.CreatePackagesAsync(
pathContext.PackageSource,
packageX,
packageY);

string addPackageCommandArgs = $"add {project.ProjectPath} package {packageX.Id}";
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs);
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs, testOutputHelper: _testOutputHelper);

string whyCommandArgs = $"nuget why {project.ProjectPath} {packageY.Id} --framework {projectFramework}";
string whyCommandArgs = $"nuget why {project.ProjectPath} {packageY.Id} --framework {Constants.ProjectTargetFramework}";

// Act
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
Assert.Equal(ExitCodes.Success, result.ExitCode);
Expand All @@ -126,28 +126,27 @@ public async Task WhyCommand_WithFrameworksOptionAlias_OptionParsedSuccessfully(
{
// Arrange
var pathContext = new SimpleTestPathContext();
var projectFramework = "net7.0";
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, projectFramework);
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, Constants.ProjectTargetFramework);

var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", projectFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", projectFramework);
var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", Constants.ProjectTargetFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", Constants.ProjectTargetFramework);

packageX.Dependencies.Add(packageY);

project.AddPackageToFramework(projectFramework, packageX);
project.AddPackageToFramework(Constants.ProjectTargetFramework, packageX);

await SimpleTestPackageUtility.CreatePackagesAsync(
pathContext.PackageSource,
packageX,
packageY);

string addPackageCommandArgs = $"add {project.ProjectPath} package {packageX.Id}";
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs);
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs, testOutputHelper: _testOutputHelper);

string whyCommandArgs = $"nuget why {project.ProjectPath} {packageY.Id} -f {projectFramework}";
string whyCommandArgs = $"nuget why {project.ProjectPath} {packageY.Id} -f {Constants.ProjectTargetFramework}";

// Act
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
Assert.Equal(ExitCodes.Success, result.ExitCode);
Expand All @@ -163,25 +162,24 @@ public void WhyCommand_EmptyProjectArgument_Fails()
string whyCommandArgs = $"nuget why";

// Act
CommandRunnerResult result = _testFixture.RunDotnetExpectFailure(pathContext.SolutionRoot, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectFailure(pathContext.SolutionRoot, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
Assert.Equal(ExitCodes.InvalidArguments, result.ExitCode);
Assert.Contains($"Required argument missing for command: 'why'.", result.Errors);
}

[Fact]
[Fact(Skip = "https://github.com/NuGet/Home/issues/14030")]
public void WhyCommand_EmptyPackageArgument_Fails()
{
// Arrange
var pathContext = new SimpleTestPathContext();
var projectFramework = "net7.0";
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, projectFramework);
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, Constants.ProjectTargetFramework);

string whyCommandArgs = $"nuget why {project.ProjectPath}";

// Act
CommandRunnerResult result = _testFixture.RunDotnetExpectFailure(pathContext.SolutionRoot, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectFailure(pathContext.SolutionRoot, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
Assert.Equal(ExitCodes.InvalidArguments, result.ExitCode);
Expand All @@ -193,29 +191,28 @@ public async Task WhyCommand_InvalidFrameworksOption_WarnsCorrectly()
{
// Arrange
var pathContext = new SimpleTestPathContext();
var projectFramework = "net7.0";
var inputFrameworksOption = "invalidFrameworkAlias";
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, projectFramework);
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, Constants.ProjectTargetFramework);

var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", projectFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", projectFramework);
var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", Constants.ProjectTargetFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", Constants.ProjectTargetFramework);

packageX.Dependencies.Add(packageY);

project.AddPackageToFramework(projectFramework, packageX);
project.AddPackageToFramework(Constants.ProjectTargetFramework, packageX);

await SimpleTestPackageUtility.CreatePackagesAsync(
pathContext.PackageSource,
packageX,
packageY);

string addPackageCommandArgs = $"add {project.ProjectPath} package {packageX.Id}";
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs);
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs, testOutputHelper: _testOutputHelper);

string whyCommandArgs = $"nuget why {project.ProjectPath} {packageY.Id} -f {inputFrameworksOption} -f {projectFramework}";
string whyCommandArgs = $"nuget why {project.ProjectPath} {packageY.Id} -f {inputFrameworksOption} -f {Constants.ProjectTargetFramework}";

// Act
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
Assert.Equal(ExitCodes.Success, result.ExitCode);
Expand All @@ -228,29 +225,28 @@ public async Task WhyCommand_DirectoryWithProject_HasTransitiveDependency_Depend
{
// Arrange
var pathContext = new SimpleTestPathContext();
var projectFramework = "net7.0";
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, projectFramework);
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, Constants.ProjectTargetFramework);

var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", projectFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", projectFramework);
var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", Constants.ProjectTargetFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", Constants.ProjectTargetFramework);

packageX.Dependencies.Add(packageY);

project.AddPackageToFramework(projectFramework, packageX);
project.AddPackageToFramework(Constants.ProjectTargetFramework, packageX);

await SimpleTestPackageUtility.CreatePackagesAsync(
pathContext.PackageSource,
packageX,
packageY);

string addPackageCommandArgs = $"add {project.ProjectPath} package {packageX.Id}";
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs);
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs, testOutputHelper: _testOutputHelper);

var projectDirectory = Path.GetDirectoryName(project.ProjectPath);
string whyCommandArgs = $"nuget why {projectDirectory} {packageY.Id}";

// Act
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
Assert.Equal(ExitCodes.Success, result.ExitCode);
Expand All @@ -262,29 +258,28 @@ public async Task WhyCommand_AssetsFileWithoutProject_Succeeds()
{
// Arrange
var pathContext = new SimpleTestPathContext();
var projectFramework = "net7.0";
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, projectFramework);
var project = XPlatTestUtils.CreateProject(ProjectName, pathContext, Constants.ProjectTargetFramework);

var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", projectFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", projectFramework);
var packageX = XPlatTestUtils.CreatePackage("PackageX", "1.0.0", Constants.ProjectTargetFramework);
var packageY = XPlatTestUtils.CreatePackage("PackageY", "1.0.1", Constants.ProjectTargetFramework);

packageX.Dependencies.Add(packageY);

project.AddPackageToFramework(projectFramework, packageX);
project.AddPackageToFramework(Constants.ProjectTargetFramework, packageX);

await SimpleTestPackageUtility.CreatePackagesAsync(
pathContext.PackageSource,
packageX,
packageY);

string addPackageCommandArgs = $"add {project.ProjectPath} package {packageX.Id}";
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs);
CommandRunnerResult addPackageResult = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, addPackageCommandArgs, testOutputHelper: _testOutputHelper);

var assetsFile = Path.Combine(Path.GetDirectoryName(project.ProjectPath), "obj", "project.assets.json");

// Act
string whyCommandArgs = $"nuget why {assetsFile} {packageY.Id}";
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectSuccess(pathContext.SolutionRoot, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
result.AllOutput.Should().Contain(packageX.Id);
Expand All @@ -300,7 +295,7 @@ public void WhyCommand_EmptyJsonFile_OutputsError()

// Act
string whyCommandArgs = $"nuget why {jsonFilePath} packageId";
CommandRunnerResult result = _testFixture.RunDotnetExpectFailure(testDirectory, whyCommandArgs);
CommandRunnerResult result = _testFixture.RunDotnetExpectFailure(testDirectory, whyCommandArgs, testOutputHelper: _testOutputHelper);

// Assert
result.AllOutput.Should().Contain("https://aka.ms/dotnet/nuget/why");
Expand Down
Loading