2017-03-02 21:04:03 -08:00
// 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.
2017-02-22 10:43:05 -08:00
using FluentAssertions ;
2017-04-10 14:24:52 -05:00
using Microsoft.DotNet.Tools.Store ;
2017-02-22 15:49:39 -08:00
using System.IO ;
2017-04-10 14:24:52 -05:00
using System.Linq ;
using Xunit ;
2017-02-22 10:43:05 -08:00
namespace Microsoft.DotNet.Cli.MSBuild.Tests
{
2017-04-07 14:15:38 -05:00
public class GivenDotnetStoreInvocation
2017-02-22 10:43:05 -08:00
{
2018-04-02 15:14:32 -07:00
const string ExpectedPrefix = "exec <msbuildpath> -maxcpucount -verbosity:m -target:ComposeStore <project>" ;
static readonly string [ ] ArgsPrefix = { "--manifest" , "<project>" } ;
2017-02-22 15:49:39 -08:00
[Theory]
2017-04-07 14:15:38 -05:00
[InlineData("-m")]
[InlineData("--manifest")]
2017-02-22 15:49:39 -08:00
public void ItAddsProjectToMsbuildInvocation ( string optionName )
{
var msbuildPath = "<msbuildpath>" ;
string [ ] args = new string [ ] { optionName , "<project>" } ;
2017-04-07 14:15:38 -05:00
StoreCommand . FromArgs ( args , msbuildPath )
2017-02-22 15:49:39 -08:00
. GetProcessStartInfo ( ) . Arguments . Should ( ) . Be ( $"{ExpectedPrefix}" ) ;
}
[Theory]
2018-05-31 21:20:25 -07:00
[InlineData(new string[] { "-f" , "<tfm>" } , @"-property:TargetFramework=<tfm>" ) ]
[InlineData(new string[] { "--framework" , "<tfm>" } , @"-property:TargetFramework=<tfm>" ) ]
[InlineData(new string[] { "-r" , "<rid>" } , @"-property:RuntimeIdentifier=<rid>" ) ]
[InlineData(new string[] { "--runtime" , "<rid>" } , @"-property:RuntimeIdentifier=<rid>" ) ]
[InlineData(new string[] { "--manifest" , "one.xml" , "--manifest" , "two.xml" , "--manifest" , "three.xml" } , @"-property:AdditionalProjects=one.xml%3Btwo.xml%3Bthree.xml" ) ]
2017-02-22 15:49:39 -08:00
public void MsbuildInvocationIsCorrect ( string [ ] args , string expectedAdditionalArgs )
2017-02-22 10:43:05 -08:00
{
2017-02-22 15:49:39 -08:00
args = ArgsPrefix . Concat ( args ) . ToArray ( ) ;
expectedAdditionalArgs = ( string . IsNullOrEmpty ( expectedAdditionalArgs ) ? "" : $" {expectedAdditionalArgs}" ) ;
var msbuildPath = "<msbuildpath>" ;
2017-04-07 14:15:38 -05:00
StoreCommand . FromArgs ( args , msbuildPath )
2017-02-22 15:49:39 -08:00
. GetProcessStartInfo ( ) . Arguments . Should ( ) . Be ( $"{ExpectedPrefix}{expectedAdditionalArgs}" ) ;
}
[Theory]
[InlineData("-o")]
[InlineData("--output")]
public void ItAddsOutputPathToMsBuildInvocation ( string optionName )
{
2017-03-16 23:15:45 -07:00
string path = "/some/path" ;
2017-02-22 15:49:39 -08:00
var args = ArgsPrefix . Concat ( new string [ ] { optionName , path } ) . ToArray ( ) ;
2017-02-22 10:43:05 -08:00
var msbuildPath = "<msbuildpath>" ;
2017-04-07 14:15:38 -05:00
StoreCommand . FromArgs ( args , msbuildPath )
2018-05-31 21:20:25 -07:00
. GetProcessStartInfo ( ) . Arguments . Should ( ) . Be ( $"{ExpectedPrefix} -property:ComposeDir={Path.GetFullPath(path)}" ) ;
2017-02-22 10:43:05 -08:00
}
}
}