2016-06-17 16:16:09 -07: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.
using System ;
using System.IO ;
using FluentAssertions ;
2017-06-13 00:04:25 -07:00
using Microsoft.DotNet.TestFramework ;
2016-06-17 16:16:09 -07:00
using Microsoft.DotNet.Tools.Test.Utilities ;
using Xunit ;
2016-12-18 00:45:25 -08:00
using System.Linq ;
2016-06-17 16:16:09 -07:00
2016-10-27 18:46:43 -07:00
namespace Microsoft.DotNet.Cli.Build.Tests
2016-06-17 16:16:09 -07:00
{
2016-10-27 18:46:43 -07:00
public class GivenDotnetBuildBuildsCsproj : TestBase
2016-06-17 16:16:09 -07:00
{
[Fact]
2016-12-18 00:45:25 -08:00
public void ItBuildsARunnableOutput ( )
2016-06-17 16:16:09 -07:00
{
var testAppName = "MSBuildTestApp" ;
2016-10-31 16:16:07 -07:00
var testInstance = TestAssets . Get ( testAppName )
. CreateInstance ( testAppName )
. WithSourceFiles ( )
. WithRestoreFiles ( ) ;
2016-09-27 14:41:06 -07:00
2016-10-27 18:46:43 -07:00
new BuildCommand ( )
2016-10-31 16:16:07 -07:00
. WithWorkingDirectory ( testInstance . Root )
2016-07-21 18:29:35 -05:00
. Execute ( )
2016-10-31 16:16:07 -07:00
. Should ( ) . Pass ( ) ;
2016-06-17 16:16:09 -07:00
var configuration = Environment . GetEnvironmentVariable ( "CONFIGURATION" ) ? ? "Debug" ;
2016-10-31 16:16:07 -07:00
2017-08-18 15:36:01 -07:00
var outputDll = testInstance . Root . GetDirectory ( "bin" , configuration , "netcoreapp2.1" )
2016-10-31 16:16:07 -07:00
. GetFile ( $"{testAppName}.dll" ) ;
2017-03-16 01:31:16 -07:00
var outputRunCommand = new DotnetCommand ( ) ;
2016-06-17 16:16:09 -07:00
2016-10-31 16:16:07 -07:00
outputRunCommand . ExecuteWithCapturedOutput ( outputDll . FullName )
. Should ( ) . Pass ( )
. And . HaveStdOutContaining ( "Hello World" ) ;
2016-06-17 16:16:09 -07:00
}
2016-12-18 00:45:25 -08:00
2017-06-02 23:32:53 -07:00
[Fact]
public void ItImplicitlyRestoresAProjectWhenBuilding ( )
{
var testAppName = "MSBuildTestApp" ;
var testInstance = TestAssets . Get ( testAppName )
. CreateInstance ( testAppName )
. WithSourceFiles ( ) ;
new BuildCommand ( )
. WithWorkingDirectory ( testInstance . Root )
. Execute ( )
. Should ( ) . Pass ( ) ;
}
2017-06-13 00:04:25 -07:00
[Fact]
public void ItCanBuildAMultiTFMProjectWithImplicitRestore ( )
{
var testInstance = TestAssets . Get (
TestAssetKinds . DesktopTestProjects ,
"NETFrameworkReferenceNETStandard20" )
. CreateInstance ( )
. WithSourceFiles ( ) ;
string projectDirectory = Path . Combine ( testInstance . Root . FullName , "MultiTFMTestApp" ) ;
new BuildCommand ( )
. WithWorkingDirectory ( projectDirectory )
2017-08-18 15:36:01 -07:00
. Execute ( "--framework netcoreapp2.1" )
2017-06-13 00:04:25 -07:00
. Should ( ) . Pass ( ) ;
}
2017-06-02 23:32:53 -07:00
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenBuildingWithTheNoRestoreOption ( )
{
var testAppName = "MSBuildTestApp" ;
var testInstance = TestAssets . Get ( testAppName )
. CreateInstance ( testAppName )
. WithSourceFiles ( ) ;
new BuildCommand ( )
. WithWorkingDirectory ( testInstance . Root )
. ExecuteWithCapturedOutput ( "--no-restore" )
. Should ( ) . Fail ( )
2017-06-23 19:48:07 -07:00
. And . HaveStdOutContaining ( "project.assets.json" ) ;
2017-06-02 23:32:53 -07:00
}
2017-08-31 15:31:44 -07:00
[Fact]
2016-12-18 00:45:25 -08:00
public void ItRunsWhenRestoringToSpecificPackageDir ( )
{
2017-02-15 15:35:03 -08:00
var rootPath = TestAssets . CreateTestDirectory ( ) . FullName ;
2016-12-18 00:45:25 -08:00
string dir = "pkgs" ;
string args = $"--packages {dir}" ;
2017-08-18 15:36:01 -07:00
string newArgs = $"console -f netcoreapp2.1 -o \" { rootPath } \ " --debug:ephemeral-hive --no-restore" ;
2017-01-31 17:31:37 -08:00
new NewCommandShim ( )
2016-12-18 00:45:25 -08:00
. WithWorkingDirectory ( rootPath )
2017-01-31 17:31:37 -08:00
. Execute ( newArgs )
2016-12-18 00:45:25 -08:00
. Should ( )
. Pass ( ) ;
new RestoreCommand ( )
. WithWorkingDirectory ( rootPath )
. Execute ( args )
. Should ( )
. Pass ( )
. And . NotHaveStdErr ( ) ;
new BuildCommand ( )
. WithWorkingDirectory ( rootPath )
2017-06-02 23:32:53 -07:00
. Execute ( "--no-restore" )
2016-12-18 00:45:25 -08:00
. Should ( ) . Pass ( ) ;
2017-02-20 10:01:29 -06:00
var configuration = Environment . GetEnvironmentVariable ( "CONFIGURATION" ) ? ? "Debug" ;
var outputDll = Directory . EnumerateFiles (
2017-08-18 15:36:01 -07:00
Path . Combine ( rootPath , "bin" , configuration , "netcoreapp2.1" ) , "*.dll" ,
2017-02-20 10:01:29 -06:00
SearchOption . TopDirectoryOnly )
. Single ( ) ;
2016-12-18 00:45:25 -08:00
2017-03-16 01:31:16 -07:00
var outputRunCommand = new DotnetCommand ( ) ;
2016-12-18 00:45:25 -08:00
outputRunCommand . ExecuteWithCapturedOutput ( outputDll )
. Should ( ) . Pass ( )
. And . HaveStdOutContaining ( "Hello World" ) ;
}
2017-01-11 17:06:03 -08:00
[Fact]
public void ItPrintsBuildSummary ( )
{
var testAppName = "MSBuildTestApp" ;
var testInstance = TestAssets . Get ( testAppName )
2017-08-29 11:26:28 -07:00
. CreateInstance ( )
2017-01-11 17:06:03 -08:00
. WithSourceFiles ( )
. WithRestoreFiles ( ) ;
string expectedBuildSummary = @ "Build succeeded.
0 Warning ( s )
0 Error ( s ) ";
var cmd = new BuildCommand ( )
. WithWorkingDirectory ( testInstance . Root )
. ExecuteWithCapturedOutput ( ) ;
cmd . Should ( ) . Pass ( ) ;
2017-06-21 13:34:16 -07:00
cmd . StdOut . Should ( ) . ContainVisuallySameFragmentIfNotLocalized ( expectedBuildSummary ) ;
2017-01-11 17:06:03 -08:00
}
2016-06-17 16:16:09 -07:00
}
}