Skip to content

Enable test logging for ProjectTemplate tests #26507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNetCore.E2ETesting;
using Microsoft.AspNetCore.Testing;
using Xunit;

[assembly: TestFramework("Microsoft.AspNetCore.E2ETesting.XunitTestFrameworkWithAssemblyFixture", "Microsoft.AspNetCore.Components.E2ETests")]
[assembly: AssemblyFixture(typeof(SeleniumStandaloneServer))]
[assembly: AssemblyFixture(typeof(SauceConnectServer))]
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

<OutputPath />

<GenerateLoggingTestingAssemblyAttributes>false</GenerateLoggingTestingAssemblyAttributes>

<!-- This project references the shared framework transitively. Prevent restore errors by setting this flag. -->
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNetCore.E2ETesting;
using Microsoft.AspNetCore.Testing;
using Templates.Test.Helpers;
using Xunit;

[assembly: TestFramework("Microsoft.AspNetCore.E2ETesting.XunitTestFrameworkWithAssemblyFixture", "BlazorTemplates.Tests")]

[assembly: Microsoft.AspNetCore.E2ETesting.AssemblyFixture(typeof(ProjectFactoryFixture))]
[assembly: Microsoft.AspNetCore.E2ETesting.AssemblyFixture(typeof(SeleniumStandaloneServer))]
[assembly: AssemblyFixture(typeof(ProjectFactoryFixture))]
[assembly: AssemblyFixture(typeof(SeleniumStandaloneServer))]

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<!-- Shared testing infrastructure for running E2E tests using selenium -->
<Import Project="$(SharedSourceRoot)E2ETesting\E2ETesting.props" />
Expand All @@ -22,7 +22,6 @@
<TestTemplateCreationFolder>TestTemplates\</TestTemplateCreationFolder>
<TestPackageRestorePath>$([MSBuild]::EnsureTrailingSlash('$(RepoRoot)'))obj\template-restore\</TestPackageRestorePath>
<TestTemplateTestsProps>TemplateTests.props</TestTemplateTestsProps>
<GenerateLoggingTestingAssemblyAttributes>false</GenerateLoggingTestingAssemblyAttributes>
<TestDependsOnAspNetRuntime>true</TestDependsOnAspNetRuntime>
</PropertyGroup>

Expand All @@ -43,11 +42,6 @@
<Reference Include="Microsoft.NET.Sdk.Razor" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
</ItemGroup>

<PropertyGroup>
<PreserveExistingLogsInOutput Condition="'$(PreserveExistingLogsInOutput)' == '' AND '$(ContinuousIntegrationBuild)' == 'true'">true</PreserveExistingLogsInOutput>
<PreserveExistingLogsInOutput Condition="'$(PreserveExistingLogsInOutput)' == ''">false</PreserveExistingLogsInOutput>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>DotNetEfFullPath</_Parameter1>
Expand All @@ -65,11 +59,6 @@
<_Parameter1>ContinuousIntegrationBuild</_Parameter1>
<_Parameter2>true</_Parameter2>
</AssemblyAttribute>
<AssemblyAttribute Include="Microsoft.AspNetCore.Testing.TestFrameworkFileLoggerAttribute">
<_Parameter1>$(PreserveExistingLogsInOutput)</_Parameter1>
<_Parameter2>$(TargetFramework)</_Parameter2>
<_Parameter3></_Parameter3>
</AssemblyAttribute>
</ItemGroup>

<Target Name="PrepareForTest" BeforeTargets="GetAssemblyAttributes" Condition="$(DesignTimeBuild) != true">
Expand Down
2 changes: 1 addition & 1 deletion src/ProjectTemplates/Shared/ProjectFactoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task<Project> GetOrCreateProject(string projectKey, ITestOutputHelp
}

private static string GetTemplateFolderBasePath(Assembly assembly) =>
(string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HELIX_DIR")))
(string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HELIX_DIR")))
? assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
.Single(a => a.Key == "TestTemplateCreationFolder")
.Value
Expand Down
28 changes: 28 additions & 0 deletions src/ProjectTemplates/Shared/TestOutputLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace Templates.Test.Helpers
{
internal class TestOutputLogger : ITestOutputHelper
{
private readonly ILogger _logger;

public TestOutputLogger(ILogger logger)
{
_logger = logger;
}

public void WriteLine(string message)
{
_logger.LogInformation(message);
}

public void WriteLine(string format, params object[] args)
{
_logger.LogInformation(string.Format(format, args));
}
}
}
7 changes: 2 additions & 5 deletions src/ProjectTemplates/test/AssemblyInfo.AssemblyFixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
using Microsoft.AspNetCore.E2ETesting;
using Microsoft.AspNetCore.Testing;
using Templates.Test.Helpers;
using Xunit;

[assembly: TestFramework("Microsoft.AspNetCore.E2ETesting.XunitTestFrameworkWithAssemblyFixture", "ProjectTemplates.Tests")]

[assembly: Microsoft.AspNetCore.E2ETesting.AssemblyFixture(typeof(ProjectFactoryFixture))]
[assembly: Microsoft.AspNetCore.E2ETesting.AssemblyFixture(typeof(SeleniumStandaloneServer))]
[assembly: AssemblyFixture(typeof(ProjectFactoryFixture))]
[assembly: AssemblyFixture(typeof(SeleniumStandaloneServer))]
18 changes: 14 additions & 4 deletions src/ProjectTemplates/test/BaselineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Templates.Test
{
public class BaselineTest
public class BaselineTest : LoggedTest
{
private static readonly Regex TemplateNameRegex = new Regex(
"new (?<template>[a-zA-Z]+)",
Expand All @@ -32,10 +32,9 @@ public class BaselineTest
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline,
TimeSpan.FromSeconds(1));

public BaselineTest(ProjectFactoryFixture projectFactory, ITestOutputHelper output)
public BaselineTest(ProjectFactoryFixture projectFactory)
{
ProjectFactory = projectFactory;
Output = output;
}

public Project Project { get; set; }
Expand Down Expand Up @@ -67,7 +66,18 @@ public static TheoryData<string, string[]> TemplateBaselines
}

public ProjectFactoryFixture ProjectFactory { get; }
public ITestOutputHelper Output { get; }
private ITestOutputHelper _output;
public ITestOutputHelper Output
{
get
{
if (_output == null)
{
_output = new TestOutputLogger(Logger);
}
return _output;
}
}

[Theory]
[MemberData(nameof(TemplateBaselines))]
Expand Down
26 changes: 19 additions & 7 deletions src/ProjectTemplates/test/ByteOrderMarkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Testing;
using Templates.Test.Helpers;
using Xunit;
using Xunit.Abstractions;

namespace Templates.Test
{
public class ByteOrderMarkTest
public class ByteOrderMarkTest : LoggedTest
{
private readonly ITestOutputHelper _output;
private ITestOutputHelper _output;
public ITestOutputHelper Output
{
get
{
if (_output == null)
{
_output = new TestOutputLogger(Logger);
}
return _output;
}
}

public ByteOrderMarkTest(ITestOutputHelper output)
public ByteOrderMarkTest()
{
_output = output;
}

[Theory]
Expand All @@ -43,13 +55,13 @@ public void JSAndJSONInAllTemplates_ShouldNotContainBOM(string projectName)
// Check for UTF8 BOM 0xEF,0xBB,0xBF
if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)
{
_output.WriteLine($"File {filePath} has UTF-8 BOM characters.");
Output.WriteLine($"File {filePath} has UTF-8 BOM characters.");
filesWithBOMCharactersPresent = true;
}
// Check for UTF16 BOM 0xFF, 0xFE
if (bytes[0] == 0xFF && bytes[1] == 0xFE)
{
_output.WriteLine($"File {filePath} has UTF-16 BOM characters.");
Output.WriteLine($"File {filePath} has UTF-16 BOM characters.");
filesWithBOMCharactersPresent = true;
}
}
Expand Down Expand Up @@ -83,7 +95,7 @@ public void RazorFilesInWebProjects_ShouldContainBOM(string projectName)
var expectedBytes = Encoding.UTF8.GetPreamble();
if (bytes[0] != expectedBytes[0] || bytes[1] != expectedBytes[1] || bytes[2] != expectedBytes[2])
{
_output.WriteLine($"File {filePath} does not have UTF-8 BOM characters.");
Output.WriteLine($"File {filePath} does not have UTF-8 BOM characters.");
nonBOMFilesPresent = true;
}
}
Expand Down
42 changes: 25 additions & 17 deletions src/ProjectTemplates/test/EmptyWebTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@

namespace Templates.Test
{
public class EmptyWebTemplateTest
public class EmptyWebTemplateTest : LoggedTest
{
public EmptyWebTemplateTest(ProjectFactoryFixture projectFactory, ITestOutputHelper output)
public EmptyWebTemplateTest(ProjectFactoryFixture projectFactory)
{
ProjectFactory = projectFactory;
Output = output;
}

public Project Project { get; set; }

public ProjectFactoryFixture ProjectFactory { get; }

public ITestOutputHelper Output { get; }
private ITestOutputHelper _output;
public ITestOutputHelper Output
{
get
{
if (_output == null)
{
_output = new TestOutputLogger(Logger);
}
return _output;
}
}

[ConditionalFact]
[SkipOnHelix("Cert failures", Queues = "OSX.1014.Amd64;OSX.1014.Amd64.Open")]
Expand All @@ -38,41 +46,41 @@ public async Task EmptyWebTemplateFSharp()

private async Task EmtpyTemplateCore(string languageOverride)
{
Project = await ProjectFactory.GetOrCreateProject("empty" + (languageOverride == "F#" ? "fsharp" : "csharp"), Output);
var project = await ProjectFactory.GetOrCreateProject("empty" + (languageOverride == "F#" ? "fsharp" : "csharp"), Output);

var createResult = await Project.RunDotNetNewAsync("web", language: languageOverride);
Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create/restore", Project, createResult));
var createResult = await project.RunDotNetNewAsync("web", language: languageOverride);
Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create/restore", project, createResult));

// Avoid the F# compiler. See https://github.com/dotnet/aspnetcore/issues/14022
if (languageOverride != null)
{
return;
}

var publishResult = await Project.RunDotNetPublishAsync();
Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", Project, publishResult));
var publishResult = await project.RunDotNetPublishAsync();
Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", project, publishResult));

// Run dotnet build after publish. The reason is that one uses Config = Debug and the other uses Config = Release
// The output from publish will go into bin/Release/netcoreappX.Y/publish and won't be affected by calling build
// later, while the opposite is not true.

var buildResult = await Project.RunDotNetBuildAsync();
Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", Project, buildResult));
var buildResult = await project.RunDotNetBuildAsync();
Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", project, buildResult));

using (var aspNetProcess = Project.StartBuiltProjectAsync())
using (var aspNetProcess = project.StartBuiltProjectAsync())
{
Assert.False(
aspNetProcess.Process.HasExited,
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built project", Project, aspNetProcess.Process));
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built project", project, aspNetProcess.Process));

await aspNetProcess.AssertOk("/");
}

using (var aspNetProcess = Project.StartPublishedProjectAsync())
using (var aspNetProcess = project.StartPublishedProjectAsync())
{
Assert.False(
aspNetProcess.Process.HasExited,
ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", Project, aspNetProcess.Process));
ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", project, aspNetProcess.Process));

await aspNetProcess.AssertOk("/");
}
Expand Down
Loading