2018-03-15 19:45:11 -07: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.Linq ;
using FluentAssertions ;
using Microsoft.DotNet.Cli ;
using Microsoft.DotNet.Cli.CommandLine ;
using Xunit ;
using Xunit.Abstractions ;
using Parser = Microsoft . DotNet . Cli . Parser ;
namespace Microsoft.DotNet.Tests.ParserTests
{
public class UpdateInstallToolParserTests
{
private readonly ITestOutputHelper _output ;
public UpdateInstallToolParserTests ( ITestOutputHelper output )
{
_output = output ;
}
[Fact]
public void UpdateGlobaltoolParserCanGetPackageId ( )
{
var command = Parser . Instance ;
2018-03-21 19:12:32 -07:00
var result = command . Parse ( "dotnet tool update -g console.test.app" ) ;
2018-03-15 19:45:11 -07:00
2018-03-21 19:12:32 -07:00
var parseResult = result [ "dotnet" ] [ "tool" ] [ "update" ] ;
2018-03-15 19:45:11 -07:00
var packageId = parseResult . Arguments . Single ( ) ;
packageId . Should ( ) . Be ( "console.test.app" ) ;
}
[Fact]
public void UpdateToolParserCanGetGlobalOption ( )
{
2018-03-21 19:12:32 -07:00
var result = Parser . Instance . Parse ( "dotnet tool update -g console.test.app" ) ;
2018-03-15 19:45:11 -07:00
2018-03-21 19:12:32 -07:00
var appliedOptions = result [ "dotnet" ] [ "tool" ] [ "update" ] ;
2018-03-15 19:45:11 -07:00
appliedOptions . ValueOrDefault < bool > ( "global" ) . Should ( ) . Be ( true ) ;
}
[Fact]
public void UpdateToolParserCanGetFollowingArguments ( )
{
var command = Parser . Instance ;
var result =
command . Parse (
2018-03-21 19:12:32 -07:00
@"dotnet tool update -g console.test.app --version 1.0.1 --framework netcoreapp2.0 --configfile C:\TestAssetLocalNugetFeed" ) ;
2018-03-15 19:45:11 -07:00
2018-03-21 19:12:32 -07:00
var parseResult = result [ "dotnet" ] [ "tool" ] [ "update" ] ;
2018-03-15 19:45:11 -07:00
parseResult . ValueOrDefault < string > ( "configfile" ) . Should ( ) . Be ( @"C:\TestAssetLocalNugetFeed" ) ;
parseResult . ValueOrDefault < string > ( "framework" ) . Should ( ) . Be ( "netcoreapp2.0" ) ;
}
[Fact]
public void UpdateToolParserCanParseSourceOption ( )
{
const string expectedSourceValue = "TestSourceValue" ;
var result =
2018-05-01 10:21:00 -07:00
Parser . Instance . Parse ( $"dotnet tool update -g --add-source {expectedSourceValue} console.test.app" ) ;
2018-03-15 19:45:11 -07:00
2018-03-21 19:12:32 -07:00
var appliedOptions = result [ "dotnet" ] [ "tool" ] [ "update" ] ;
2018-05-01 10:21:00 -07:00
appliedOptions . ValueOrDefault < string [ ] > ( "add-source" ) . First ( ) . Should ( ) . Be ( expectedSourceValue ) ;
2018-03-19 22:22:45 -07:00
}
[Fact]
public void UpdateToolParserCanParseMultipleSourceOption ( )
{
const string expectedSourceValue1 = "TestSourceValue1" ;
const string expectedSourceValue2 = "TestSourceValue2" ;
var result =
Parser . Instance . Parse (
2018-03-21 19:12:32 -07:00
$"dotnet tool update -g " +
2018-05-01 10:21:00 -07:00
$"--add-source {expectedSourceValue1} " +
$"--add-source {expectedSourceValue2} console.test.app" ) ;
2018-03-19 22:22:45 -07:00
2018-03-21 19:12:32 -07:00
var appliedOptions = result [ "dotnet" ] [ "tool" ] [ "update" ] ;
2018-03-19 22:22:45 -07:00
2018-05-01 10:21:00 -07:00
appliedOptions . ValueOrDefault < string [ ] > ( "add-source" ) [ 0 ] . Should ( ) . Be ( expectedSourceValue1 ) ;
appliedOptions . ValueOrDefault < string [ ] > ( "add-source" ) [ 1 ] . Should ( ) . Be ( expectedSourceValue2 ) ;
2018-03-15 19:45:11 -07:00
}
[Fact]
public void UpdateToolParserCanParseVerbosityOption ( )
{
const string expectedVerbosityLevel = "diag" ;
var result =
2018-03-21 19:12:32 -07:00
Parser . Instance . Parse ( $"dotnet tool update -g --verbosity:{expectedVerbosityLevel} console.test.app" ) ;
2018-03-15 19:45:11 -07:00
2018-03-21 19:12:32 -07:00
var appliedOptions = result [ "dotnet" ] [ "tool" ] [ "update" ] ;
2018-03-15 19:45:11 -07:00
appliedOptions . SingleArgumentOrDefault ( "verbosity" ) . Should ( ) . Be ( expectedVerbosityLevel ) ;
}
[Fact]
public void UpdateToolParserCanParseToolPathOption ( )
{
var result =
2018-03-21 19:12:32 -07:00
Parser . Instance . Parse ( @"dotnet tool update --tool-path C:\TestAssetLocalNugetFeed console.test.app" ) ;
2018-03-15 19:45:11 -07:00
2018-03-21 19:12:32 -07:00
var appliedOptions = result [ "dotnet" ] [ "tool" ] [ "update" ] ;
2018-03-15 19:45:11 -07:00
appliedOptions . SingleArgumentOrDefault ( "tool-path" ) . Should ( ) . Be ( @"C:\TestAssetLocalNugetFeed" ) ;
}
}
}