From 2612e779a4f28d46c5d5ca8298d2780bf2526c2b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Jun 2025 17:48:20 +0000 Subject: [PATCH 1/2] Fix dotnet package remove command to default to current directory Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com> --- .../Package/Remove/PackageRemoveCommand.cs | 2 +- .../Remove/GivenDotnetPackageRemove.cs | 90 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetPackageRemove.cs diff --git a/src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs b/src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs index 61ddc6c522a0..a702e173a5d8 100644 --- a/src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs +++ b/src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs @@ -25,7 +25,7 @@ public PackageRemoveCommand( _arguments = parseResult.GetValue(PackageRemoveCommandParser.CmdPackageArgument).ToList().AsReadOnly(); if (_fileOrDirectory == null) { - throw new ArgumentNullException(nameof(_fileOrDirectory)); + _fileOrDirectory = Environment.CurrentDirectory; } if (_arguments.Count != 1) { diff --git a/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetPackageRemove.cs b/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetPackageRemove.cs new file mode 100644 index 000000000000..57d888aded3e --- /dev/null +++ b/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetPackageRemove.cs @@ -0,0 +1,90 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.DotNet.Cli.Utils; + +namespace Microsoft.DotNet.Cli.Package.Remove.Tests +{ + public class GivenDotnetPackageRemove : SdkTest + { + public GivenDotnetPackageRemove(ITestOutputHelper log) : base(log) + { + } + + [Fact] + public void WhenPackageIsRemovedWithoutProjectArgument() + { + var projectDirectory = _testAssetsManager + .CopyTestAsset("TestAppSimple") + .WithSource().Path; + + var packageName = "Newtonsoft.Json"; + var add = new DotnetCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("add", "package", packageName); + add.Should().Pass(); + + // Test the new 'dotnet package remove' command without specifying project + var remove = new DotnetCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("package", "remove", packageName); + + remove.Should().Pass(); + remove.StdOut.Should().Contain($"Removing PackageReference for package '{packageName}' from project 'TestAppSimple.csproj'."); + remove.StdErr.Should().BeEmpty(); + } + + [Fact] + public void WhenPackageIsRemovedWithProjectOption() + { + var projectDirectory = _testAssetsManager + .CopyTestAsset("TestAppSimple") + .WithSource().Path; + + var packageName = "Newtonsoft.Json"; + var add = new DotnetCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("add", "package", packageName); + add.Should().Pass(); + + // Test the new 'dotnet package remove' command with --project option + var remove = new DotnetCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("package", "remove", packageName, "--project", "TestAppSimple.csproj"); + + remove.Should().Pass(); + remove.StdOut.Should().Contain($"Removing PackageReference for package '{packageName}' from project 'TestAppSimple.csproj'."); + remove.StdErr.Should().BeEmpty(); + } + + [Fact] + public void WhenNoPackageIsPassedCommandFails() + { + var projectDirectory = _testAssetsManager + .CopyTestAsset("TestAppSimple") + .WithSource() + .Path; + + var cmd = new DotnetCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("package", "remove") + .Should() + .Fail(); + } + + [Fact] + public void WhenMultiplePackagesArePassedCommandFails() + { + var projectDirectory = _testAssetsManager + .CopyTestAsset("TestAppSimple") + .WithSource() + .Path; + + var cmd = new DotnetCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("package", "remove", "package1", "package2") + .Should() + .Fail(); + } + } +} \ No newline at end of file From 7fc954b8c8190b6b2ae838e31ec6eb7ffc2940d2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Jun 2025 23:48:39 +0000 Subject: [PATCH 2/2] Fix test expectation to use full project path in output message Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com> --- .../CommandTests/Package/Remove/GivenDotnetPackageRemove.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetPackageRemove.cs b/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetPackageRemove.cs index 57d888aded3e..825b1073aa90 100644 --- a/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetPackageRemove.cs +++ b/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetPackageRemove.cs @@ -30,7 +30,7 @@ public void WhenPackageIsRemovedWithoutProjectArgument() .Execute("package", "remove", packageName); remove.Should().Pass(); - remove.StdOut.Should().Contain($"Removing PackageReference for package '{packageName}' from project 'TestAppSimple.csproj'."); + remove.StdOut.Should().Contain($"Removing PackageReference for package '{packageName}' from project '{projectDirectory + Path.DirectorySeparatorChar}TestAppSimple.csproj'."); remove.StdErr.Should().BeEmpty(); }