From 74af357f07334465949aa7517d0a07a21866d319 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Wed, 26 Apr 2017 16:43:55 -0700 Subject: [PATCH] fix NullReferenceError on remove package and incorrect help text --- Microsoft.DotNet.Cli.sln | 56 +++++++++++++- .../dotnet-remove-package/Program.cs | 2 +- .../RemovePackageParser.cs | 13 +++- test/Microsoft.DotNet.Cli.Tests.sln | 14 ++++ .../GivenDotnetRemovePackage.cs | 73 +++++++++++++++++++ .../dotnet-remove-package.Tests.csproj | 25 +++++++ 6 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 test/dotnet-remove-package.Tests/GivenDotnetRemovePackage.cs create mode 100644 test/dotnet-remove-package.Tests/dotnet-remove-package.Tests.csproj diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 08da39cfa..38745a85f 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -166,7 +166,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet.Tests", "test\dotnet EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-build.Tests", "test\dotnet-build.Tests\dotnet-build.Tests.csproj", "{BBB5A4C8-CD2D-4A6A-9159-0FEAF84B745E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-help.Tests", "test\dotnet-help.Tests\dotnet-help.Tests.csproj", "{8AA88E83-6A98-4AD6-86EB-2ED4F6EDA17F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-help.Tests", "test\dotnet-help.Tests\dotnet-help.Tests.csproj", "{8AA88E83-6A98-4AD6-86EB-2ED4F6EDA17F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-migrate.Tests", "test\dotnet-migrate.Tests\dotnet-migrate.Tests.csproj", "{726D2CB9-80E5-4496-9C86-910AC452C45E}" EndProject @@ -228,6 +228,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-back-compat.Tests", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-outputsframeworkversion-netcoreapp1.0", "TestAssets\TestPackages\dotnet-outputsframeworkversion\dotnet-outputsframeworkversion-netcoreapp1.0\dotnet-outputsframeworkversion-netcoreapp1.0.csproj", "{3F7D56A3-A280-467E-8916-C18659C243BA}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-remove-package.Tests", "test\dotnet-remove-package.Tests\dotnet-remove-package.Tests.csproj", "{B1AEC227-5115-44BC-92D2-B1B3545E1DDE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-add-package.Tests", "test\dotnet-add-package.Tests\dotnet-add-package.Tests.csproj", "{08A40B6A-F695-4EA9-AC8D-CF88FADEA796}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1588,6 +1592,54 @@ Global {3F7D56A3-A280-467E-8916-C18659C243BA}.RelWithDebInfo|x64.Build.0 = Release|Any CPU {3F7D56A3-A280-467E-8916-C18659C243BA}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU {3F7D56A3-A280-467E-8916-C18659C243BA}.RelWithDebInfo|x86.Build.0 = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Debug|x64.ActiveCfg = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Debug|x64.Build.0 = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Debug|x86.ActiveCfg = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Debug|x86.Build.0 = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.MinSizeRel|x86.Build.0 = Debug|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Release|Any CPU.Build.0 = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Release|x64.ActiveCfg = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Release|x64.Build.0 = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Release|x86.ActiveCfg = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.Release|x86.Build.0 = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE}.RelWithDebInfo|x86.Build.0 = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Debug|Any CPU.Build.0 = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Debug|x64.ActiveCfg = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Debug|x64.Build.0 = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Debug|x86.ActiveCfg = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Debug|x86.Build.0 = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.MinSizeRel|x86.Build.0 = Debug|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Release|Any CPU.ActiveCfg = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Release|Any CPU.Build.0 = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Release|x64.ActiveCfg = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Release|x64.Build.0 = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Release|x86.ActiveCfg = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.Release|x86.Build.0 = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796}.RelWithDebInfo|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1658,5 +1710,7 @@ Global {DE4D1AEB-871B-4E7C-945A-453F9A490C06} = {89905EC4-BC0F-443B-8ADF-691321F10108} {A4C198B4-D46E-4CA8-87DF-B2B206DCCAE6} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {3F7D56A3-A280-467E-8916-C18659C243BA} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34} + {B1AEC227-5115-44BC-92D2-B1B3545E1DDE} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} + {08A40B6A-F695-4EA9-AC8D-CF88FADEA796} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} EndGlobalSection EndGlobal diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs index de13b8b97..36d5fce0d 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs @@ -29,7 +29,7 @@ namespace Microsoft.DotNet.Tools.Remove.PackageReference { throw new ArgumentNullException(nameof(fileOrDirectory)); } - if (_appliedCommand.Arguments.Count != 1) + if (appliedCommand.Arguments.Count != 1) { throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference); } diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs index acfe8fa1c..1c7cdc21a 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs @@ -1,14 +1,19 @@ using Microsoft.DotNet.Cli.CommandLine; -using LocalizableStrings = Microsoft.DotNet.Tools.Remove.ProjectToProjectReference.LocalizableStrings; +using LocalizableStrings = Microsoft.DotNet.Tools.Remove.PackageReference.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class RemovePackageParser { - public static Command RemovePackage() => - Create.Command( + public static Command RemovePackage() + { + return Create.Command( "package", LocalizableStrings.AppFullName, + Accept.ExactlyOneArgument() + .With(name: Tools.Add.PackageReference.LocalizableStrings.CmdPackage, + description: LocalizableStrings.AppHelpText), CommonOptions.HelpOption()); + } } -} \ No newline at end of file +} diff --git a/test/Microsoft.DotNet.Cli.Tests.sln b/test/Microsoft.DotNet.Cli.Tests.sln index 30e4e2f60..7771b2c18 100644 --- a/test/Microsoft.DotNet.Cli.Tests.sln +++ b/test/Microsoft.DotNet.Cli.Tests.sln @@ -76,6 +76,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-store.Tests", "dotne EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-back-compat.Tests", "dotnet-back-compat.Tests\dotnet-back-compat.Tests.csproj", "{27351B2F-325B-4843-9F4C-BC53FD06A7B5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-remove-package.Tests", "dotnet-remove-package.Tests\dotnet-remove-package.Tests.csproj", "{CF517B15-B307-4660-87D5-CC036ADECD4B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -506,6 +508,18 @@ Global {27351B2F-325B-4843-9F4C-BC53FD06A7B5}.Release|x64.Build.0 = Release|Any CPU {27351B2F-325B-4843-9F4C-BC53FD06A7B5}.Release|x86.ActiveCfg = Release|Any CPU {27351B2F-325B-4843-9F4C-BC53FD06A7B5}.Release|x86.Build.0 = Release|Any CPU + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Debug|x64.ActiveCfg = Debug|x64 + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Debug|x64.Build.0 = Debug|x64 + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Debug|x86.ActiveCfg = Debug|x86 + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Debug|x86.Build.0 = Debug|x86 + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Release|Any CPU.Build.0 = Release|Any CPU + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Release|x64.ActiveCfg = Release|x64 + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Release|x64.Build.0 = Release|x64 + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Release|x86.ActiveCfg = Release|x86 + {CF517B15-B307-4660-87D5-CC036ADECD4B}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/dotnet-remove-package.Tests/GivenDotnetRemovePackage.cs b/test/dotnet-remove-package.Tests/GivenDotnetRemovePackage.cs new file mode 100644 index 000000000..f0ee0f490 --- /dev/null +++ b/test/dotnet-remove-package.Tests/GivenDotnetRemovePackage.cs @@ -0,0 +1,73 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.IO; +using FluentAssertions; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; + +namespace Microsoft.DotNet.Cli.Remove.Package.Tests +{ + public class GivenDotnetRemovePackage : TestBase + { + private const string HelpText = @".NET Remove Package reference Command. + +Usage: dotnet remove package [options] + +Arguments: + The project file to operate on. If a file is not specified, the command will search the current directory for one. + Package reference to remove. + +Options: + -h, --help Show help information +"; + + [Theory] + [InlineData("--help")] + [InlineData("-h")] + public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg) + { + var cmd = new DotnetCommand().ExecuteWithCapturedOutput($"remove package {helpArg}"); + cmd.Should().Pass(); + cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText); + } + + [Theory] + [InlineData("")] + [InlineData("unknownCommandName")] + public void WhenNoCommandIsPassedItPrintsError(string commandName) + { + var cmd = new DotnetCommand() + .ExecuteWithCapturedOutput($"remove {commandName}"); + cmd.Should().Fail(); + cmd.StdErr.Should().Be("Required command was not provided."); + } + + [Fact] + public void WhenReferencedPackageIsPassedItGetsRemoved() + { + var projectDirectory = TestAssets + .Get("TestAppSimple") + .CreateInstance() + .WithSourceFiles() + .Root + .FullName; + + var packageName = "Newtonsoft.Json"; + var add = new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput($"add package {packageName}"); + add.Should().Pass(); + + + var remove = new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput($"remove package {packageName}"); + + remove.Should().Pass(); + remove.StdOut.Should().Contain($"Removing PackageReference for package '{packageName}' from project '{projectDirectory + Path.DirectorySeparatorChar}TestAppSimple.csproj'."); + remove.StdErr.Should().BeEmpty(); + } + } +} diff --git a/test/dotnet-remove-package.Tests/dotnet-remove-package.Tests.csproj b/test/dotnet-remove-package.Tests/dotnet-remove-package.Tests.csproj new file mode 100644 index 000000000..7ed37efa2 --- /dev/null +++ b/test/dotnet-remove-package.Tests/dotnet-remove-package.Tests.csproj @@ -0,0 +1,25 @@ + + + + + $(CliTargetFramework) + $(CLI_SharedFrameworkVersion) + true + dotnet-remove-package.Tests + $(PackageTargetFallback);dotnet5.4;portable-net451+win8 + + + + + + + + + + + + + + + +