2018-11-20 10:53:39 -08:00
using System ;
using System.IO ;
using System.Linq ;
using System.Xml.Linq ;
2019-10-02 12:32:23 -07:00
using Microsoft.DotNet.PlatformAbstractions ;
2018-11-20 10:53:39 -08:00
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 ( )
2019-10-02 12:32:23 -07:00
. WithWorkingDirectory ( projectDirectory )
. ExecuteWithCapturedOutput ( )
2019-10-18 15:10:51 -07:00
// Templates are still at 3.1 and will not run on 5.0, revert to commented out assertion when 5.0 templates land
2019-08-02 22:09:56 -07:00
//.Should().Pass().And.HaveStdOutContaining("Hello World!");
2019-10-18 15:10:51 -07:00
. Should ( ) . Fail ( ) . And . HaveStdErrContaining ( "https://aka.ms/dotnet-core-applaunch" ) ;
2018-11-20 10:53:39 -08:00
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-10-02 12:32:23 -07:00
[Fact]
2019-01-07 13:55:18 -08:00
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 ( )
2019-10-02 12:32:23 -07:00
. WithWorkingDirectory ( projectDirectory )
. ExecuteWithCapturedOutput ( )
2019-10-18 15:10:51 -07:00
// Templates are still at 3.1 and will not run on 5.0, revert to commented out assertion when 5.0 templates land
2019-08-02 22:09:56 -07:00
//.Should().Pass().And.HaveStdOutContaining("Hello World!");
2019-10-18 15:10:51 -07:00
. Should ( ) . Fail ( ) . And . HaveStdErrContaining ( "https://aka.ms/dotnet-core-applaunch" ) ;
2019-08-02 22:09:56 -07:00
2019-01-07 13:55:18 -08:00
}
2018-11-20 10:53:39 -08:00
[Theory]
[InlineData("console")]
[InlineData("classlib")]
[InlineData("mstest")]
[InlineData("nunit")]
2018-11-20 18:55:46 -08:00
[InlineData("web")]
2019-05-20 12:40:08 -07:00
[InlineData("mvc")]
2018-11-20 10:53:39 -08:00
public void ItCanBuildTemplates ( string templateName )
2018-11-20 19:43:45 -08:00
{
TestTemplateBuild ( templateName ) ;
}
[WindowsOnlyTheory]
[InlineData("wpf")]
[InlineData("winforms")]
public void ItCanBuildDesktopTemplates ( string templateName )
{
TestTemplateBuild ( templateName ) ;
}
2019-10-02 12:32:23 -07:00
[WindowsOnlyTheory]
[InlineData("wpf")]
public void ItCanBuildDesktopTemplatesSelfContained ( string templateName )
{
TestTemplateBuild ( templateName ) ;
}
[Theory]
[InlineData("web")]
[InlineData("console")]
public void ItCanBuildTemplatesSelfContained ( string templateName )
{
TestTemplateBuild ( templateName , selfContained : true ) ;
}
private void TestTemplateBuild ( string templateName , bool selfContained = false )
2018-11-20 10:53:39 -08: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 ( ) ;
2019-10-02 12:32:23 -07:00
var buildArgs = selfContained ? "" : $"-r {RuntimeEnvironment.GetRuntimeIdentifier()}" ;
2019-09-24 13:59:39 -07:00
var dotnetRoot = Path . GetDirectoryName ( RepoDirectoriesProvider . DotnetUnderTest ) ;
2018-11-20 10:53:39 -08:00
new BuildCommand ( )
2019-09-24 13:59:39 -07:00
. WithEnvironmentVariable ( "PATH" , dotnetRoot ) // override PATH since razor rely on PATH to find dotnet
. WithWorkingDirectory ( projectDirectory )
2019-10-02 12:32:23 -07:00
. Execute ( buildArgs )
2019-09-24 13:59:39 -07:00
. Should ( ) . Pass ( ) ;
2018-11-20 10:53:39 -08:00
}
}
}