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 ;
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
var outputDll = testInstance . Root . GetDirectory ( "bin" , configuration , "netcoreapp1.0" )
. GetFile ( $"{testAppName}.dll" ) ;
2016-06-17 16:16:09 -07:00
var outputRunCommand = new TestCommand ( "dotnet" ) ;
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
[Fact]
public void ItRunsWhenRestoringToSpecificPackageDir ( )
{
var rootPath = TestAssetsManager . CreateTestDirectory ( ) . Path ;
string dir = "pkgs" ;
string args = $"--packages {dir}" ;
2017-01-31 17:31:37 -08:00
string newArgs = $"console -o \" { rootPath } \ " --debug:ephemeral-hive" ;
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 )
. Execute ( )
. Should ( ) . Pass ( ) ;
var outputDll = Directory . EnumerateFiles ( Path . Combine ( rootPath , "bin" ) , "*.dll" , SearchOption . AllDirectories ) . Single ( ) ;
var outputRunCommand = new TestCommand ( "dotnet" ) ;
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 )
. CreateInstance ( testAppName )
. WithSourceFiles ( )
. WithRestoreFiles ( ) ;
string expectedBuildSummary = @ "Build succeeded.
0 Warning ( s )
0 Error ( s ) ";
var cmd = new BuildCommand ( )
. WithWorkingDirectory ( testInstance . Root )
. ExecuteWithCapturedOutput ( ) ;
cmd . Should ( ) . Pass ( ) ;
cmd . StdOut . Should ( ) . ContainVisuallySameFragment ( expectedBuildSummary ) ;
}
2016-06-17 16:16:09 -07:00
}
}