// 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.IO; using Microsoft.DotNet.Tools.MSBuild; using FluentAssertions; using Xunit; using static Microsoft.DotNet.Tools.Test.Utilities.DirectoryInfoExtensions; using WindowsOnlyFactAttribute = Microsoft.DotNet.Tools.Test.Utilities.WindowsOnlyFactAttribute; using NonWindowsOnlyFactAttribute = Microsoft.DotNet.Tools.Test.Utilities.NonWindowsOnlyFactAttribute; namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenMsbuildForwardingApp { [WindowsOnlyFact] public void DotnetExeIsExecuted() { var msbuildPath = ""; new MSBuildForwardingApp(new string[0], msbuildPath) .GetProcessStartInfo().FileName.Should().Be("dotnet.exe"); } [NonWindowsOnlyFact] public void DotnetIsExecuted() { var msbuildPath = ""; new MSBuildForwardingApp(new string[0], msbuildPath) .GetProcessStartInfo().FileName.Should().Be("dotnet"); } [Theory] [InlineData("MSBuildExtensionsPath")] [InlineData("CscToolExe")] [InlineData("VbcToolExe")] [InlineData("MSBuildSDKsPath")] [InlineData("DOTNET_CLI_TELEMETRY_SESSIONID")] public void ItSetsEnvironmentalVariables(string envVarName) { var msbuildPath = ""; var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath).GetProcessStartInfo(); startInfo.Environment.ContainsKey(envVarName).Should().BeTrue(); } [Fact] public void ItSetsMSBuildExtensionPathToExistingPath() { var msbuildPath = ""; var envVar = "MSBuildExtensionsPath"; new DirectoryInfo(new MSBuildForwardingApp(new string[0], msbuildPath) .GetProcessStartInfo() .Environment[envVar]) .Should() .Exist(); } [Fact] public void ItSetsMSBuildSDKsPathToExistingPath() { var msbuildPath = ""; var envVar = "MSBuildSDKsPath"; new DirectoryInfo(new MSBuildForwardingApp(new string[0], msbuildPath) .GetProcessStartInfo() .Environment[envVar]) .Should() .Exist(); } [Fact] public void ItSetsCscToolExePathToValidPath() { var msbuildPath = ""; var envVar = "CscToolExe"; new FileInfo(new MSBuildForwardingApp(new string[0], msbuildPath) .GetProcessStartInfo() .Environment[envVar]) .Should().NotBeNull("constructor will throw on invalid path"); } [Fact] public void ItSetsVbcToolExePathToValidPath() { var msbuildPath = ""; var envVar = "VbcToolExe"; new FileInfo(new MSBuildForwardingApp(new string[0], msbuildPath) .GetProcessStartInfo() .Environment[envVar]) .Should().NotBeNull("constructor will throw on invalid path"); } [Fact] public void ItSetsOrIgnoresTelemetrySessionId() { var msbuildPath = ""; var envVar = "DOTNET_CLI_TELEMETRY_SESSIONID"; var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath) .GetProcessStartInfo(); (startInfo.Environment[envVar] == null || int.TryParse(startInfo.Environment[envVar], out _)) .Should().BeTrue("DOTNET_CLI_TELEMETRY_SESSIONID should be null or current session id"); } [Fact] public void ItDoesNotSetCurrentWorkingDirectory() { var msbuildPath = ""; var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath) .GetProcessStartInfo().WorkingDirectory.Should().Be(""); } } }