forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGivenDotnetRunInvocation.cs
54 lines (47 loc) · 2.69 KB
/
GivenDotnetRunInvocation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Cli.Commands.Run;
namespace Microsoft.DotNet.Cli.MSBuild.Tests
{
[Collection(TestConstants.UsesStaticTelemetryState)]
public class GivenDotnetRunInvocation : IClassFixture<NullCurrentSessionIdFixture>
{
private static readonly string[] ConstantRestoreArgs = ["-nologo", "-verbosity:quiet"];
private static readonly string NuGetDisabledProperty = "-property:NuGetInteractive=false";
public ITestOutputHelper Log { get; }
public GivenDotnetRunInvocation(ITestOutputHelper log)
{
Log = log;
}
[Theory]
[InlineData(new string[] { "-p:prop1=true" }, new string[] { "--property:prop1=true" })]
[InlineData(new string[] { "--property:prop1=true" }, new string[] { "--property:prop1=true" })]
[InlineData(new string[] { "--property", "prop1=true" }, new string[] { "--property:prop1=true" })]
[InlineData(new string[] { "-p", "prop1=true" }, new string[] { "--property:prop1=true" })]
[InlineData(new string[] { "-p", "prop1=true", "-p", "prop2=false" }, new string[] { "--property:prop1=true", "--property:prop2=false" })]
[InlineData(new string[] { "-p:prop1=true;prop2=false" }, new string[] { "--property:prop1=true", "--property:prop2=false" })]
[InlineData(new string[] { "-p", "MyProject.csproj", "-p:prop1=true" }, new string[] { "--property:prop1=true" })]
[InlineData(new string[] { "--disable-build-servers" }, new string[] { "--property:UseRazorBuildServer=false", "--property:UseSharedCompilation=false", "/nodeReuse:false" })]
public void MsbuildInvocationIsCorrect(string[] args, string[] expectedArgs)
{
var tam = new TestAssetsManager(Log);
var oldWorkingDirectory = Directory.GetCurrentDirectory();
var newWorkingDir = tam.CopyTestAsset("HelloWorld", identifier: $"{nameof(MsbuildInvocationIsCorrect)}_{args.GetHashCode()}_{expectedArgs.GetHashCode()}").WithSource().Path;
try
{
Directory.SetCurrentDirectory(newWorkingDir);
CommandDirectoryContext.PerformActionWithBasePath(newWorkingDir, () =>
{
var command = RunCommand.FromArgs(args);
command.RestoreArgs
.Should()
.BeEquivalentTo([.. ConstantRestoreArgs, .. expectedArgs, NuGetDisabledProperty]);
});
}
finally
{
Directory.SetCurrentDirectory(oldWorkingDirectory);
}
}
}
}