2016-09-23 12:49:24 -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.
|
|
|
|
|
2016-10-26 00:04:40 -05:00
|
|
|
using System.IO;
|
2016-09-23 12:49:24 -07:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Run3.Tests
|
|
|
|
{
|
|
|
|
public class GivenDotnetRun3BuildsCsproj : TestBase
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void ItCanRunAMSBuildProject()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
|
|
|
var testInstance = TestAssetsManager
|
2016-09-27 14:41:06 -07:00
|
|
|
.CreateTestInstance(testAppName);
|
2016-09-23 12:49:24 -07:00
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
2016-09-27 14:41:06 -07:00
|
|
|
new Restore3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
2016-09-23 12:49:24 -07:00
|
|
|
new Build3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
new Run3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-10-26 00:04:40 -05:00
|
|
|
.ExecuteWithCapturedOutput()
|
2016-09-23 12:49:24 -07:00
|
|
|
.Should()
|
|
|
|
.Pass()
|
|
|
|
.And
|
|
|
|
.HaveStdOutContaining("Hello World!");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItBuildsTheProjectBeforeRunning()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
|
|
|
var testInstance = TestAssetsManager
|
2016-09-27 14:41:06 -07:00
|
|
|
.CreateTestInstance(testAppName);
|
2016-09-23 12:49:24 -07:00
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
2016-09-27 14:41:06 -07:00
|
|
|
new Restore3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
2016-09-23 12:49:24 -07:00
|
|
|
new Run3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-10-26 00:04:40 -05:00
|
|
|
.ExecuteWithCapturedOutput()
|
2016-09-23 12:49:24 -07:00
|
|
|
.Should()
|
|
|
|
.Pass()
|
|
|
|
.And
|
|
|
|
.HaveStdOutContaining("Hello World!");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItCanRunAMSBuildProjectWhenSpecifyingAFramework()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
|
|
|
var testInstance = TestAssetsManager
|
2016-09-27 14:41:06 -07:00
|
|
|
.CreateTestInstance(testAppName);
|
2016-09-23 12:49:24 -07:00
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
2016-09-27 14:41:06 -07:00
|
|
|
new Restore3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
2016-09-23 12:49:24 -07:00
|
|
|
new Run3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput("--framework netcoreapp1.0")
|
|
|
|
.Should()
|
|
|
|
.Pass()
|
|
|
|
.And
|
2016-10-26 00:04:40 -05:00
|
|
|
.HaveStdOutContaining("Hello World!");
|
2016-09-23 12:49:24 -07:00
|
|
|
}
|
2016-10-13 17:26:21 -05:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItReportsAGoodErrorWhenProjectHasMultipleFrameworks()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildAppWithMultipleFrameworks";
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
.CreateTestInstance(testAppName);
|
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
|
|
|
new Restore3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-10-17 18:38:03 -05:00
|
|
|
.Execute("/p:SkipInvalidConfigurations=true")
|
2016-10-13 17:26:21 -05:00
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
// 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 Run3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput("--no-build")
|
|
|
|
.Should()
|
|
|
|
.Fail()
|
|
|
|
.And
|
|
|
|
.HaveStdErrContaining("--framework");
|
|
|
|
}
|
2016-10-26 00:04:40 -05:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void It_runs_portable_apps_from_a_different_path_after_building()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
.CreateTestInstance(testAppName);
|
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
|
|
|
new Restore3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
new Build3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
string workingDirectory = Directory.GetParent(testProjectDirectory).FullName;
|
|
|
|
new Run3Command()
|
|
|
|
.WithWorkingDirectory(workingDirectory)
|
|
|
|
.ExecuteWithCapturedOutput($"--no-build --project {Path.Combine(testProjectDirectory, testAppName)}.csproj")
|
|
|
|
.Should()
|
|
|
|
.Pass()
|
|
|
|
.And
|
|
|
|
.HaveStdOutContaining("Hello World!");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void It_runs_portable_apps_from_a_different_path_without_building()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
.CreateTestInstance(testAppName);
|
|
|
|
|
|
|
|
var testProjectDirectory = testInstance.TestRoot;
|
|
|
|
|
|
|
|
new Restore3Command()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
string workingDirectory = Directory.GetParent(testProjectDirectory).FullName;
|
|
|
|
new Run3Command()
|
|
|
|
.WithWorkingDirectory(workingDirectory)
|
|
|
|
.ExecuteWithCapturedOutput($"--project {Path.Combine(testProjectDirectory, testAppName)}.csproj")
|
|
|
|
.Should()
|
|
|
|
.Pass()
|
|
|
|
.And
|
|
|
|
.HaveStdOutContaining("Hello World!");
|
|
|
|
}
|
2016-09-23 12:49:24 -07:00
|
|
|
}
|
|
|
|
}
|