// 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.Text; using Xunit; using FluentAssertions; using Microsoft.DotNet.Tools.Test.Utilities; namespace Microsoft.DotNet.Cli { public class GivenForwardingApp { [WindowsOnlyFact] public void DotnetExeIsExecuted() { new ForwardingApp("", new string[0]) .GetProcessStartInfo().FileName.Should().Be("dotnet.exe"); } [NonWindowsOnlyFact] public void DotnetIsExecuted() { new ForwardingApp("", new string[0]) .GetProcessStartInfo().FileName.Should().Be("dotnet"); } [Fact] public void ItForwardsArgs() { new ForwardingApp("", new string[] { "one", "two", "three" }) .GetProcessStartInfo().Arguments.Should().Be("exec one two three"); } [Fact] public void ItAddsDepsFileArg() { new ForwardingApp("", new string[] { "" }, depsFile: "") .GetProcessStartInfo().Arguments.Should().Be("exec --depsfile "); } [Fact] public void ItAddsRuntimeConfigArg() { new ForwardingApp("", new string[] { "" }, runtimeConfig: "") .GetProcessStartInfo().Arguments.Should().Be("exec --runtimeconfig "); } [Fact] public void ItAddsAdditionalProbingPathArg() { new ForwardingApp("", new string[] { "" }, additionalProbingPath: "") .GetProcessStartInfo().Arguments.Should().Be("exec --additionalprobingpath "); } [Fact] public void ItQuotesArgsWithSpaces() { new ForwardingApp("", new string[] { "a b c" }) .GetProcessStartInfo().Arguments.Should().Be("exec \"a b c\""); } [Fact] public void ItEscapesArgs() { new ForwardingApp("", new string[] { "a\"b\"c" }) .GetProcessStartInfo().Arguments.Should().Be("exec a\\\"b\\\"c"); } [Fact] public void ItSetsEnvironmentalVariables() { var startInfo = new ForwardingApp("", new string[0], environmentVariables: new Dictionary { { "env1", "env1value" }, { "env2", "env2value" } }) .GetProcessStartInfo(); startInfo.EnvironmentVariables["env1"].Should().Be("env1value"); startInfo.EnvironmentVariables["env2"].Should().Be("env2value"); } } }