fix NullReferenceError on remove package and incorrect help text

This commit is contained in:
Jon Sequeira 2017-04-26 16:43:55 -07:00
parent c9e0989152
commit 74af357f07
6 changed files with 177 additions and 6 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -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());
}
}
}
}

View file

@ -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

View file

@ -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 <PROJECT> package [options] <PACKAGE_NAME>
Arguments:
<PROJECT> The project file to operate on. If a file is not specified, the command will search the current directory for one.
<PACKAGE_NAME> 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();
}
}
}

View file

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<TargetFramework>$(CliTargetFramework)</TargetFramework>
<RuntimeFrameworkVersion>$(CLI_SharedFrameworkVersion)</RuntimeFrameworkVersion>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>dotnet-remove-package.Tests</AssemblyName>
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Sln.Internal\Microsoft.DotNet.Cli.Sln.Internal.csproj" />
<ProjectReference Include="..\..\src\Microsoft.DotNet.ProjectJsonMigration\Microsoft.DotNet.ProjectJsonMigration.csproj" />
<ProjectReference Include="..\Msbuild.Tests.Utilities\Msbuild.Tests.Utilities.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20161024-02" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta4-build1194" />
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
<PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" />
<PackageReference Include="FluentAssertions" Version="4.18.0" />
</ItemGroup>
</Project>