2016-12-16 00:55:52 +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.Collections.Generic ;
using System.IO ;
using Microsoft.Build.Construction ;
using Microsoft.DotNet.Tools.Test.Utilities ;
using Xunit ;
using FluentAssertions ;
2017-02-17 17:00:25 +00:00
using HelpActual = Microsoft . DotNet . Tools . Help ;
2016-12-16 00:55:52 +00:00
namespace Microsoft.DotNet.Help.Tests
{
public class GivenThatIWantToShowHelpForDotnetCommand : TestBase
{
private const string HelpText =
@ "Usage: dotnet [host-options] [command] [arguments] [common-options]
Arguments :
[command] The command to execute
[arguments] Arguments to pass to the command
[host-options] Options specific to dotnet ( host )
[common-options] Options common to all commands
Common options :
- v | - - verbose Enable verbose output
2017-04-05 18:30:45 +00:00
- h | - - help Show help
2016-12-16 00:55:52 +00:00
Host options ( passed before the command ) :
2016-12-16 20:35:25 +00:00
- d | - - diagnostics Enable diagnostic output
2016-12-16 00:55:52 +00:00
- - version Display . NET CLI Version Number
- - info Display . NET CLI Info
Commands :
2016-12-17 03:16:38 +00:00
new Initialize . NET projects .
restore Restore dependencies specified in the . NET project .
build Builds a . NET project .
publish Publishes a . NET project for deployment ( including the runtime ) .
run Compiles and immediately executes a . NET project .
test Runs unit tests using the test runner specified in the project .
pack Creates a NuGet package .
migrate Migrates a project . json based project to a msbuild based project .
2016-12-17 04:14:33 +00:00
clean Clean build output ( s ) .
2017-01-05 20:05:58 +00:00
sln Modify solution ( SLN ) files .
2016-12-16 00:55:52 +00:00
Project modification commands :
add Add items to the project
remove Remove items from the project
list List items in the project
Advanced Commands :
2016-12-17 03:16:38 +00:00
nuget Provides additional NuGet commands .
msbuild Runs Microsoft Build Engine ( MSBuild ) .
vstest Runs Microsoft Test Execution Command Line Tool . ";
2016-12-16 00:55:52 +00:00
[Theory]
[InlineData("--help")]
[InlineData("-h")]
2017-01-13 09:24:12 +00:00
[InlineData("-?")]
[InlineData("/?")]
2016-12-16 00:55:52 +00:00
public void WhenHelpOptionIsPassedToDotnetItPrintsUsage ( string helpArg )
{
var cmd = new DotnetCommand ( )
. ExecuteWithCapturedOutput ( $"{helpArg}" ) ;
2016-12-28 22:50:34 +00:00
cmd . Should ( ) . Pass ( ) ;
cmd . StdOut . Should ( ) . ContainVisuallySameFragment ( HelpText ) ;
2016-12-16 00:55:52 +00:00
}
2017-02-17 17:00:25 +00:00
2017-04-05 18:30:45 +00:00
[Fact]
public void WhenHelpCommandIsPassedToDotnetItPrintsUsage ( )
{
var cmd = new HelpCommand ( )
. ExecuteWithCapturedOutput ( ) ;
cmd . Should ( ) . Pass ( ) ;
cmd . StdOut . Should ( ) . ContainVisuallySameFragment ( HelpText ) ;
}
2017-02-17 17:00:25 +00:00
[Fact]
2017-03-15 14:24:00 +00:00
public void WhenInvalidCommandIsPassedToDotnetHelpItPrintsError ( )
2017-02-17 17:00:25 +00:00
{
var cmd = new DotnetCommand ( )
. ExecuteWithCapturedOutput ( "help invalid" ) ;
2017-04-05 18:30:45 +00:00
2017-02-17 17:00:25 +00:00
cmd . Should ( ) . Fail ( ) ;
2017-03-16 00:00:52 +00:00
cmd . StdErr . Should ( ) . ContainVisuallySameFragment ( $"Specified command 'invalid' is not a valid CLI command. Please specify a valid CLI commands. For more information, run dotnet help." ) ;
2017-03-15 16:51:07 +00:00
cmd . StdOut . Should ( ) . ContainVisuallySameFragment ( HelpText ) ;
2017-02-17 17:00:25 +00:00
}
[WindowsOnlyFact]
public void WhenRunOnWindowsDotnetHelpCommandShouldContainProperProcessInformation ( )
{
var proc = HelpActual . HelpCommand . ConfigureProcess ( "https://aka.ms/dotnet-build" ) ;
Assert . Equal ( "cmd" , proc . StartInfo . FileName ) ;
Assert . Equal ( "/c start https://aka.ms/dotnet-build" , proc . StartInfo . Arguments ) ;
}
[LinuxOnlyFact]
public void WhenRunOnLinuxDotnetHelpCommandShouldContainProperProcessInformation ( )
{
var proc = HelpActual . HelpCommand . ConfigureProcess ( "https://aka.ms/dotnet-build" ) ;
Assert . Equal ( "xdg-open" , proc . StartInfo . FileName ) ;
Assert . Equal ( "https://aka.ms/dotnet-build" , proc . StartInfo . Arguments ) ;
2017-04-05 18:30:45 +00:00
2017-02-17 17:00:25 +00:00
}
[MacOsOnlyFact]
public void WhenRunOnMacOsDotnetHelpCommandShouldContainProperProcessInformation ( )
{
var proc = HelpActual . HelpCommand . ConfigureProcess ( "https://aka.ms/dotnet-build" ) ;
Assert . Equal ( "open" , proc . StartInfo . FileName ) ;
Assert . Equal ( "https://aka.ms/dotnet-build" , proc . StartInfo . Arguments ) ;
}
2016-12-16 00:55:52 +00:00
}
}