2016-10-28 01:46:43 +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.IO;
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Run.Tests
|
|
|
|
{
|
|
|
|
public class GivenDotnetRunBuildsCsproj : TestBase
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void ItCanRunAMSBuildProject()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
2017-02-15 23:35:03 +00:00
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
2017-02-15 23:35:03 +00:00
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute("/p:SkipInvalidConfigurations=true")
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new RunCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World!");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItBuildsTheProjectBeforeRunning()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
2017-02-15 23:35:03 +00:00
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
2017-02-15 23:35:03 +00:00
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute("/p:SkipInvalidConfigurations=true")
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new RunCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World!");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItCanRunAMSBuildProjectWhenSpecifyingAFramework()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
2017-02-15 23:35:03 +00:00
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
2017-02-15 23:35:03 +00:00
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute("/p:SkipInvalidConfigurations=true")
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new RunCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2017-03-02 20:46:21 +00:00
|
|
|
.ExecuteWithCapturedOutput("--framework netcoreapp2.0")
|
2016-10-28 01:46:43 +00:00
|
|
|
.Should().Pass()
|
2017-03-03 04:35:20 +00:00
|
|
|
.And.HaveStdOutContaining("Hello World!");
|
2016-10-28 01:46:43 +00:00
|
|
|
}
|
2017-03-03 04:35:20 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItRunsPortableAppsFromADifferentPathAfterBuilding()
|
2016-10-28 01:46:43 +00:00
|
|
|
{
|
|
|
|
var testInstance = TestAssets.Get("MSBuildTestApp")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
2017-03-03 04:35:20 +00:00
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new RunCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.ExecuteWithCapturedOutput($"--no-build")
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World!");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItRunsPortableAppsFromADifferentPathWithoutBuilding()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
2016-10-28 01:46:43 +00:00
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
2017-03-03 04:35:20 +00:00
|
|
|
var projectFile = testInstance.Root.GetFile(testAppName + ".csproj");
|
2016-10-28 01:46:43 +00:00
|
|
|
|
2017-03-03 04:35:20 +00:00
|
|
|
new RunCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root.Parent)
|
|
|
|
.ExecuteWithCapturedOutput($"--project {projectFile.FullName}")
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World!");
|
2016-12-18 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-24 05:44:53 +00:00
|
|
|
[Fact]
|
|
|
|
public void ItRunsPortableAppsFromADifferentPathSpecifyingOnlyTheDirectoryWithoutBuilding()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
|
|
|
|
|
|
|
new RunCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root.Parent)
|
|
|
|
.ExecuteWithCapturedOutput($"--project {testProjectDirectory}")
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World!");
|
|
|
|
}
|
|
|
|
|
2016-12-18 08:45:25 +00:00
|
|
|
[Fact]
|
|
|
|
public void ItRunsAppWhenRestoringToSpecificPackageDirectory()
|
|
|
|
{
|
2017-02-15 23:35:03 +00:00
|
|
|
var rootPath = TestAssets.CreateTestDirectory().FullName;
|
2016-12-18 08:45:25 +00:00
|
|
|
|
|
|
|
string dir = "pkgs";
|
|
|
|
string args = $"--packages {dir}";
|
|
|
|
|
2017-04-11 03:00:17 +00:00
|
|
|
string newArgs = $"console -o \"{rootPath}\" --no-restore";
|
2017-02-01 01:31:37 +00:00
|
|
|
new NewCommandShim()
|
2016-12-18 08:45:25 +00:00
|
|
|
.WithWorkingDirectory(rootPath)
|
2017-02-01 01:31:37 +00:00
|
|
|
.Execute(newArgs)
|
2016-12-18 08:45:25 +00:00
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(rootPath)
|
|
|
|
.Execute(args)
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
new RunCommand()
|
|
|
|
.WithWorkingDirectory(rootPath)
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World");
|
|
|
|
}
|
2017-03-21 18:46:08 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItReportsAGoodErrorWhenProjectHasMultipleFrameworks()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildAppWithMultipleFrameworks";
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
|
|
// use --no-build so this test can run on all platforms.
|
|
|
|
// the test app targets net451, which can't be built on non-Windows
|
|
|
|
new RunCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.ExecuteWithCapturedOutput("--no-build")
|
|
|
|
.Should().Fail()
|
|
|
|
.And.HaveStdErrContaining("--framework");
|
|
|
|
}
|
2017-04-12 23:03:45 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItCanPassArgumentsToSubjectAppByDoubleDash()
|
|
|
|
{
|
|
|
|
const string testAppName = "MSBuildTestApp";
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
|
|
|
|
|
|
|
new RunCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput("-- foo bar baz")
|
|
|
|
.Should()
|
|
|
|
.Pass()
|
|
|
|
.And.HaveStdOutContaining("echo args:foo;bar;baz");
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
}
|
2017-03-03 04:35:20 +00:00
|
|
|
}
|