split msbuildforwardingapp unit tests with build invocation
This commit is contained in:
parent
1b7d4e3200
commit
e6578eeb14
2 changed files with 97 additions and 88 deletions
|
@ -1,11 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.DotNet.Tools.Build;
|
||||
using Microsoft.DotNet.Tools.Build;
|
||||
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
|
||||
{
|
||||
|
@ -28,92 +23,11 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
|||
[InlineData(new string[] { "-v", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
||||
[InlineData(new string[] { "--verbosity", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
||||
[InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec <msbuildpath> /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")]
|
||||
public void WhenArgsArePassedThenMsbuildInvocationIsCorrect(string[] args, string expectedCommand)
|
||||
public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand)
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
BuildCommand.FromArgs(args, msbuildPath)
|
||||
.GetProcessStartInfo().Arguments.Should().Be(expectedCommand);
|
||||
}
|
||||
|
||||
[WindowsOnlyFact]
|
||||
public void WhenInvokingBuildCommandOnWindowsTheDotnetIsExecuted()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
BuildCommand.FromArgs(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo().FileName.Should().Be("dotnet.exe");
|
||||
}
|
||||
|
||||
[NonWindowsOnlyFact]
|
||||
public void WhenInvokingBuildCommandOnNonWindowsTheDotnetIsExecuted()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
BuildCommand.FromArgs(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo().FileName.Should().Be("dotnet");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("MSBuildExtensionsPath")]
|
||||
[InlineData("CscToolExe")]
|
||||
[InlineData("MSBuildSDKsPath")]
|
||||
[InlineData("DOTNET_CLI_TELEMETRY_SESSIONID")]
|
||||
public void WhenInvokingBuildCommandItSetsEnvironmentalVariables(string envVarName)
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var startInfo = BuildCommand.FromArgs(new string[0], msbuildPath).GetProcessStartInfo();
|
||||
startInfo.Environment.ContainsKey(envVarName).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenInvokingBuildCommandItSetsMSBuildExtensionPathToExistingPath()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var envVar = "MSBuildExtensionsPath";
|
||||
new DirectoryInfo(BuildCommand.FromArgs(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo()
|
||||
.Environment[envVar])
|
||||
.Should()
|
||||
.Exist();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenInvokingBuildCommandItSetsMSBuildSDKsPathToExistingPath()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var envVar = "MSBuildSDKsPath";
|
||||
new DirectoryInfo(BuildCommand.FromArgs(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo()
|
||||
.Environment[envVar])
|
||||
.Should()
|
||||
.Exist();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenInvokingBuildCommandItSetsCscToolExePathToValidPath()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var envVar = "CscToolExe";
|
||||
new FileInfo(BuildCommand.FromArgs(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo()
|
||||
.Environment[envVar])
|
||||
.Should().NotBeNull("constructor will throw on invalid path");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenInvokingBuildCommandItSetsTelemetryEnvVar()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var envVar = "DOTNET_CLI_TELEMETRY_SESSIONID";
|
||||
var startInfo = BuildCommand.FromArgs(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 WhenInvokingBuildCommandItDoesNotSetCurrentWorkingDirectory()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var startInfo = BuildCommand.FromArgs(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo().WorkingDirectory.Should().Be("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
95
test/dotnet-msbuild.Tests/GivenMsbuildForwardingApp.cs
Normal file
95
test/dotnet-msbuild.Tests/GivenMsbuildForwardingApp.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
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 = "<msbuildpath>";
|
||||
new MSBuildForwardingApp(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo().FileName.Should().Be("dotnet.exe");
|
||||
}
|
||||
|
||||
[NonWindowsOnlyFact]
|
||||
public void DotnetIsExecuted()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
new MSBuildForwardingApp(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo().FileName.Should().Be("dotnet");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("MSBuildExtensionsPath")]
|
||||
[InlineData("CscToolExe")]
|
||||
[InlineData("MSBuildSDKsPath")]
|
||||
[InlineData("DOTNET_CLI_TELEMETRY_SESSIONID")]
|
||||
public void ItSetsEnvironmentalVariables(string envVarName)
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath).GetProcessStartInfo();
|
||||
startInfo.Environment.ContainsKey(envVarName).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItSetsMSBuildExtensionPathToExistingPath()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var envVar = "MSBuildExtensionsPath";
|
||||
new DirectoryInfo(new MSBuildForwardingApp(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo()
|
||||
.Environment[envVar])
|
||||
.Should()
|
||||
.Exist();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItSetsMSBuildSDKsPathToExistingPath()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var envVar = "MSBuildSDKsPath";
|
||||
new DirectoryInfo(new MSBuildForwardingApp(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo()
|
||||
.Environment[envVar])
|
||||
.Should()
|
||||
.Exist();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItSetsCscToolExePathToValidPath()
|
||||
{
|
||||
var msbuildPath = "<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 ItSetsOrIgnoresTelemetrySessionId()
|
||||
{
|
||||
var msbuildPath = "<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 = "<msbuildpath>";
|
||||
var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo().WorkingDirectory.Should().Be("");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue