2016-02-10 13:16:23 -06: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 Microsoft.DotNet.Cli.Utils ;
using Microsoft.DotNet.Tools.Test.Utilities ;
using Xunit ;
2016-03-03 15:31:04 -08:00
using FluentAssertions ;
2016-02-10 13:16:23 -06:00
namespace Microsoft.DotNet.Tests
{
public class PackagedCommandTests : TestBase
{
private readonly string _testProjectsRoot ;
public PackagedCommandTests ( )
{
_testProjectsRoot = Path . Combine ( AppContext . BaseDirectory , "TestAssets" , "TestProjects" ) ;
}
[Theory]
[InlineData("AppWithDirectAndToolDependency")]
[InlineData("AppWithToolDependency")]
2016-03-03 15:31:04 -08:00
public void TestProjectToolIsAvailableThroughDriver ( string appName )
2016-02-10 13:16:23 -06:00
{
2016-03-03 15:31:04 -08:00
var appDirectory = Path . Combine ( _testProjectsRoot , appName ) ;
2016-02-10 13:16:23 -06:00
new BuildCommand ( Path . Combine ( appDirectory , "project.json" ) )
. Execute ( )
. Should ( )
. Pass ( ) ;
var currentDirectory = Directory . GetCurrentDirectory ( ) ;
Directory . SetCurrentDirectory ( appDirectory ) ;
try
{
2016-03-17 11:43:17 -07:00
CommandResult result = new PortableCommand ( ) . ExecuteWithCapturedOutput ( ) ;
2016-02-10 13:16:23 -06:00
2016-03-17 11:43:17 -07:00
result . Should ( ) . HaveStdOut ( "Hello Portable World!" + Environment . NewLine ) ;
2016-02-10 13:16:23 -06:00
result . Should ( ) . NotHaveStdErr ( ) ;
result . Should ( ) . Pass ( ) ;
}
finally
{
Directory . SetCurrentDirectory ( currentDirectory ) ;
}
}
2016-03-03 15:31:04 -08:00
[Fact]
public void TestProjectDependencyIsNotAvailableThroughDriver ( )
{
var appName = "AppWithDirectDependency" ;
var appDirectory = Path . Combine ( _testProjectsRoot , appName ) ;
new BuildCommand ( Path . Combine ( appDirectory , "project.json" ) )
. Execute ( )
. Should ( )
. Pass ( ) ;
var currentDirectory = Directory . GetCurrentDirectory ( ) ;
Directory . SetCurrentDirectory ( appDirectory ) ;
try
{
CommandResult result = new HelloCommand ( ) . ExecuteWithCapturedOutput ( ) ;
result . StdOut . Should ( ) . Contain ( "No executable found matching command" ) ;
result . Should ( ) . NotPass ( ) ;
}
finally
{
Directory . SetCurrentDirectory ( currentDirectory ) ;
}
}
2016-02-10 13:16:23 -06:00
class HelloCommand : TestCommand
{
public HelloCommand ( )
: base ( "dotnet" )
{
}
public override CommandResult Execute ( string args = "" )
{
args = $"hello {args}" ;
return base . Execute ( args ) ;
}
public override CommandResult ExecuteWithCapturedOutput ( string args = "" )
{
args = $"hello {args}" ;
return base . ExecuteWithCapturedOutput ( args ) ;
}
}
2016-03-17 11:43:17 -07:00
class PortableCommand : TestCommand
{
public PortableCommand ( )
: base ( "dotnet" )
{
}
public override CommandResult Execute ( string args = "" )
{
args = $"portable {args}" ;
return base . Execute ( args ) ;
}
public override CommandResult ExecuteWithCapturedOutput ( string args = "" )
{
args = $"portable {args}" ;
return base . ExecuteWithCapturedOutput ( args ) ;
}
}
2016-02-10 13:16:23 -06:00
}
}