2017-04-26 23:43:55 +00:00
// 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 ;
2017-06-14 03:38:15 +00:00
using Microsoft.DotNet.Tools ;
2017-04-26 23:43:55 +00:00
using Microsoft.DotNet.Tools.Test.Utilities ;
using Xunit ;
namespace Microsoft.DotNet.Cli.Remove.Package.Tests
{
public class GivenDotnetRemovePackage : TestBase
{
2017-06-27 00:17:51 +00:00
private const string HelpText = @ "Usage: dotnet remove <PROJECT> package [options] <PACKAGE_NAME>
2017-04-26 23:43:55 +00:00
Arguments :
< PROJECT > The project file to operate on . If a file is not specified , the command will search the current directory for one .
2018-04-30 20:42:47 +00:00
< PACKAGE_NAME > The package reference to remove .
2017-04-26 23:43:55 +00:00
Options :
2018-04-30 20:42:47 +00:00
- h , - - help Show command line help . ";
2017-04-26 23:43:55 +00:00
2017-06-27 00:17:51 +00:00
private const string RemoveCommandHelpText = @ "Usage: dotnet remove [options] <PROJECT> [command]
2017-05-03 23:01:35 +00:00
Arguments :
< PROJECT > The project file to operate on . If a file is not specified , the command will search the current directory for one .
Options :
2018-04-30 20:42:47 +00:00
- h , - - help Show command line help .
2017-05-03 23:01:35 +00:00
Commands :
2018-04-09 21:18:24 +00:00
package < PACKAGE_NAME > Remove a NuGet package reference from the project .
2018-04-30 20:42:47 +00:00
reference < PROJECT_PATH > Remove a project - to - project reference from the project . ";
2017-05-03 23:01:35 +00:00
2017-04-26 23:43:55 +00:00
[Theory]
[InlineData("--help")]
[InlineData("-h")]
public void WhenHelpOptionIsPassedItPrintsUsage ( string helpArg )
{
var cmd = new DotnetCommand ( ) . ExecuteWithCapturedOutput ( $"remove package {helpArg}" ) ;
cmd . Should ( ) . Pass ( ) ;
2017-06-14 03:38:15 +00:00
cmd . StdOut . Should ( ) . BeVisuallyEquivalentToIfNotLocalized ( HelpText ) ;
2017-04-26 23:43:55 +00:00
}
[Theory]
[InlineData("")]
[InlineData("unknownCommandName")]
public void WhenNoCommandIsPassedItPrintsError ( string commandName )
{
var cmd = new DotnetCommand ( )
. ExecuteWithCapturedOutput ( $"remove {commandName}" ) ;
cmd . Should ( ) . Fail ( ) ;
2017-06-14 03:38:15 +00:00
cmd . StdErr . Should ( ) . Be ( CommonLocalizableStrings . RequiredCommandNotPassed ) ;
cmd . StdOut . Should ( ) . BeVisuallyEquivalentToIfNotLocalized ( RemoveCommandHelpText ) ;
2017-04-26 23:43:55 +00:00
}
[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 ( ) ;
}
}
}