2016-02-10 19:16:23 +00: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 23:31:04 +00:00
|
|
|
|
using FluentAssertions;
|
2016-02-10 19:16:23 +00: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 23:31:04 +00:00
|
|
|
|
public void TestProjectToolIsAvailableThroughDriver(string appName)
|
2016-02-10 19:16:23 +00:00
|
|
|
|
{
|
2016-03-03 23:31:04 +00:00
|
|
|
|
var appDirectory = Path.Combine(_testProjectsRoot, appName);
|
2016-02-10 19:16:23 +00:00
|
|
|
|
|
|
|
|
|
new BuildCommand(Path.Combine(appDirectory, "project.json"))
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
|
|
|
|
Directory.SetCurrentDirectory(appDirectory);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-03-17 18:43:17 +00:00
|
|
|
|
CommandResult result = new PortableCommand().ExecuteWithCapturedOutput();
|
2016-02-10 19:16:23 +00:00
|
|
|
|
|
2016-03-17 18:43:17 +00:00
|
|
|
|
result.Should().HaveStdOut("Hello Portable World!" + Environment.NewLine);
|
2016-02-10 19:16:23 +00:00
|
|
|
|
result.Should().NotHaveStdErr();
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(currentDirectory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-28 08:15:09 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(".NETStandardApp,Version=v1.5")]
|
|
|
|
|
[InlineData(".NETFramework,Version=v4.5.1")]
|
|
|
|
|
public void TestFrameworkSpecificDependencyToolsCanBeInvoked(string framework)
|
|
|
|
|
{
|
|
|
|
|
var appDirectory = Path.Combine(_testProjectsRoot, "AppWithDirectDependencyDesktopAndPortable");
|
|
|
|
|
|
|
|
|
|
new BuildCommand(Path.Combine(appDirectory, "project.json"))
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
|
|
var currentDirectory = Directory.GetCurrentDirectory();
|
|
|
|
|
Directory.SetCurrentDirectory(appDirectory);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CommandResult result = new DependencyToolInvokerCommand()
|
|
|
|
|
.ExecuteWithCapturedOutput(framework);
|
|
|
|
|
|
|
|
|
|
result.Should().HaveStdOutContaining(framework);
|
|
|
|
|
result.Should().NotHaveStdErr();
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(currentDirectory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-03 23:31:04 +00: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 19:16:23 +00: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 18:43:17 +00: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-03-28 08:15:09 +00:00
|
|
|
|
|
|
|
|
|
class DependencyToolInvokerCommand : TestCommand
|
|
|
|
|
{
|
|
|
|
|
public DependencyToolInvokerCommand()
|
|
|
|
|
: base("dotnet")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult Execute(string framework)
|
|
|
|
|
{
|
|
|
|
|
var args = $"dependency-tool-invoker desktop-and-portable --framework {framework}";
|
|
|
|
|
return base.Execute(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override CommandResult ExecuteWithCapturedOutput(string framework)
|
|
|
|
|
{
|
|
|
|
|
var args = $"dependency-tool-invoker desktop-and-portable --framework {framework}";
|
|
|
|
|
return base.ExecuteWithCapturedOutput(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-10 19:16:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|