2018-11-20 18:53:39 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace EndToEnd.Tests
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public class ProjectBuildTests : TestBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ItCanNewRestoreBuildRunCleanMSBuildProject()
|
|
|
|
|
{
|
|
|
|
|
var directory = TestAssets.CreateTestDirectory();
|
|
|
|
|
string projectDirectory = directory.FullName;
|
|
|
|
|
|
|
|
|
|
string newArgs = "console --debug:ephemeral-hive --no-restore";
|
|
|
|
|
new NewCommandShim()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(newArgs)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var runCommand = new RunCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory);
|
|
|
|
|
|
|
|
|
|
// Set DOTNET_ROOT as workaround for https://github.com/dotnet/cli/issues/10196
|
|
|
|
|
var dotnetRoot = Path.GetDirectoryName(RepoDirectoriesProvider.DotnetUnderTest);
|
|
|
|
|
if (!string.IsNullOrEmpty(dotnetRoot))
|
|
|
|
|
{
|
2018-11-30 05:07:50 +00:00
|
|
|
|
bool useX86 = RepoDirectoriesProvider.DotnetRidUnderTest.EndsWith("x86", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
|
runCommand = runCommand.WithEnvironmentVariable(useX86 ? "DOTNET_ROOT(x86)" : "DOTNET_ROOT",
|
2018-11-20 18:53:39 +00:00
|
|
|
|
dotnetRoot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runCommand.ExecuteWithCapturedOutput()
|
|
|
|
|
.Should().Pass()
|
|
|
|
|
.And.HaveStdOutContaining("Hello World!");
|
|
|
|
|
|
|
|
|
|
var binDirectory = new DirectoryInfo(projectDirectory).Sub("bin");
|
|
|
|
|
binDirectory.Should().HaveFilesMatching("*.dll", SearchOption.AllDirectories);
|
|
|
|
|
|
|
|
|
|
new CleanCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
binDirectory.Should().NotHaveFilesMatching("*.dll", SearchOption.AllDirectories);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 21:55:18 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItCanRunAnAppUsingTheWebSdk()
|
|
|
|
|
{
|
|
|
|
|
var directory = TestAssets.CreateTestDirectory();
|
|
|
|
|
string projectDirectory = directory.FullName;
|
|
|
|
|
|
|
|
|
|
string newArgs = "console --debug:ephemeral-hive --no-restore";
|
|
|
|
|
new NewCommandShim()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(newArgs)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
string projectPath = Path.Combine(projectDirectory, directory.Name + ".csproj");
|
|
|
|
|
|
|
|
|
|
var project = XDocument.Load(projectPath);
|
|
|
|
|
var ns = project.Root.Name.Namespace;
|
|
|
|
|
|
|
|
|
|
project.Root.Attribute("Sdk").Value = "Microsoft.NET.Sdk.Web";
|
|
|
|
|
|
|
|
|
|
project.Save(projectPath);
|
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var runCommand = new RunCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory);
|
|
|
|
|
|
|
|
|
|
// Set DOTNET_ROOT as workaround for https://github.com/dotnet/cli/issues/10196
|
|
|
|
|
var dotnetRoot = Path.GetDirectoryName(RepoDirectoriesProvider.DotnetUnderTest);
|
|
|
|
|
if (!string.IsNullOrEmpty(dotnetRoot))
|
|
|
|
|
{
|
|
|
|
|
bool useX86 = RepoDirectoriesProvider.DotnetRidUnderTest.EndsWith("x86", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
|
runCommand = runCommand.WithEnvironmentVariable(useX86 ? "DOTNET_ROOT(x86)" : "DOTNET_ROOT",
|
|
|
|
|
dotnetRoot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runCommand.ExecuteWithCapturedOutput()
|
|
|
|
|
.Should().Pass()
|
|
|
|
|
.And.HaveStdOutContaining("Hello World!");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 18:53:39 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("console")]
|
|
|
|
|
[InlineData("classlib")]
|
|
|
|
|
[InlineData("mstest")]
|
|
|
|
|
[InlineData("nunit")]
|
2018-11-21 02:55:46 +00:00
|
|
|
|
[InlineData("web")]
|
|
|
|
|
[InlineData("mvc")]
|
2018-11-20 18:53:39 +00:00
|
|
|
|
public void ItCanBuildTemplates(string templateName)
|
2018-11-21 03:43:45 +00:00
|
|
|
|
{
|
|
|
|
|
TestTemplateBuild(templateName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[WindowsOnlyTheory]
|
|
|
|
|
[InlineData("wpf")]
|
|
|
|
|
[InlineData("winforms")]
|
|
|
|
|
public void ItCanBuildDesktopTemplates(string templateName)
|
|
|
|
|
{
|
|
|
|
|
TestTemplateBuild(templateName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TestTemplateBuild(string templateName)
|
2018-11-20 18:53:39 +00:00
|
|
|
|
{
|
|
|
|
|
var directory = TestAssets.CreateTestDirectory(identifier: templateName);
|
|
|
|
|
string projectDirectory = directory.FullName;
|
|
|
|
|
|
|
|
|
|
string newArgs = $"{templateName} --debug:ephemeral-hive --no-restore";
|
|
|
|
|
new NewCommandShim()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute(newArgs)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|