From 099dca39500bf67bf873459ff2d7eed0796c11dd Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 10:43:05 -0800 Subject: [PATCH 01/12] stub for tests --- src/Microsoft.DotNet.Cli.Utils/CoreHost.cs | 52 ------------------- .../Extensions/LockFileFormatExtensions.cs | 6 --- .../InvalidProjectException.cs | 11 ---- .../GivenDotnetAddInvocation.cs | 35 +++++++++++++ .../GivenDotnetCacheInvocation.cs | 35 +++++++++++++ .../GivenDotnetCleanInvocation.cs | 35 +++++++++++++ .../GivenDotnetListInvocation.cs | 35 +++++++++++++ .../GivenDotnetMsbuildInvocation.cs | 35 +++++++++++++ .../GivenDotnetPackInvocation.cs | 35 +++++++++++++ .../GivenDotnetPublishInvocation.cs | 35 +++++++++++++ .../GivenDotnetRemoveInvocation.cs | 35 +++++++++++++ .../GivenDotnetRestoreInvocation.cs | 35 +++++++++++++ .../GivenDotnetRunInvocation.cs | 35 +++++++++++++ .../GivenDotnetSlnInvocation.cs | 35 +++++++++++++ .../GivenDotnetTestInvocation.cs | 35 +++++++++++++ .../GivenDotnetVsTestInvocation.cs | 35 +++++++++++++ 16 files changed, 455 insertions(+), 69 deletions(-) delete mode 100644 src/Microsoft.DotNet.Cli.Utils/CoreHost.cs delete mode 100644 src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs diff --git a/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs b/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs deleted file mode 100644 index 2424bf65f..000000000 --- a/src/Microsoft.DotNet.Cli.Utils/CoreHost.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.IO; - -namespace Microsoft.DotNet.Cli.Utils -{ - public static class CoreHost - { - internal static string _hostDir; - internal static string _hostExePath; - - public static string HostExePath - { - get - { - if (_hostExePath == null) - { - _hostExePath = Path.Combine(HostDir, Constants.HostExecutableName); - } - return _hostExePath; - } - } - - private static string HostDir - { - get - { - if (_hostDir == null) - { - var fxDepsFile = Muxer.GetDataFromAppDomain("FX_DEPS_FILE"); - _hostDir = Path.GetDirectoryName(fxDepsFile); - } - - return _hostDir; - } - } - - public static void CopyTo(string destinationPath, string hostExeName) - { - foreach (var binaryName in Constants.HostBinaryNames) - { - var outputBinaryName = binaryName.Equals(Constants.HostExecutableName) - ? hostExeName : binaryName; - var outputBinaryPath = Path.Combine(destinationPath, outputBinaryName); - var hostBinaryPath = Path.Combine(HostDir, binaryName); - File.Copy(hostBinaryPath, outputBinaryPath, overwrite: true); - - // Update the last write time so this file can be treated as an output of a build - File.SetLastWriteTimeUtc(outputBinaryPath, DateTime.UtcNow); - } - } - } -} diff --git a/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileFormatExtensions.cs b/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileFormatExtensions.cs index 0c4f9c702..559d6bebe 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileFormatExtensions.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileFormatExtensions.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Threading; using System.Threading.Tasks; - using NuGet.Common; using NuGet.ProjectModel; @@ -13,11 +12,6 @@ namespace Microsoft.DotNet.Cli.Utils { public static class LockFileFormatExtensions { - - private const int NumberOfRetries = 3000; - - private static readonly TimeSpan SleepDuration = TimeSpan.FromMilliseconds(10); - public static async Task ReadWithLock(this LockFileFormat subject, string path) { return await ConcurrencyUtilities.ExecuteWithFileLockedAsync( diff --git a/src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs b/src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs deleted file mode 100644 index ac3946b96..000000000 --- a/src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace Microsoft.DotNet.Cli.Utils -{ - public class InvalidProjectException : Exception - { - public InvalidProjectException() { } - public InvalidProjectException(string message) : base(message) { } - public InvalidProjectException(string message, Exception innerException) : base(message, innerException) { } - } -} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs new file mode 100644 index 000000000..381277b96 --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetAddInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs new file mode 100644 index 000000000..5d87eb449 --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetCacheInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs new file mode 100644 index 000000000..29269b902 --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetCleanInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs new file mode 100644 index 000000000..08b297f1f --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetListInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs new file mode 100644 index 000000000..476f88fba --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetMsbuildInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs new file mode 100644 index 000000000..7fbdc0443 --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetPackInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs new file mode 100644 index 000000000..8081c19df --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetPublishInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs new file mode 100644 index 000000000..e4353a610 --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetRemoveInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs new file mode 100644 index 000000000..c178869f8 --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetRestoreInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs new file mode 100644 index 000000000..0bb0486db --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetRunInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs new file mode 100644 index 000000000..50eef976d --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetSlnInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs new file mode 100644 index 000000000..701aee7a1 --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetTestInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs new file mode 100644 index 000000000..a41c40e18 --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs @@ -0,0 +1,35 @@ +using Microsoft.DotNet.Tools.Build; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetVsTestInvocation + { + [Theory] + [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] + [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] + [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] + [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] + [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] + [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] + [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] + [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] + [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + { + var msbuildPath = ""; + BuildCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + throw new NotImplementedException(); + } + } +} From 873bb31cfa2fb2d87a3372ff8ab060c93c0f0e5e Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 10:52:23 -0800 Subject: [PATCH 02/12] Move CommandCreationException to root --- src/dotnet/CommandCreationException.cs | 16 ++++++++++++++++ src/dotnet/commands/dotnet-build/Program.cs | 10 ---------- 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 src/dotnet/CommandCreationException.cs diff --git a/src/dotnet/CommandCreationException.cs b/src/dotnet/CommandCreationException.cs new file mode 100644 index 000000000..2e437dfbb --- /dev/null +++ b/src/dotnet/CommandCreationException.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.DotNet.Cli +{ + internal class CommandCreationException : Exception + { + public int ExitCode { get; private set; } + + public CommandCreationException(int exitCode) + { + ExitCode = exitCode; + } + } +} diff --git a/src/dotnet/commands/dotnet-build/Program.cs b/src/dotnet/commands/dotnet-build/Program.cs index b29348757..abd9b2675 100644 --- a/src/dotnet/commands/dotnet-build/Program.cs +++ b/src/dotnet/commands/dotnet-build/Program.cs @@ -142,15 +142,5 @@ namespace Microsoft.DotNet.Tools.Build { return GetProcessStartInfo().Execute(); } - - private class CommandCreationException : Exception - { - public int ExitCode { get; private set; } - - public CommandCreationException(int exitCode) - { - ExitCode = exitCode; - } - } } } From 06ceb66089a0ef32f28adae20d3c164a53f6d38e Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 11:43:03 -0800 Subject: [PATCH 03/12] skip not finished tests and add restore unit tests --- src/dotnet/commands/dotnet-restore/Program.cs | 51 +++++++++++++++++-- .../GivenDotnetAddInvocation.cs | 2 +- .../GivenDotnetCacheInvocation.cs | 2 +- .../GivenDotnetCleanInvocation.cs | 2 +- .../GivenDotnetListInvocation.cs | 2 +- .../GivenDotnetMsbuildInvocation.cs | 2 +- .../GivenDotnetPackInvocation.cs | 2 +- .../GivenDotnetPublishInvocation.cs | 2 +- .../GivenDotnetRemoveInvocation.cs | 2 +- .../GivenDotnetRestoreInvocation.cs | 44 ++++++++-------- .../GivenDotnetRunInvocation.cs | 2 +- .../GivenDotnetSlnInvocation.cs | 2 +- .../GivenDotnetTestInvocation.cs | 2 +- .../GivenDotnetVsTestInvocation.cs | 2 +- 14 files changed, 82 insertions(+), 37 deletions(-) diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index fca6f25b8..a2370d5fe 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -5,12 +5,21 @@ using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; +using Microsoft.DotNet.Cli; +using System.Diagnostics; namespace Microsoft.DotNet.Tools.Restore { public class RestoreCommand { - public static int Run(string[] args) + private MSBuildForwardingApp _forwardingApp; + + public RestoreCommand(IEnumerable msbuildArgs, string msbuildPath = null) + { + _forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath); + } + + public static RestoreCommand FromArgs(string[] args, string msbuildPath = null) { DebugHelper.HandleDebugSwitch(ref args); @@ -72,9 +81,10 @@ namespace Microsoft.DotNet.Tools.Restore CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd); + List msbuildArgs = null; cmd.OnExecute(() => { - var msbuildArgs = new List() + msbuildArgs = new List() { "/NoLogo", "/t:Restore", @@ -132,10 +142,43 @@ namespace Microsoft.DotNet.Tools.Restore // Add remaining arguments that the parser did not understand msbuildArgs.AddRange(cmd.RemainingArguments); - return new MSBuildForwardingApp(msbuildArgs).Execute(); + return 0; }); - return cmd.Execute(args); + int exitCode = cmd.Execute(args); + if (msbuildArgs == null) + { + throw new CommandCreationException(exitCode); + } + + return new RestoreCommand(msbuildArgs, msbuildPath); + } + + public static int Run(string[] args) + { + DebugHelper.HandleDebugSwitch(ref args); + + RestoreCommand cmd; + try + { + cmd = FromArgs(args); + } + catch (CommandCreationException e) + { + return e.ExitCode; + } + + return cmd.Execute(); + } + + public ProcessStartInfo GetProcessStartInfo() + { + return _forwardingApp.GetProcessStartInfo(); + } + + public int Execute() + { + return GetProcessStartInfo().Execute(); } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs index 381277b96..aee2b12ec 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetAddInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs index 5d87eb449..78dd84da0 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetCacheInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs index 29269b902..c9d59384c 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetCleanInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs index 08b297f1f..4d6dc5c46 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetListInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs index 476f88fba..5676494ae 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetMsbuildInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs index 7fbdc0443..df8e6f559 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetPackInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs index 8081c19df..3c1799593 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetPublishInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs index e4353a610..928e7f660 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetRemoveInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs index c178869f8..f5c95187c 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs @@ -1,4 +1,4 @@ -using Microsoft.DotNet.Tools.Build; +using Microsoft.DotNet.Tools.Restore; using FluentAssertions; using Xunit; using System; @@ -7,29 +7,31 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetRestoreInvocation { + const string ExpectedPrefix = "exec /m /v:m /NoLogo /t:Restore /ConsoleLoggerParameters:Verbosity=Minimal"; + [Theory] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + [InlineData(new string[] { }, "")] + [InlineData(new string[] { "-s", "" }, "/p:RestoreSources=")] + [InlineData(new string[] { "--source", "" }, "/p:RestoreSources=")] + [InlineData(new string[] { "-s", "", "-s", "" }, "/p:RestoreSources=%3B")] + [InlineData(new string[] { "-r", "" }, "/p:RuntimeIdentifiers=")] + [InlineData(new string[] { "--runtime", "" }, "/p:RuntimeIdentifiers=")] + [InlineData(new string[] { "-r", "", "-r", "" }, "/p:RuntimeIdentifiers=%3B")] + [InlineData(new string[] { "--packages", "" }, "/p:RestorePackagesPath=")] + [InlineData(new string[] { "--disable-parallel" }, "/p:RestoreDisableParallel=true")] + [InlineData(new string[] { "--configfile", "" }, "/p:RestoreConfigFile=")] + [InlineData(new string[] { "--no-cache" }, "/p:RestoreNoCache=true")] + [InlineData(new string[] { "--ignore-failed-sources" }, "/p:RestoreIgnoreFailedSources=true")] + [InlineData(new string[] { "--no-dependencies" }, "/p:RestoreRecursive=false")] + [InlineData(new string[] { "-v", "" }, @"/verbosity:")] + [InlineData(new string[] { "--verbosity", "" }, @"/verbosity:")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { + expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); + var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); + RestoreCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs index 0bb0486db..e4dd3daf7 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetRunInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs index 50eef976d..3e9c36d91 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetSlnInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs index 701aee7a1..6f0ab8e46 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetTestInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs index a41c40e18..877e72a5a 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetVsTestInvocation { - [Theory] + [Theory(Skip = "finish me")] [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] From 584b4a93c0594fe054d620a0c0651b1d3495cd56 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 12:01:59 -0800 Subject: [PATCH 04/12] add dotnet pack unit tests --- .../commands/dotnet-pack/PackCommand.cs | 51 +++++++++++++++++-- .../GivenDotnetPackInvocation.cs | 46 +++++++++-------- 2 files changed, 71 insertions(+), 26 deletions(-) diff --git a/src/dotnet/commands/dotnet-pack/PackCommand.cs b/src/dotnet/commands/dotnet-pack/PackCommand.cs index 020ec778c..ee371f109 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommand.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommand.cs @@ -5,12 +5,21 @@ using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; +using Microsoft.DotNet.Cli; +using System.Diagnostics; namespace Microsoft.DotNet.Tools.Pack { public class PackCommand { - public static int Run(string[] args) + private MSBuildForwardingApp _forwardingApp; + + public PackCommand(IEnumerable msbuildArgs, string msbuildPath = null) + { + _forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath); + } + + public static PackCommand FromArgs(string[] args, string msbuildPath = null) { DebugHelper.HandleDebugSwitch(ref args); @@ -59,9 +68,10 @@ namespace Microsoft.DotNet.Tools.Pack multipleValues:true); CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd); + List msbuildArgs = null; cmd.OnExecute(() => { - var msbuildArgs = new List() + msbuildArgs = new List() { "/t:pack" }; @@ -109,10 +119,43 @@ namespace Microsoft.DotNet.Tools.Pack msbuildArgs.AddRange(argRoot.Values); msbuildArgs.AddRange(cmd.RemainingArguments); - return new MSBuildForwardingApp(msbuildArgs).Execute(); + return 0; }); - return cmd.Execute(args); + int exitCode = cmd.Execute(args); + if (msbuildArgs == null) + { + throw new CommandCreationException(exitCode); + } + + return new PackCommand(msbuildArgs, msbuildPath); + } + + public static int Run(string[] args) + { + DebugHelper.HandleDebugSwitch(ref args); + + PackCommand cmd; + try + { + cmd = FromArgs(args); + } + catch (CommandCreationException e) + { + return e.ExitCode; + } + + return cmd.Execute(); + } + + public ProcessStartInfo GetProcessStartInfo() + { + return _forwardingApp.GetProcessStartInfo(); + } + + public int Execute() + { + return GetProcessStartInfo().Execute(); } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs index df8e6f559..0a30d536f 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs @@ -1,35 +1,37 @@ -using Microsoft.DotNet.Tools.Build; +using Microsoft.DotNet.Tools.Pack; using FluentAssertions; using Xunit; using System; +using System.Linq; namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetPackInvocation { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + const string ExpectedPrefix = "exec /m /v:m /t:pack"; + + [Theory] + [InlineData(new string[] { }, "")] + [InlineData(new string[] { "-o", "" }, "/p:PackageOutputPath=")] + [InlineData(new string[] { "--output", "" }, "/p:PackageOutputPath=")] + [InlineData(new string[] { "--no-build" }, "/p:NoBuild=true")] + [InlineData(new string[] { "--include-symbols" }, "/p:IncludeSymbols=true")] + [InlineData(new string[] { "--include-source" }, "/p:IncludeSource=true")] + [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] + [InlineData(new string[] { "-s" }, "/p:Serviceable=true")] + [InlineData(new string[] { "--serviceable" }, "/p:Serviceable=true")] + [InlineData(new string[] { "-v", "" }, @"/verbosity:")] + [InlineData(new string[] { "--verbosity", "" }, @"/verbosity:")] + [InlineData(new string[] { "" }, "")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { + expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); + var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); + PackCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); } } } From 1514dd5e16917e56ba49f0eb848f28ff938d2c8f Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 12:45:11 -0800 Subject: [PATCH 05/12] add dotnet-publish unit tests --- src/dotnet/commands/dotnet-publish/Program.cs | 46 ++++++++++++++++-- .../commands/dotnet-publish/PublishCommand.cs | 13 +++-- .../GivenDotnetPublishInvocation.cs | 47 ++++++++++--------- 3 files changed, 74 insertions(+), 32 deletions(-) diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index cfaef0043..404090036 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -1,15 +1,17 @@ // 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 Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; +using System.Diagnostics; namespace Microsoft.DotNet.Tools.Publish { public partial class PublishCommand { - public static int Run(string[] args) + public static PublishCommand FromArgs(string[] args, string msbuildPath = null) { DebugHelper.HandleDebugSwitch(ref args); @@ -50,10 +52,11 @@ namespace Microsoft.DotNet.Tools.Publish CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); + var publish = new PublishCommand(msbuildPath); + bool commandExecuted = false; app.OnExecute(() => { - var publish = new PublishCommand(); - + commandExecuted = true; publish.ProjectPath = projectArgument.Value; publish.Framework = frameworkOption.Value(); publish.Runtime = runtimeOption.Value(); @@ -64,10 +67,43 @@ namespace Microsoft.DotNet.Tools.Publish publish.Verbosity = verbosityOption.Value(); publish.ExtraMSBuildArguments = app.RemainingArguments; - return publish.Execute(); + return 0; }); - return app.Execute(args); + int exitCode = app.Execute(args); + if (!commandExecuted) + { + throw new CommandCreationException(exitCode); + } + + return publish; + } + + public static int Run(string[] args) + { + DebugHelper.HandleDebugSwitch(ref args); + + PublishCommand cmd; + try + { + cmd = FromArgs(args); + } + catch (CommandCreationException e) + { + return e.ExitCode; + } + + return cmd.Execute(); + } + + public ProcessStartInfo GetProcessStartInfo() + { + return CreateForwardingApp(_msbuildPath).GetProcessStartInfo(); + } + + public int Execute() + { + return GetProcessStartInfo().Execute(); } } } diff --git a/src/dotnet/commands/dotnet-publish/PublishCommand.cs b/src/dotnet/commands/dotnet-publish/PublishCommand.cs index 767092bde..162927902 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommand.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommand.cs @@ -11,6 +11,8 @@ namespace Microsoft.DotNet.Tools.Publish { public partial class PublishCommand { + private string _msbuildPath; + public string ProjectPath { get; set; } public string Framework { get; set; } public string Runtime { get; set; } @@ -22,21 +24,22 @@ namespace Microsoft.DotNet.Tools.Publish public List ExtraMSBuildArguments { get; set; } - private PublishCommand() + private PublishCommand(string msbuildPath = null) { + _msbuildPath = msbuildPath; } - public int Execute() + private MSBuildForwardingApp CreateForwardingApp(string msbuildPath) { List msbuildArgs = new List(); + msbuildArgs.Add("/t:Publish"); + if (!string.IsNullOrEmpty(ProjectPath)) { msbuildArgs.Add(ProjectPath); } - msbuildArgs.Add("/t:Publish"); - if (!string.IsNullOrEmpty(Framework)) { msbuildArgs.Add($"/p:TargetFramework={Framework}"); @@ -74,7 +77,7 @@ namespace Microsoft.DotNet.Tools.Publish msbuildArgs.AddRange(ExtraMSBuildArguments); - return new MSBuildForwardingApp(msbuildArgs).Execute(); + return new MSBuildForwardingApp(msbuildArgs, msbuildPath); } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs index 3c1799593..d1ed249bb 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs @@ -1,35 +1,38 @@ -using Microsoft.DotNet.Tools.Build; +using Microsoft.DotNet.Tools.Publish; using FluentAssertions; using Xunit; using System; +using System.Linq; namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetPublishInvocation { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + const string ExpectedPrefix = "exec /m /v:m /t:Publish"; + + [Theory] + [InlineData(new string[] { }, "")] + [InlineData(new string[] { "-f", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "--framework", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "-r", "" }, "/p:RuntimeIdentifier=")] + [InlineData(new string[] { "--runtime", "" }, "/p:RuntimeIdentifier=")] + [InlineData(new string[] { "-o", "" }, "/p:PublishDir=")] + [InlineData(new string[] { "--output", "" }, "/p:PublishDir=")] + [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] + [InlineData(new string[] { "--filter", "" }, "/p:FilterProjFile=")] + [InlineData(new string[] { "-v", "" }, "/verbosity:")] + [InlineData(new string[] { "--verbosity", "" }, "/verbosity:")] + [InlineData(new string[] { "" }, "")] + [InlineData(new string[] { "", "" }, " ")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { + expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); + var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); + PublishCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); } } } From 22bcf2cddc2db7d1f1ebd4c1e67efd904efcb937 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 13:44:06 -0800 Subject: [PATCH 06/12] add ForwardingApp unit tests --- .../GivenForwardingApp.cs | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/dotnet-msbuild.Tests/GivenForwardingApp.cs diff --git a/test/dotnet-msbuild.Tests/GivenForwardingApp.cs b/test/dotnet-msbuild.Tests/GivenForwardingApp.cs new file mode 100644 index 000000000..cc25efd2e --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenForwardingApp.cs @@ -0,0 +1,82 @@ +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"); + } + } +} From 3415a7994029b620c4ab06196722863f2ab3bd65 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 13:53:44 -0800 Subject: [PATCH 07/12] vstest unit tests --- .../dotnet-vstest/VSTestForwardingApp.cs | 8 ++++- .../GivenDotnetVsTestForwardingApp.cs | 17 +++++++++ .../GivenDotnetVsTestInvocation.cs | 35 ------------------- 3 files changed, 24 insertions(+), 36 deletions(-) create mode 100644 test/dotnet-msbuild.Tests/GivenDotnetVsTestForwardingApp.cs delete mode 100644 test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs diff --git a/src/dotnet/commands/dotnet-vstest/VSTestForwardingApp.cs b/src/dotnet/commands/dotnet-vstest/VSTestForwardingApp.cs index 32e91070f..0359fb478 100644 --- a/src/dotnet/commands/dotnet-vstest/VSTestForwardingApp.cs +++ b/src/dotnet/commands/dotnet-vstest/VSTestForwardingApp.cs @@ -4,6 +4,7 @@ using Microsoft.DotNet.Cli.Utils; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; namespace Microsoft.DotNet.Cli @@ -20,9 +21,14 @@ namespace Microsoft.DotNet.Cli argsToForward); } + public ProcessStartInfo GetProcessStartInfo() + { + return _forwardingApp.GetProcessStartInfo(); + } + public int Execute() { - return _forwardingApp.Execute(); + return GetProcessStartInfo().Execute(); } private string GetVSTestExePath() diff --git a/test/dotnet-msbuild.Tests/GivenDotnetVsTestForwardingApp.cs b/test/dotnet-msbuild.Tests/GivenDotnetVsTestForwardingApp.cs new file mode 100644 index 000000000..34103ea84 --- /dev/null +++ b/test/dotnet-msbuild.Tests/GivenDotnetVsTestForwardingApp.cs @@ -0,0 +1,17 @@ +using Microsoft.DotNet.Tools.VSTest; +using FluentAssertions; +using Xunit; +using System; + +namespace Microsoft.DotNet.Cli.MSBuild.Tests +{ + public class GivenDotnetVsTestForwardingApp + { + [Fact] + public void ItRunsVsTestApp() + { + new VSTestForwardingApp(new string[0]) + .GetProcessStartInfo().FileName.Should().EndWith("vstest.console.dll"); + } + } +} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs deleted file mode 100644 index 877e72a5a..000000000 --- a/test/dotnet-msbuild.Tests/GivenDotnetVsTestInvocation.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.DotNet.Tools.Build; -using FluentAssertions; -using Xunit; -using System; - -namespace Microsoft.DotNet.Cli.MSBuild.Tests -{ - public class GivenDotnetVsTestInvocation - { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) - { - var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); - } - } -} From b85a2ec6f2a5a16c40bd7a7f65d854844a295702 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 15:49:39 -0800 Subject: [PATCH 08/12] unit tests for dotnet-cache invocation, some cleanup --- .../commands/dotnet-cache/CacheCommand.cs | 9 ++- src/dotnet/commands/dotnet-cache/Program.cs | 46 ++++++++++++-- .../GivenDotnetAddInvocation.cs | 35 ----------- .../GivenDotnetCacheInvocation.cs | 63 ++++++++++++------- .../GivenDotnetListInvocation.cs | 35 ----------- .../GivenDotnetMsbuildInvocation.cs | 35 ----------- .../GivenDotnetRemoveInvocation.cs | 35 ----------- .../GivenDotnetRunInvocation.cs | 35 ----------- .../GivenDotnetSlnInvocation.cs | 35 ----------- .../GivenDotnetVsTestForwardingApp.cs | 2 +- 10 files changed, 89 insertions(+), 241 deletions(-) delete mode 100644 test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs delete mode 100644 test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs delete mode 100644 test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs delete mode 100644 test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs delete mode 100644 test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs delete mode 100644 test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs diff --git a/src/dotnet/commands/dotnet-cache/CacheCommand.cs b/src/dotnet/commands/dotnet-cache/CacheCommand.cs index 1691bb6e5..4d5bc4022 100644 --- a/src/dotnet/commands/dotnet-cache/CacheCommand.cs +++ b/src/dotnet/commands/dotnet-cache/CacheCommand.cs @@ -14,6 +14,8 @@ namespace Microsoft.DotNet.Tools.Cache { public partial class CacheCommand { + private string _msbuildPath; + public string ProjectArgument { get; set; } public string Framework { get; set; } public string Runtime { get; set; } @@ -26,11 +28,12 @@ namespace Microsoft.DotNet.Tools.Cache public List ExtraMSBuildArguments { get; set; } - private CacheCommand() + private CacheCommand(string msbuildPath = null) { + _msbuildPath = msbuildPath; } - public int Execute() + private MSBuildForwardingApp CreateForwardingApp(string msbuildPath) { var msbuildArgs = new List(); @@ -85,7 +88,7 @@ namespace Microsoft.DotNet.Tools.Cache msbuildArgs.AddRange(ExtraMSBuildArguments); - return new MSBuildForwardingApp(msbuildArgs).Execute(); + return new MSBuildForwardingApp(msbuildArgs, msbuildPath); } } } diff --git a/src/dotnet/commands/dotnet-cache/Program.cs b/src/dotnet/commands/dotnet-cache/Program.cs index 3992fec48..b51dbeea2 100644 --- a/src/dotnet/commands/dotnet-cache/Program.cs +++ b/src/dotnet/commands/dotnet-cache/Program.cs @@ -5,12 +5,14 @@ using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; +using Microsoft.DotNet.Cli; +using System.Diagnostics; namespace Microsoft.DotNet.Tools.Cache { public partial class CacheCommand { - public static int Run(string[] args) + public static CacheCommand FromArgs(string[] args, string msbuildPath = null) { DebugHelper.HandleDebugSwitch(ref args); @@ -56,10 +58,11 @@ namespace Microsoft.DotNet.Tools.Cache CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); + var cache = new CacheCommand(msbuildPath); + bool commandExecuted = false; app.OnExecute(() => { - var cache = new CacheCommand(); - + commandExecuted = true; cache.Framework = frameworkOption.Value(); cache.Runtime = runtimeOption.Value(); cache.OutputPath = outputOption.Value(); @@ -71,10 +74,43 @@ namespace Microsoft.DotNet.Tools.Cache cache.ExtraMSBuildArguments = app.RemainingArguments; cache.ProjectArgument = projectArgument.Value(); - return cache.Execute(); + return 0; }); - return app.Execute(args); + int exitCode = app.Execute(args); + if (!commandExecuted) + { + throw new CommandCreationException(exitCode); + } + + return cache; + } + + public static int Run(string[] args) + { + DebugHelper.HandleDebugSwitch(ref args); + + CacheCommand cmd; + try + { + cmd = FromArgs(args); + } + catch (CommandCreationException e) + { + return e.ExitCode; + } + + return cmd.Execute(); + } + + public ProcessStartInfo GetProcessStartInfo() + { + return CreateForwardingApp(_msbuildPath).GetProcessStartInfo(); + } + + public int Execute() + { + return GetProcessStartInfo().Execute(); } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs deleted file mode 100644 index aee2b12ec..000000000 --- a/test/dotnet-msbuild.Tests/GivenDotnetAddInvocation.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.DotNet.Tools.Build; -using FluentAssertions; -using Xunit; -using System; - -namespace Microsoft.DotNet.Cli.MSBuild.Tests -{ - public class GivenDotnetAddInvocation - { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) - { - var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); - } - } -} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs index 78dd84da0..d7c0740d0 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs @@ -1,35 +1,54 @@ -using Microsoft.DotNet.Tools.Build; +using Microsoft.DotNet.Tools.Cache; using FluentAssertions; using Xunit; using System; +using System.Linq; +using System.IO; namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetCacheInvocation { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + const string ExpectedPrefix = "exec /m /v:m /t:ComposeCache "; + static readonly string[] ArgsPrefix = { "-e", "" }; + + [Theory] + [InlineData("-e")] + [InlineData("--entries")] + public void ItAddsProjectToMsbuildInvocation(string optionName) { var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); + string[] args = new string[] { optionName, "" }; + CacheCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}"); + } + + [Theory] + [InlineData(new string[] { "-f", "" }, @"/p:TargetFramework=")] + [InlineData(new string[] { "--framework", "" }, @"/p:TargetFramework=")] + [InlineData(new string[] { "-r", "" }, @"/p:RuntimeIdentifier=")] + [InlineData(new string[] { "--runtime", "" }, @"/p:RuntimeIdentifier=")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) + { + args = ArgsPrefix.Concat(args).ToArray(); + expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); + + var msbuildPath = ""; + CacheCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); + } + + [Theory] + [InlineData("-o")] + [InlineData("--output")] + public void ItAddsOutputPathToMsBuildInvocation(string optionName) + { + string path = "/some/path"; + var args = ArgsPrefix.Concat(new string[] { optionName, path }).ToArray(); + + var msbuildPath = ""; + CacheCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix} /p:ComposeDir={Path.GetFullPath(path)}"); } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs deleted file mode 100644 index 4d6dc5c46..000000000 --- a/test/dotnet-msbuild.Tests/GivenDotnetListInvocation.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.DotNet.Tools.Build; -using FluentAssertions; -using Xunit; -using System; - -namespace Microsoft.DotNet.Cli.MSBuild.Tests -{ - public class GivenDotnetListInvocation - { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) - { - var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); - } - } -} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs deleted file mode 100644 index 5676494ae..000000000 --- a/test/dotnet-msbuild.Tests/GivenDotnetMsbuildInvocation.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.DotNet.Tools.Build; -using FluentAssertions; -using Xunit; -using System; - -namespace Microsoft.DotNet.Cli.MSBuild.Tests -{ - public class GivenDotnetMsbuildInvocation - { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) - { - var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); - } - } -} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs deleted file mode 100644 index 928e7f660..000000000 --- a/test/dotnet-msbuild.Tests/GivenDotnetRemoveInvocation.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.DotNet.Tools.Build; -using FluentAssertions; -using Xunit; -using System; - -namespace Microsoft.DotNet.Cli.MSBuild.Tests -{ - public class GivenDotnetRemoveInvocation - { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) - { - var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); - } - } -} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs deleted file mode 100644 index e4dd3daf7..000000000 --- a/test/dotnet-msbuild.Tests/GivenDotnetRunInvocation.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.DotNet.Tools.Build; -using FluentAssertions; -using Xunit; -using System; - -namespace Microsoft.DotNet.Cli.MSBuild.Tests -{ - public class GivenDotnetRunInvocation - { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) - { - var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); - } - } -} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs deleted file mode 100644 index 3e9c36d91..000000000 --- a/test/dotnet-msbuild.Tests/GivenDotnetSlnInvocation.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.DotNet.Tools.Build; -using FluentAssertions; -using Xunit; -using System; - -namespace Microsoft.DotNet.Cli.MSBuild.Tests -{ - public class GivenDotnetSlnInvocation - { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) - { - var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); - } - } -} diff --git a/test/dotnet-msbuild.Tests/GivenDotnetVsTestForwardingApp.cs b/test/dotnet-msbuild.Tests/GivenDotnetVsTestForwardingApp.cs index 34103ea84..e1bf1d752 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetVsTestForwardingApp.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetVsTestForwardingApp.cs @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests public void ItRunsVsTestApp() { new VSTestForwardingApp(new string[0]) - .GetProcessStartInfo().FileName.Should().EndWith("vstest.console.dll"); + .GetProcessStartInfo().Arguments.Should().EndWith("vstest.console.dll"); } } } From eddca32b2fc43751928b2abe8f705a7c973bed52 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 17:40:02 -0800 Subject: [PATCH 09/12] add dotnet clean unit tests --- src/dotnet/commands/dotnet-clean/Program.cs | 51 +++++++++++++++++-- .../GivenDotnetBuildInvocation.cs | 41 ++++++++------- .../GivenDotnetCleanInvocation.cs | 48 +++++++++-------- 3 files changed, 96 insertions(+), 44 deletions(-) diff --git a/src/dotnet/commands/dotnet-clean/Program.cs b/src/dotnet/commands/dotnet-clean/Program.cs index 1d881efc8..72ad61575 100644 --- a/src/dotnet/commands/dotnet-clean/Program.cs +++ b/src/dotnet/commands/dotnet-clean/Program.cs @@ -5,12 +5,21 @@ using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; +using Microsoft.DotNet.Cli; +using System.Diagnostics; namespace Microsoft.DotNet.Tools.Clean { public class CleanCommand { - public static int Run(string[] args) + private MSBuildForwardingApp _forwardingApp; + + public CleanCommand(IEnumerable msbuildArgs, string msbuildPath = null) + { + _forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath); + } + + public static CleanCommand FromArgs(string[] args, string msbuildPath = null) { DebugHelper.HandleDebugSwitch(ref args); @@ -42,9 +51,10 @@ namespace Microsoft.DotNet.Tools.Clean CommandOptionType.SingleValue); CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); + List msbuildArgs = null; app.OnExecute(() => { - List msbuildArgs = new List(); + msbuildArgs = new List(); if (!string.IsNullOrEmpty(projectArgument.Value)) { @@ -75,10 +85,43 @@ namespace Microsoft.DotNet.Tools.Clean msbuildArgs.AddRange(app.RemainingArguments); - return new MSBuildForwardingApp(msbuildArgs).Execute(); + return 0; }); - return app.Execute(args); + int exitCode = app.Execute(args); + if (msbuildArgs == null) + { + throw new CommandCreationException(exitCode); + } + + return new CleanCommand(msbuildArgs, msbuildPath); + } + + public static int Run(string[] args) + { + DebugHelper.HandleDebugSwitch(ref args); + + CleanCommand cmd; + try + { + cmd = FromArgs(args); + } + catch (CommandCreationException e) + { + return e.ExitCode; + } + + return cmd.Execute(); + } + + public ProcessStartInfo GetProcessStartInfo() + { + return _forwardingApp.GetProcessStartInfo(); + } + + public int Execute() + { + return GetProcessStartInfo().Execute(); } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs index 457297d45..72e412172 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs @@ -6,28 +6,33 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetBuildInvocation { + const string ExpectedPrefix = "exec /m /v:m"; + const string ExpectedSuffix = "/clp:Summary"; + [Theory] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + [InlineData(new string[] { }, "/t:Build")] + [InlineData(new string[] { "-o", "foo" }, "/t:Build /p:OutputPath=foo")] + [InlineData(new string[] { "--output", "foo" }, "/t:Build /p:OutputPath=foo")] + [InlineData(new string[] { "-o", "foo1 foo2" }, "/t:Build \"/p:OutputPath=foo1 foo2\"")] + [InlineData(new string[] { "--no-incremental" }, "/t:Rebuild")] + [InlineData(new string[] { "-f", "framework" }, "/t:Build /p:TargetFramework=framework")] + [InlineData(new string[] { "--framework", "framework" }, "/t:Build /p:TargetFramework=framework")] + [InlineData(new string[] { "-r", "runtime" }, "/t:Build /p:RuntimeIdentifier=runtime")] + [InlineData(new string[] { "--runtime", "runtime" }, "/t:Build /p:RuntimeIdentifier=runtime")] + [InlineData(new string[] { "-c", "configuration" }, "/t:Build /p:Configuration=configuration")] + [InlineData(new string[] { "--configuration", "configuration" }, "/t:Build /p:Configuration=configuration")] + [InlineData(new string[] { "--version-suffix", "mysuffix" }, "/t:Build /p:VersionSuffix=mysuffix")] + [InlineData(new string[] { "--no-dependencies" }, "/t:Build /p:BuildProjectReferences=false")] + [InlineData(new string[] { "-v", "verbosity" }, "/t:Build /verbosity:verbosity")] + [InlineData(new string[] { "--verbosity", "verbosity" }, "/t:Build /verbosity:verbosity")] + [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, "/t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { + expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); + var msbuildPath = ""; BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); + .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs} {ExpectedSuffix}"); } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs index c9d59384c..8817d3f02 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs @@ -1,4 +1,4 @@ -using Microsoft.DotNet.Tools.Build; +using Microsoft.DotNet.Tools.Clean; using FluentAssertions; using Xunit; using System; @@ -7,29 +7,33 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetCleanInvocation { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) + const string ExpectedPrefix = "exec /m /v:m /t:Clean"; + + [Fact] + public void ItAddsProjectToMsbuildInvocation() { var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); + CleanCommand.FromArgs(new string[] { "" }, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be("exec /m /v:m /t:Clean"); + } + + [Theory] + [InlineData(new string[] { }, "")] + [InlineData(new string[] { "-o", "" }, "/p:OutputPath=")] + [InlineData(new string[] { "--output", "" }, "/p:OutputPath=")] + [InlineData(new string[] { "-f", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "--framework", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] + [InlineData(new string[] { "-v", "" }, "/verbosity:")] + [InlineData(new string[] { "--verbosity", "" }, "/verbosity:")] + public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) + { + expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); + + var msbuildPath = ""; + CleanCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); } } } From de7587782e7a0799af545e4f16ff0b92eb00c98a Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 22 Feb 2017 17:41:20 -0800 Subject: [PATCH 10/12] remove dotnet test unit test stub --- .../GivenDotnetTestInvocation.cs | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs diff --git a/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs deleted file mode 100644 index 6f0ab8e46..000000000 --- a/test/dotnet-msbuild.Tests/GivenDotnetTestInvocation.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.DotNet.Tools.Build; -using FluentAssertions; -using Xunit; -using System; - -namespace Microsoft.DotNet.Cli.MSBuild.Tests -{ - public class GivenDotnetTestInvocation - { - [Theory(Skip = "finish me")] - [InlineData(new string[] { }, @"exec /m /v:m /t:Build /clp:Summary")] - [InlineData(new string[] { "-o", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "--output", "foo" }, @"exec /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")] - [InlineData(new string[] { "-o", "foo1 foo2" }, @"exec /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")] - [InlineData(new string[] { "--no-incremental" }, @"exec /m /v:m /t:Rebuild /clp:Summary")] - [InlineData(new string[] { "-f", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "--framework", "framework" }, @"exec /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")] - [InlineData(new string[] { "-r", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "--runtime", "runtime" }, @"exec /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")] - [InlineData(new string[] { "-c", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--configuration", "configuration" }, @"exec /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")] - [InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")] - [InlineData(new string[] { "--no-dependencies" }, @"exec /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")] - [InlineData(new string[] { "-v", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--verbosity", "verbosity" }, @"exec /m /v:m /t:Build /verbosity:verbosity /clp:Summary")] - [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedCommand) - { - var msbuildPath = ""; - BuildCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be(expectedCommand); - throw new NotImplementedException(); - } - } -} From c75d2e446e5782b260f826e959daa2a1a91eb56c Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Thu, 23 Feb 2017 11:24:36 -0800 Subject: [PATCH 11/12] reduce some repetition --- src/dotnet/commands/dotnet-build/Program.cs | 16 +--- .../commands/dotnet-cache/CacheCommand.cs | 95 ------------------- src/dotnet/commands/dotnet-cache/Program.cs | 91 ++++++++++++------ src/dotnet/commands/dotnet-clean/Program.cs | 18 +--- .../commands/dotnet-pack/PackCommand.cs | 18 +--- src/dotnet/commands/dotnet-publish/Program.cs | 82 +++++++++++----- .../commands/dotnet-publish/PublishCommand.cs | 83 ---------------- .../dotnet-vstest/VSTestForwardingApp.cs | 19 +--- 8 files changed, 131 insertions(+), 291 deletions(-) delete mode 100644 src/dotnet/commands/dotnet-cache/CacheCommand.cs delete mode 100644 src/dotnet/commands/dotnet-publish/PublishCommand.cs diff --git a/src/dotnet/commands/dotnet-build/Program.cs b/src/dotnet/commands/dotnet-build/Program.cs index abd9b2675..1bf412224 100644 --- a/src/dotnet/commands/dotnet-build/Program.cs +++ b/src/dotnet/commands/dotnet-build/Program.cs @@ -11,13 +11,11 @@ using Microsoft.DotNet.Cli; namespace Microsoft.DotNet.Tools.Build { - public class BuildCommand + public class BuildCommand : MSBuildForwardingApp { - private MSBuildForwardingApp _forwardingApp; - public BuildCommand(IEnumerable msbuildArgs, string msbuildPath = null) + : base(msbuildArgs, msbuildPath) { - _forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath); } public static BuildCommand FromArgs(string[] args, string msbuildPath = null) @@ -132,15 +130,5 @@ namespace Microsoft.DotNet.Tools.Build return cmd.Execute(); } - - public ProcessStartInfo GetProcessStartInfo() - { - return _forwardingApp.GetProcessStartInfo(); - } - - public int Execute() - { - return GetProcessStartInfo().Execute(); - } } } diff --git a/src/dotnet/commands/dotnet-cache/CacheCommand.cs b/src/dotnet/commands/dotnet-cache/CacheCommand.cs deleted file mode 100644 index 4d5bc4022..000000000 --- a/src/dotnet/commands/dotnet-cache/CacheCommand.cs +++ /dev/null @@ -1,95 +0,0 @@ -// 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.Linq; -using System.Collections.Generic; -using System.IO; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools.MSBuild; -using Microsoft.DotNet.Tools.Restore; -using Microsoft.DotNet.Cli.CommandLine; - -namespace Microsoft.DotNet.Tools.Cache -{ - public partial class CacheCommand - { - private string _msbuildPath; - - public string ProjectArgument { get; set; } - public string Framework { get; set; } - public string Runtime { get; set; } - public string OutputPath { get; set; } - public string FrameworkVersion { get; set; } - public string IntermediateDir { get; set; } - public string Verbosity { get; set; } - private bool SkipOptimization { get; set; } - private bool PreserveIntermediateDir { get; set; } - - public List ExtraMSBuildArguments { get; set; } - - private CacheCommand(string msbuildPath = null) - { - _msbuildPath = msbuildPath; - } - - private MSBuildForwardingApp CreateForwardingApp(string msbuildPath) - { - var msbuildArgs = new List(); - - if (string.IsNullOrEmpty(ProjectArgument)) - { - throw new InvalidOperationException(LocalizableStrings.SpecifyEntries); - } - - msbuildArgs.Add("/t:ComposeCache"); - msbuildArgs.Add(ProjectArgument); - - if (!string.IsNullOrEmpty(Framework)) - { - msbuildArgs.Add($"/p:TargetFramework={Framework}"); - } - - if (!string.IsNullOrEmpty(Runtime)) - { - msbuildArgs.Add($"/p:RuntimeIdentifier={Runtime}"); - } - - if (!string.IsNullOrEmpty(OutputPath)) - { - OutputPath = Path.GetFullPath(OutputPath); - msbuildArgs.Add($"/p:ComposeDir={OutputPath}"); - } - - if (!string.IsNullOrEmpty(FrameworkVersion)) - { - msbuildArgs.Add($"/p:FX_Version={FrameworkVersion}"); - } - - if (!string.IsNullOrEmpty(IntermediateDir)) - { - msbuildArgs.Add($"/p:ComposeWorkingDir={IntermediateDir}"); - } - - if (SkipOptimization) - { - msbuildArgs.Add($"/p:SkipOptimization={SkipOptimization}"); - } - - if (PreserveIntermediateDir) - { - msbuildArgs.Add($"/p:PreserveComposeWorkingDir={PreserveIntermediateDir}"); - } - - if (!string.IsNullOrEmpty(Verbosity)) - { - msbuildArgs.Add($"/verbosity:{Verbosity}"); - } - - msbuildArgs.AddRange(ExtraMSBuildArguments); - - return new MSBuildForwardingApp(msbuildArgs, msbuildPath); - } - } -} - diff --git a/src/dotnet/commands/dotnet-cache/Program.cs b/src/dotnet/commands/dotnet-cache/Program.cs index b51dbeea2..2e995ea42 100644 --- a/src/dotnet/commands/dotnet-cache/Program.cs +++ b/src/dotnet/commands/dotnet-cache/Program.cs @@ -7,11 +7,18 @@ using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Cli; using System.Diagnostics; +using System; +using System.IO; namespace Microsoft.DotNet.Tools.Cache { - public partial class CacheCommand + public partial class CacheCommand : MSBuildForwardingApp { + private CacheCommand(IEnumerable msbuildArgs, string msbuildPath = null) + : base(msbuildArgs, msbuildPath) + { + } + public static CacheCommand FromArgs(string[] args, string msbuildPath = null) { DebugHelper.HandleDebugSwitch(ref args); @@ -58,32 +65,72 @@ namespace Microsoft.DotNet.Tools.Cache CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); - var cache = new CacheCommand(msbuildPath); - bool commandExecuted = false; + List msbuildArgs = null; app.OnExecute(() => { - commandExecuted = true; - cache.Framework = frameworkOption.Value(); - cache.Runtime = runtimeOption.Value(); - cache.OutputPath = outputOption.Value(); - cache.FrameworkVersion = fxOption.Value(); - cache.Verbosity = verbosityOption.Value(); - cache.SkipOptimization = skipOptimizationOption.HasValue(); - cache.IntermediateDir = workingDir.Value(); - cache.PreserveIntermediateDir = preserveWorkingDir.HasValue(); - cache.ExtraMSBuildArguments = app.RemainingArguments; - cache.ProjectArgument = projectArgument.Value(); - + msbuildArgs = new List(); + + if (string.IsNullOrEmpty(projectArgument.Value())) + { + throw new InvalidOperationException(LocalizableStrings.SpecifyEntries); + } + + msbuildArgs.Add("/t:ComposeCache"); + msbuildArgs.Add(projectArgument.Value()); + + if (!string.IsNullOrEmpty(frameworkOption.Value())) + { + msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); + } + + if (!string.IsNullOrEmpty(runtimeOption.Value())) + { + msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}"); + } + + if (!string.IsNullOrEmpty(outputOption.Value())) + { + var outputPath = Path.GetFullPath(outputOption.Value()); + msbuildArgs.Add($"/p:ComposeDir={outputPath}"); + } + + if (!string.IsNullOrEmpty(fxOption.Value())) + { + msbuildArgs.Add($"/p:FX_Version={fxOption.Value()}"); + } + + if (!string.IsNullOrEmpty(workingDir.Value())) + { + msbuildArgs.Add($"/p:ComposeWorkingDir={workingDir.Value()}"); + } + + if (skipOptimizationOption.HasValue()) + { + msbuildArgs.Add($"/p:SkipOptimization={skipOptimizationOption.HasValue()}"); + } + + if (preserveWorkingDir.HasValue()) + { + msbuildArgs.Add($"/p:PreserveComposeWorkingDir={preserveWorkingDir.HasValue()}"); + } + + if (!string.IsNullOrEmpty(verbosityOption.Value())) + { + msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); + } + + msbuildArgs.AddRange(app.RemainingArguments); + return 0; }); int exitCode = app.Execute(args); - if (!commandExecuted) + if (msbuildArgs == null) { throw new CommandCreationException(exitCode); } - return cache; + return new CacheCommand(msbuildArgs, msbuildPath); } public static int Run(string[] args) @@ -102,15 +149,5 @@ namespace Microsoft.DotNet.Tools.Cache return cmd.Execute(); } - - public ProcessStartInfo GetProcessStartInfo() - { - return CreateForwardingApp(_msbuildPath).GetProcessStartInfo(); - } - - public int Execute() - { - return GetProcessStartInfo().Execute(); - } } } diff --git a/src/dotnet/commands/dotnet-clean/Program.cs b/src/dotnet/commands/dotnet-clean/Program.cs index 72ad61575..f76e25b84 100644 --- a/src/dotnet/commands/dotnet-clean/Program.cs +++ b/src/dotnet/commands/dotnet-clean/Program.cs @@ -10,13 +10,11 @@ using System.Diagnostics; namespace Microsoft.DotNet.Tools.Clean { - public class CleanCommand + public class CleanCommand : MSBuildForwardingApp { - private MSBuildForwardingApp _forwardingApp; - public CleanCommand(IEnumerable msbuildArgs, string msbuildPath = null) + : base(msbuildArgs, msbuildPath) { - _forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath); } public static CleanCommand FromArgs(string[] args, string msbuildPath = null) @@ -49,7 +47,7 @@ namespace Microsoft.DotNet.Tools.Clean $"-c|--configuration <{LocalizableStrings.CmdConfiguration}>", LocalizableStrings.CmdConfigurationDescription, CommandOptionType.SingleValue); - CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); + CommandOption verbosityOption = AddVerbosityOption(app); List msbuildArgs = null; app.OnExecute(() => @@ -113,15 +111,5 @@ namespace Microsoft.DotNet.Tools.Clean return cmd.Execute(); } - - public ProcessStartInfo GetProcessStartInfo() - { - return _forwardingApp.GetProcessStartInfo(); - } - - public int Execute() - { - return GetProcessStartInfo().Execute(); - } } } diff --git a/src/dotnet/commands/dotnet-pack/PackCommand.cs b/src/dotnet/commands/dotnet-pack/PackCommand.cs index ee371f109..31de05df5 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommand.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommand.cs @@ -10,13 +10,11 @@ using System.Diagnostics; namespace Microsoft.DotNet.Tools.Pack { - public class PackCommand + public class PackCommand : MSBuildForwardingApp { - private MSBuildForwardingApp _forwardingApp; - public PackCommand(IEnumerable msbuildArgs, string msbuildPath = null) + : base(msbuildArgs, msbuildPath) { - _forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath); } public static PackCommand FromArgs(string[] args, string msbuildPath = null) @@ -66,7 +64,7 @@ namespace Microsoft.DotNet.Tools.Pack $"<{LocalizableStrings.CmdArgumentProject}>", LocalizableStrings.CmdArgumentDescription, multipleValues:true); - CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd); + CommandOption verbosityOption = AddVerbosityOption(cmd); List msbuildArgs = null; cmd.OnExecute(() => @@ -147,15 +145,5 @@ namespace Microsoft.DotNet.Tools.Pack return cmd.Execute(); } - - public ProcessStartInfo GetProcessStartInfo() - { - return _forwardingApp.GetProcessStartInfo(); - } - - public int Execute() - { - return GetProcessStartInfo().Execute(); - } } } diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index 404090036..c74db0d40 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -5,12 +5,18 @@ using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; +using System.Collections.Generic; using System.Diagnostics; namespace Microsoft.DotNet.Tools.Publish { - public partial class PublishCommand + public partial class PublishCommand : MSBuildForwardingApp { + private PublishCommand(IEnumerable msbuildArgs, string msbuildPath = null) + : base(msbuildArgs, msbuildPath) + { + } + public static PublishCommand FromArgs(string[] args, string msbuildPath = null) { DebugHelper.HandleDebugSwitch(ref args); @@ -50,33 +56,67 @@ namespace Microsoft.DotNet.Tools.Publish $"--filter <{LocalizableStrings.FilterProjOption}>", LocalizableStrings.FilterProjOptionDescription, CommandOptionType.SingleValue); - CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); + CommandOption verbosityOption = AddVerbosityOption(app); - var publish = new PublishCommand(msbuildPath); - bool commandExecuted = false; + List msbuildArgs = null; app.OnExecute(() => { - commandExecuted = true; - publish.ProjectPath = projectArgument.Value; - publish.Framework = frameworkOption.Value(); - publish.Runtime = runtimeOption.Value(); - publish.OutputPath = outputOption.Value(); - publish.Configuration = configurationOption.Value(); - publish.VersionSuffix = versionSuffixOption.Value(); - publish.FilterProject = filterProjOption.Value(); - publish.Verbosity = verbosityOption.Value(); - publish.ExtraMSBuildArguments = app.RemainingArguments; + msbuildArgs = new List(); + + msbuildArgs.Add("/t:Publish"); + + if (!string.IsNullOrEmpty(projectArgument.Value)) + { + msbuildArgs.Add(projectArgument.Value); + } + + if (!string.IsNullOrEmpty(frameworkOption.Value())) + { + msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); + } + + if (!string.IsNullOrEmpty(runtimeOption.Value())) + { + msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}"); + } + + if (!string.IsNullOrEmpty(outputOption.Value())) + { + msbuildArgs.Add($"/p:PublishDir={outputOption.Value()}"); + } + + if (!string.IsNullOrEmpty(configurationOption.Value())) + { + msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}"); + } + + if (!string.IsNullOrEmpty(versionSuffixOption.Value())) + { + msbuildArgs.Add($"/p:VersionSuffix={versionSuffixOption.Value()}"); + } + + if (!string.IsNullOrEmpty(filterProjOption.Value())) + { + msbuildArgs.Add($"/p:FilterProjFile={filterProjOption.Value()}"); + } + + if (!string.IsNullOrEmpty(verbosityOption.Value())) + { + msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); + } + + msbuildArgs.AddRange(app.RemainingArguments); return 0; }); int exitCode = app.Execute(args); - if (!commandExecuted) + if (msbuildArgs == null) { throw new CommandCreationException(exitCode); } - return publish; + return new PublishCommand(msbuildArgs, msbuildPath); } public static int Run(string[] args) @@ -95,15 +135,5 @@ namespace Microsoft.DotNet.Tools.Publish return cmd.Execute(); } - - public ProcessStartInfo GetProcessStartInfo() - { - return CreateForwardingApp(_msbuildPath).GetProcessStartInfo(); - } - - public int Execute() - { - return GetProcessStartInfo().Execute(); - } } } diff --git a/src/dotnet/commands/dotnet-publish/PublishCommand.cs b/src/dotnet/commands/dotnet-publish/PublishCommand.cs deleted file mode 100644 index 162927902..000000000 --- a/src/dotnet/commands/dotnet-publish/PublishCommand.cs +++ /dev/null @@ -1,83 +0,0 @@ -// 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.Linq; -using System.Collections.Generic; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools.MSBuild; -using Microsoft.DotNet.Tools.Restore; - -namespace Microsoft.DotNet.Tools.Publish -{ - public partial class PublishCommand - { - private string _msbuildPath; - - public string ProjectPath { get; set; } - public string Framework { get; set; } - public string Runtime { get; set; } - public string OutputPath { get; set; } - public string Configuration { get; set; } - public string VersionSuffix { get; set; } - public string FilterProject { get; set; } - public string Verbosity { get; set; } - - public List ExtraMSBuildArguments { get; set; } - - private PublishCommand(string msbuildPath = null) - { - _msbuildPath = msbuildPath; - } - - private MSBuildForwardingApp CreateForwardingApp(string msbuildPath) - { - List msbuildArgs = new List(); - - msbuildArgs.Add("/t:Publish"); - - if (!string.IsNullOrEmpty(ProjectPath)) - { - msbuildArgs.Add(ProjectPath); - } - - if (!string.IsNullOrEmpty(Framework)) - { - msbuildArgs.Add($"/p:TargetFramework={Framework}"); - } - - if (!string.IsNullOrEmpty(Runtime)) - { - msbuildArgs.Add($"/p:RuntimeIdentifier={Runtime}"); - } - - if (!string.IsNullOrEmpty(OutputPath)) - { - msbuildArgs.Add($"/p:PublishDir={OutputPath}"); - } - - if (!string.IsNullOrEmpty(Configuration)) - { - msbuildArgs.Add($"/p:Configuration={Configuration}"); - } - - if (!string.IsNullOrEmpty(VersionSuffix)) - { - msbuildArgs.Add($"/p:VersionSuffix={VersionSuffix}"); - } - - if (!string.IsNullOrEmpty(FilterProject)) - { - msbuildArgs.Add($"/p:FilterProjFile={FilterProject}"); - } - - if (!string.IsNullOrEmpty(Verbosity)) - { - msbuildArgs.Add($"/verbosity:{Verbosity}"); - } - - msbuildArgs.AddRange(ExtraMSBuildArguments); - - return new MSBuildForwardingApp(msbuildArgs, msbuildPath); - } - } -} diff --git a/src/dotnet/commands/dotnet-vstest/VSTestForwardingApp.cs b/src/dotnet/commands/dotnet-vstest/VSTestForwardingApp.cs index 0359fb478..8c91b1bfc 100644 --- a/src/dotnet/commands/dotnet-vstest/VSTestForwardingApp.cs +++ b/src/dotnet/commands/dotnet-vstest/VSTestForwardingApp.cs @@ -9,29 +9,16 @@ using System.IO; namespace Microsoft.DotNet.Cli { - public class VSTestForwardingApp + public class VSTestForwardingApp : ForwardingApp { private const string VstestAppName = "vstest.console.dll"; - private readonly ForwardingApp _forwardingApp; public VSTestForwardingApp(IEnumerable argsToForward) + : base(GetVSTestExePath(), argsToForward) { - _forwardingApp = new ForwardingApp( - GetVSTestExePath(), - argsToForward); } - public ProcessStartInfo GetProcessStartInfo() - { - return _forwardingApp.GetProcessStartInfo(); - } - - public int Execute() - { - return GetProcessStartInfo().Execute(); - } - - private string GetVSTestExePath() + private static string GetVSTestExePath() { return Path.Combine(AppContext.BaseDirectory, VstestAppName); } From 3a3025b3af95591f97582944474ed0379917d1f6 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Thu, 23 Feb 2017 11:31:48 -0800 Subject: [PATCH 12/12] remove duplication in dotnet-restore --- src/dotnet/commands/dotnet-restore/Program.cs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index a2370d5fe..2ba2e350e 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -10,13 +10,11 @@ using System.Diagnostics; namespace Microsoft.DotNet.Tools.Restore { - public class RestoreCommand + public class RestoreCommand : MSBuildForwardingApp { - private MSBuildForwardingApp _forwardingApp; - public RestoreCommand(IEnumerable msbuildArgs, string msbuildPath = null) + : base(msbuildArgs, msbuildPath) { - _forwardingApp = new MSBuildForwardingApp(msbuildArgs, msbuildPath); } public static RestoreCommand FromArgs(string[] args, string msbuildPath = null) @@ -170,15 +168,5 @@ namespace Microsoft.DotNet.Tools.Restore return cmd.Execute(); } - - public ProcessStartInfo GetProcessStartInfo() - { - return _forwardingApp.GetProcessStartInfo(); - } - - public int Execute() - { - return GetProcessStartInfo().Execute(); - } } }