Deploy tests the same way we do for RazorSdk

Remove tests marked previously skipped
This commit is contained in:
Pranav K 2018-05-22 12:54:18 -07:00
Родитель 4eda3c378c
Коммит 488fff41a7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 1963DA6D96C3057A
11 изменённых файлов: 163 добавлений и 116 удалений

Просмотреть файл

@ -24,9 +24,8 @@ namespace FunctionalTests
public async Task PublishingPrintsParseErrors()
{
// Arrange
var applicationPath = ApplicationPaths.GetTestAppDirectory("ApplicationWithParseErrors");
var indexPath = Path.Combine(applicationPath, "Views", "Home", "Index.cshtml");
var viewImportsPath = Path.Combine(applicationPath, "Views", "Home", "About.cshtml");
var indexPath = Path.Combine(Fixture.TestProjectDirectory, "Views", "Home", "Index.cshtml");
var viewImportsPath = Path.Combine(Fixture.TestProjectDirectory, "Views", "Home", "About.cshtml");
var expectedErrors = new[]
{
indexPath + " (0): The code block is missing a closing \"}\" character. Make sure you have a matching \"}\" character for all the \"{\" characters within this block, and that none of the \"}\" characters are being interpreted as markup.",

Просмотреть файл

@ -1,7 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
@ -9,10 +12,10 @@ using Xunit.Abstractions;
namespace FunctionalTests
{
public class ApplicationWithTagHelpersTest_CoreCLR :
LoggedTest, IClassFixture<CoreCLRApplicationTestFixture<ApplicationWithTagHelpers.Startup>>
LoggedTest, IClassFixture<ApplicationWithTagHelpersTest_CoreCLR.ApplicationWithTagHelpersTestFixture>
{
public ApplicationWithTagHelpersTest_CoreCLR(
CoreCLRApplicationTestFixture<ApplicationWithTagHelpers.Startup> fixture,
ApplicationWithTagHelpersTestFixture fixture,
ITestOutputHelper output)
: base(output)
{
@ -56,5 +59,17 @@ namespace FunctionalTests
TestEmbeddedResource.AssertContent($"ApplicationWithTagHelpers.Home.LocalTagHelper.txt", response);
}
}
public class ApplicationWithTagHelpersTestFixture : CoreCLRApplicationTestFixture<ApplicationWithTagHelpers.Startup>
{
protected override Task<DeploymentResult> CreateDeploymentAsyncCore(ILoggerFactory loggerFactory)
{
CopyDirectory(
new DirectoryInfo(Path.Combine(ApplicationPath, "..", "ClassLibraryTagHelper")),
new DirectoryInfo(Path.Combine(WorkingDirectory, "ClassLibraryTagHelper")));
return base.CreateDeploymentAsyncCore(loggerFactory);
}
}
}
}

Просмотреть файл

@ -1,56 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace FunctionalTests
{
public class PublishWithDebugTest_CoreCLR :
LoggedTest, IClassFixture<PublishWithDebugTest_CoreCLR.TestFixture>
{
public PublishWithDebugTest_CoreCLR(
TestFixture fixture,
ITestOutputHelper output)
: base(output)
{
Fixture = fixture;
}
public ApplicationTestFixture Fixture { get; }
[Fact]
public async Task PublishingInDebugWorks()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Assert
var expected = Path.Combine(deployment.ContentRoot, $"{Fixture.ApplicationName}.PrecompiledViews.dll");
Assert.True(File.Exists(expected), $"File {expected} does not exist.");
}
}
public class TestFixture : CoreCLRApplicationTestFixture<SimpleApp.Startup>
{
public TestFixture()
{
PublishOnly = true;
}
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();
deploymentParameters.Configuration = "Debug";
return deploymentParameters;
}
}
}
}

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
@ -22,7 +21,7 @@ namespace FunctionalTests
public ApplicationTestFixture Fixture { get; }
[Fact(Skip = "Unblocking the build - https://github.com/aspnet/MvcPrecompilation/issues/224")]
[Fact]
public async Task Precompilation_WorksForSimpleApps()
{
using (StartLog(out var loggerFactory))

Просмотреть файл

@ -27,9 +27,8 @@ namespace FunctionalTests
public async Task PublishingPrintsParseErrors()
{
// Arrange
var applicationPath = ApplicationPaths.GetTestAppDirectory("ApplicationWithParseErrors");
var indexPath = Path.Combine(applicationPath, "Views", "Home", "Index.cshtml");
var viewImportsPath = Path.Combine(applicationPath, "Views", "Home", "About.cshtml");
var indexPath = Path.Combine(Fixture.TestProjectDirectory, "Views", "Home", "Index.cshtml");
var viewImportsPath = Path.Combine(Fixture.TestProjectDirectory, "Views", "Home", "About.cshtml");
var expectedErrors = new[]
{
indexPath + " (0): The code block is missing a closing \"}\" character. Make sure you have a matching \"}\" character for all the \"{\" characters within this block, and that none of the \"}\" characters are being interpreted as markup.",

Просмотреть файл

@ -1,8 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
@ -12,10 +15,10 @@ namespace FunctionalTests
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class ApplicationWithTagHelpersTest_Desktop :
LoggedTest, IClassFixture<DesktopApplicationTestFixture<ApplicationWithTagHelpers.Startup>>
LoggedTest, IClassFixture<ApplicationWithTagHelpersTest_Desktop.ApplicationWithTagHelpersTestFixture>
{
public ApplicationWithTagHelpersTest_Desktop(
DesktopApplicationTestFixture<ApplicationWithTagHelpers.Startup> fixture,
ApplicationWithTagHelpersTestFixture fixture,
ITestOutputHelper output)
: base(output)
{
@ -59,5 +62,17 @@ namespace FunctionalTests
TestEmbeddedResource.AssertContent($"ApplicationWithTagHelpers.Home.LocalTagHelper.txt", response);
}
}
public class ApplicationWithTagHelpersTestFixture : DesktopApplicationTestFixture<ApplicationWithTagHelpers.Startup>
{
protected override Task<DeploymentResult> CreateDeploymentAsyncCore(ILoggerFactory loggerFactory)
{
CopyDirectory(
new DirectoryInfo(Path.Combine(ApplicationPath, "..", "ClassLibraryTagHelper")),
new DirectoryInfo(Path.Combine(WorkingDirectory, "ClassLibraryTagHelper")));
return base.CreateDeploymentAsyncCore(loggerFactory);
}
}
}
}

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
@ -13,11 +12,11 @@ namespace FunctionalTests
{
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public class PublishWithDebugTest_Desktop :
LoggedTest, IClassFixture<PublishWithDebugTest_Desktop.TestFixture>
public class SimpleAppTestWithPlatformx86_Desktop :
LoggedTest, IClassFixture<DesktopApplicationTestFixture<SimpleApp.Startup>>
{
public PublishWithDebugTest_Desktop(
TestFixture fixture,
public SimpleAppTestWithPlatformx86_Desktop(
DesktopApplicationTestFixture<SimpleApp.Startup> fixture,
ITestOutputHelper output)
: base(output)
{
@ -27,32 +26,31 @@ namespace FunctionalTests
public ApplicationTestFixture Fixture { get; }
[ConditionalFact]
public async Task PublishingInDebugWorks()
public async Task Precompilation_PublishingForPlatform()
{
using (StartLog(out var loggerFactory))
{
// Arrange
var deployment = await Fixture.CreateDeploymentAsync(loggerFactory);
// Act
var response = await deployment.HttpClient.GetStringWithRetryAsync(
deployment.ApplicationBaseUri,
loggerFactory.CreateLogger(Fixture.ApplicationName));
// Assert
var expected = Path.Combine(deployment.ContentRoot, $"{Fixture.ApplicationName}.PrecompiledViews.dll");
Assert.True(File.Exists(expected), $"File {expected} does not exist.");
TestEmbeddedResource.AssertContent("SimpleAppTest.Home.Index.txt", response);
}
}
public class TestFixture : DesktopApplicationTestFixture<SimpleApp.Startup>
public class SimpleAppTestWithPlatformx86_DesktopFixture : DesktopApplicationTestFixture<SimpleApp.Startup>
{
public TestFixture()
{
PublishOnly = true;
}
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();
deploymentParameters.Configuration = "Debug";
var parameters = base.GetDeploymentParameters();
parameters.AdditionalPublishParameters = "/p:Platform=x86";
return deploymentParameters;
return parameters;
}
}
}

Просмотреть файл

@ -25,7 +25,7 @@ namespace FunctionalTests
public ApplicationTestFixture Fixture { get; }
[ConditionalFact(Skip = "Unblocking the build - https://github.com/aspnet/MvcPrecompilation/issues/224")]
[ConditionalFact]
public async Task Precompilation_WorksForSimpleApps()
{
using (StartLog(out var loggerFactory))

Просмотреть файл

@ -3,9 +3,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Logging;
namespace FunctionalTests
@ -13,28 +15,44 @@ namespace FunctionalTests
public abstract class ApplicationTestFixture : IDisposable
{
private const string DotnetCLITelemetryOptOut = "DOTNET_CLI_TELEMETRY_OPTOUT";
private static readonly SemaphoreSlim _deploymentLock = new SemaphoreSlim(initialCount: 1);
private static readonly string SolutionDirectory;
private Task<DeploymentResult> _deploymentTask;
private ApplicationDeployer _deployer;
static ApplicationTestFixture()
{
SolutionDirectory = TestPathUtilities.GetSolutionRootDirectory("RazorViewCompilation");
if (!SolutionDirectory.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
SolutionDirectory += Path.DirectorySeparatorChar;
}
}
protected ApplicationTestFixture(string applicationName, string applicationPath)
{
ApplicationName = applicationName;
ApplicationPath = applicationPath ?? ApplicationPaths.GetTestAppDirectory(applicationName);
WorkingDirectory = Path.Combine(Path.GetTempPath(), "PrecompilationTool", Path.GetRandomFileName());
TestProjectDirectory = Path.Combine(WorkingDirectory, ApplicationName);
}
public string ApplicationName { get; }
public string ApplicationPath { get; }
public string WorkingDirectory { get; }
public string TestProjectDirectory { get; }
public bool PublishOnly { get; set; }
protected abstract DeploymentParameters GetDeploymentParameters();
protected DeploymentParameters GetDeploymentParameters(RuntimeFlavor flavor, string targetFramework)
=> GetDeploymentParameters(ApplicationPath, ApplicationName, flavor, targetFramework);
=> GetDeploymentParameters(TestProjectDirectory, ApplicationName, flavor, targetFramework);
public static DeploymentParameters GetDeploymentParameters(string applicationPath, string applicationName, RuntimeFlavor flavor, string targetFramework)
private static DeploymentParameters GetDeploymentParameters(string applicationPath, string applicationName, RuntimeFlavor flavor, string targetFramework)
{
// This determines the configuration of the the test project and consequently the configuration the src projects are most likely built in.
var projectConfiguration =
@ -54,15 +72,17 @@ namespace FunctionalTests
{
ApplicationName = applicationName,
PublishApplicationBeforeDeployment = true,
Configuration = "Release",
Configuration = projectConfiguration,
EnvironmentVariables =
{
new KeyValuePair<string, string>(DotnetCLITelemetryOptOut, "1"),
new KeyValuePair<string, string>("SolutionDirectory", SolutionDirectory),
new KeyValuePair<string, string>("SolutionConfiguration", projectConfiguration),
},
PublishEnvironmentVariables =
{
new KeyValuePair<string, string>(DotnetCLITelemetryOptOut, "1"),
new KeyValuePair<string, string>("SolutionDirectory", SolutionDirectory),
new KeyValuePair<string, string>("SolutionConfiguration", projectConfiguration),
},
TargetFramework = targetFramework,
@ -78,35 +98,89 @@ namespace FunctionalTests
_deploymentTask.Result.HttpClient?.Dispose();
}
CleanupWorkingDirectory();
_deployer?.Dispose();
}
public async Task<DeploymentResult> CreateDeploymentAsync(ILoggerFactory loggerFactory)
public Task<DeploymentResult> CreateDeploymentAsync(ILoggerFactory loggerFactory)
{
try
if (_deploymentTask == null)
{
await _deploymentLock.WaitAsync(TimeSpan.FromSeconds(10));
if (_deploymentTask == null)
{
var deploymentParameters = GetDeploymentParameters();
if (PublishOnly)
{
_deployer = new PublishOnlyDeployer(deploymentParameters, loggerFactory);
}
else
{
_deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory);
}
_deploymentTask = CreateDeploymentAsyncCore(loggerFactory);
}
_deploymentTask = _deployer.DeployAsync();
return _deploymentTask;
}
protected virtual Task<DeploymentResult> CreateDeploymentAsyncCore(ILoggerFactory loggerFactory)
{
CopyDirectory(new DirectoryInfo(ApplicationPath), new DirectoryInfo(TestProjectDirectory));
File.Copy(Path.Combine(SolutionDirectory, "global.json"), Path.Combine(TestProjectDirectory, "global.json"));
File.Copy(Path.Combine(ApplicationPath, "..", "Directory.Build.props"), Path.Combine(TestProjectDirectory, "Directory.Build.props"));
File.Copy(Path.Combine(ApplicationPath, "..", "Directory.Build.targets"), Path.Combine(TestProjectDirectory, "Directory.Build.targets"));
var deploymentParameters = GetDeploymentParameters();
if (PublishOnly)
{
_deployer = new PublishOnlyDeployer(deploymentParameters, loggerFactory);
}
else
{
_deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory);
}
return _deployer.DeployAsync();
}
public void CopyDirectory(DirectoryInfo source, DirectoryInfo destination, bool recursive = true)
{
// Recurse into subdirectories
foreach (var directory in source.EnumerateDirectories())
{
if (directory.Name == "bin")
{
continue;
}
var created = destination.CreateSubdirectory(directory.Name);
// We only want to copy the restore artifacts from obj directory while ignoring in any configuration specific directories
CopyDirectory(directory, created, recursive: directory.Name != "obj");
}
foreach (var file in source.EnumerateFiles())
{
file.CopyTo(Path.Combine(destination.FullName, file.Name));
}
}
private void CleanupWorkingDirectory()
{
var tries = 5;
var sleep = TimeSpan.FromSeconds(3);
for (var i = 0; i < tries; i++)
{
try
{
if (Directory.Exists(WorkingDirectory))
{
Directory.Delete(WorkingDirectory, recursive: true);
}
return;
}
catch when (i < tries - 1)
{
Console.WriteLine($"Failed to delete directory {TestProjectDirectory}, trying again.");
Thread.Sleep(sleep);
}
catch
{
// Do nothing
}
}
finally
{
_deploymentLock.Release();
}
return await _deploymentTask;
}
}
}

Просмотреть файл

@ -1,5 +1,9 @@
<Project>
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<SolutionDirectory Condition="'$(SolutionDirectory)'==''">$(MSBuildThisFileDirectory)..\</SolutionDirectory>
</PropertyGroup>
<Import Project="$(SolutionDirectory)Directory.Build.props" />
<PropertyGroup>
<DeveloperBuildTestAppTfms>netcoreapp2.2</DeveloperBuildTestAppTfms>

Просмотреть файл

@ -1,13 +1,13 @@
<Project>
<Import Project="..\Directory.Build.targets" />
<Import Project="$(SolutionDirectory)Directory.Build.targets" />
<PropertyGroup>
<TestIncludeViewCompilationTargets Condition="'$(TestIncludeViewCompilationTargets)'==''">$(MvcRazorCompileOnPublish)</TestIncludeViewCompilationTargets>
<SolutionConfiguration Condition="'$(SolutionConfiguration)'==''">$(Configuration)</SolutionConfiguration>
<_MvcViewCompilationTasksPath>$(MSBuildThisFileDirectory)..\src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tasks\bin\$(SolutionConfiguration)\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tasks.dll</_MvcViewCompilationTasksPath>
<_MvcViewCompilationBinariesDir>$(MSBuildThisFileDirectory)..\src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\bin\$(SolutionConfiguration)\</_MvcViewCompilationBinariesDir>
<_MvcViewCompilationTasksPath>$(SolutionDirectory)src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tasks\bin\$(SolutionConfiguration)\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tasks.dll</_MvcViewCompilationTasksPath>
<_MvcViewCompilationBinariesDir>$(SolutionDirectory)src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\bin\$(SolutionConfiguration)\</_MvcViewCompilationBinariesDir>
</PropertyGroup>
<Import Project="..\src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets"
<Import Project="$(SolutionDirectory)src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets"
Condition="'$(TestIncludeViewCompilationTargets)'=='true'"/>
</Project>