dotnet-installer/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs

68 lines
2.4 KiB
C#
Raw Normal View History

2017-03-07 04:53:26 +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 FluentAssertions;
using System.Linq;
2017-03-07 04:53:26 +00:00
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.CommandLine;
using Xunit;
using static Microsoft.DotNet.Cli.CommandLine.Accept;
using static Microsoft.DotNet.Cli.CommandLine.Create;
namespace Microsoft.DotNet.Tests.ParserTests
{
public class ArgumentForwardingExtensionsTests
{
[Fact]
public void AnOutgoingCommandLineCanBeGeneratedBasedOnAParseResult()
2017-03-07 04:53:26 +00:00
{
var command = Command("the-command", "",
Option("-o|--one", "",
2017-03-11 01:11:19 +00:00
ZeroOrOneArgument()
.ForwardAsSingle(o => $"/i:{o.Arguments.Single()}")),
Option("-t|--two", "",
2017-03-11 01:11:19 +00:00
NoArguments()
.ForwardAs("/s:true")));
2017-03-07 04:53:26 +00:00
var result = command.Parse("the-command -t -o 123");
2017-03-07 04:53:26 +00:00
result["the-command"]
.OptionValuesToBeForwarded()
2017-03-07 04:53:26 +00:00
.Should()
.BeEquivalentTo("/i:123", "/s:true");
2017-03-07 04:53:26 +00:00
}
[Fact]
public void MultipleArgumentsCanBeJoinedWhenForwarding()
{
var command = Command("the-command", "",
Option("-x", "",
2017-03-11 01:11:19 +00:00
ZeroOrMoreArguments()
.ForwardAsSingle(o => $"/x:{string.Join("&", o.Arguments)}")));
2017-03-07 04:53:26 +00:00
var result = command.Parse("the-command -x one -x two");
result["the-command"]
.OptionValuesToBeForwarded()
2017-03-07 04:53:26 +00:00
.Should()
.BeEquivalentTo("/x:one&two");
}
[Fact]
public void AnArgumentCanBeForwardedAsIs()
{
var command = Command("the-command", "",
Option("-x", "",
2017-03-11 01:11:19 +00:00
ZeroOrMoreArguments()
.Forward()));
var result = command.Parse("the-command -x one");
result["the-command"]
.OptionValuesToBeForwarded()
.Should()
.BeEquivalentTo("one");
}
2017-03-07 04:53:26 +00:00
}
2017-03-10 18:13:11 +00:00
}