Fix test runs on xplat
This commit is contained in:
parent
dd297b6d09
commit
3369bb6e90
|
|
@ -21,29 +21,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation.Tests
|
||||||
|
|
||||||
public ApplicationTestFixture Fixture { get; }
|
public ApplicationTestFixture Fixture { get; }
|
||||||
|
|
||||||
public static IEnumerable<object[]> ApplicationWithTagHelpersData
|
public static IEnumerable<object[]> SupportedFlavorsTheoryData
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var runtimeFlavors = new[]
|
return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f });
|
||||||
{
|
|
||||||
RuntimeFlavor.Clr,
|
|
||||||
RuntimeFlavor.CoreClr,
|
|
||||||
};
|
|
||||||
|
|
||||||
var urls = new[]
|
|
||||||
{
|
|
||||||
"Index",
|
|
||||||
"ViewWithPreprocessor",
|
|
||||||
};
|
|
||||||
|
|
||||||
return Enumerable.Zip(urls, runtimeFlavors, (a, b) => new object[] { a, b });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(RuntimeFlavor.Clr)]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
[InlineData(RuntimeFlavor.CoreClr)]
|
|
||||||
public async Task Precompilation_RunsConfiguredCompilationCallbacks(RuntimeFlavor flavor)
|
public async Task Precompilation_RunsConfiguredCompilationCallbacks(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -56,7 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation.Tests
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await httpClient.GetStringAsync("");
|
var response = await httpClient.GetStringWithRetryAsync("", Fixture.Logger);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
TestEmbeddedResource.AssertContent("ApplicationWithConfigureMvc.Home.Index.txt", response);
|
TestEmbeddedResource.AssertContent("ApplicationWithConfigureMvc.Home.Index.txt", response);
|
||||||
|
|
@ -64,8 +51,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(RuntimeFlavor.Clr)]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
[InlineData(RuntimeFlavor.CoreClr)]
|
|
||||||
public async Task Precompilation_UsesConfiguredParseOptions(RuntimeFlavor flavor)
|
public async Task Precompilation_UsesConfiguredParseOptions(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -78,7 +64,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation.Tests
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await httpClient.GetStringAsync("Home/ViewWithPreprocessor");
|
var response = await httpClient.GetStringWithRetryAsync("Home/ViewWithPreprocessor", Fixture.Logger);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
TestEmbeddedResource.AssertContent(
|
TestEmbeddedResource.AssertContent(
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var runtimeFlavors = new[]
|
|
||||||
{
|
|
||||||
RuntimeFlavor.Clr,
|
|
||||||
RuntimeFlavor.CoreClr,
|
|
||||||
};
|
|
||||||
|
|
||||||
var urls = new[]
|
var urls = new[]
|
||||||
{
|
{
|
||||||
"ClassLibraryTagHelper",
|
"ClassLibraryTagHelper",
|
||||||
|
|
@ -38,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
|
||||||
"NuGetPackageTagHelper",
|
"NuGetPackageTagHelper",
|
||||||
};
|
};
|
||||||
|
|
||||||
return Enumerable.Zip(urls, runtimeFlavors, (a, b) => new object[] { a, b });
|
return Enumerable.Zip(urls, RuntimeFlavors.SupportedFlavors, (a, b) => new object[] { a, b });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +50,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await httpClient.GetStringAsync($"Home/{url}");
|
var response = await httpClient.GetStringWithRetryAsync($"Home/{url}", Fixture.Logger);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
TestEmbeddedResource.AssertContent($"ApplicationWithTagHelpers.Home.{url}.txt", response);
|
TestEmbeddedResource.AssertContent($"ApplicationWithTagHelpers.Home.{url}.txt", response);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -30,8 +31,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
|
||||||
|
|
||||||
public string TempRestoreDirectory { get; } = CreateTempRestoreDirectory();
|
public string TempRestoreDirectory { get; } = CreateTempRestoreDirectory();
|
||||||
|
|
||||||
|
public ILogger Logger { get; private set; }
|
||||||
|
|
||||||
public IApplicationDeployer CreateDeployment(RuntimeFlavor flavor)
|
public IApplicationDeployer CreateDeployment(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
|
Logger = new LoggerFactory()
|
||||||
|
.AddConsole()
|
||||||
|
.CreateLogger($"{ApplicationName}:{flavor}");
|
||||||
|
|
||||||
if (!_isRestored)
|
if (!_isRestored)
|
||||||
{
|
{
|
||||||
Restore();
|
Restore();
|
||||||
|
|
@ -61,11 +68,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var logger = new LoggerFactory()
|
return ApplicationDeployerFactory.Create(deploymentParameters, Logger);
|
||||||
.AddConsole()
|
|
||||||
.CreateLogger($"{ApplicationName}:{flavor}");
|
|
||||||
|
|
||||||
return ApplicationDeployerFactory.Create(deploymentParameters, logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Restore()
|
protected virtual void Restore()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
// 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;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
|
||||||
|
{
|
||||||
|
public static class HttpClientExtensions
|
||||||
|
{
|
||||||
|
public static async Task<string> GetStringWithRetryAsync(
|
||||||
|
this HttpClient httpClient,
|
||||||
|
string url,
|
||||||
|
ILogger logger)
|
||||||
|
{
|
||||||
|
var response = await RetryHelper.RetryRequest(() => httpClient.GetAsync(url), logger, retryCount: 5);
|
||||||
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
Assert.True(response.IsSuccessStatusCode,
|
||||||
|
$"Failed to GET content from {url}. Status code {response.StatusCode}." +
|
||||||
|
Environment.NewLine +
|
||||||
|
content);
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
// 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.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
|
||||||
|
{
|
||||||
|
public static class RuntimeFlavors
|
||||||
|
{
|
||||||
|
public static IEnumerable<RuntimeFlavor> SupportedFlavors
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
yield return RuntimeFlavor.CoreClr;
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
{
|
||||||
|
yield return RuntimeFlavor.Clr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||||
|
|
@ -18,9 +20,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
|
||||||
|
|
||||||
public ApplicationTestFixture Fixture { get; }
|
public ApplicationTestFixture Fixture { get; }
|
||||||
|
|
||||||
|
public static IEnumerable<object[]> SupportedFlavorsTheoryData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(RuntimeFlavor.Clr)]
|
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||||
[InlineData(RuntimeFlavor.CoreClr)]
|
|
||||||
public async Task Precompilation_WorksForSimpleApps(RuntimeFlavor flavor)
|
public async Task Precompilation_WorksForSimpleApps(RuntimeFlavor flavor)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -33,7 +42,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await httpClient.GetStringAsync("");
|
var response = await httpClient.GetStringWithRetryAsync("", Fixture.Logger);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
TestEmbeddedResource.AssertContent("SimpleAppTest.Home.Index.txt", response);
|
TestEmbeddedResource.AssertContent("SimpleAppTest.Home.Index.txt", response);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
"define": [
|
"define": [
|
||||||
"GENERATE_BASELINES"
|
"__remove_this_to__GENERATE_BASELINES"
|
||||||
],
|
],
|
||||||
"embed": "Resources/*"
|
"embed": "Resources/*"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ namespace ApplicationWithConfigureStartup
|
||||||
{
|
{
|
||||||
if (node.Token.IsKind(SyntaxKind.StringLiteralToken))
|
if (node.Token.IsKind(SyntaxKind.StringLiteralToken))
|
||||||
{
|
{
|
||||||
return node.WithToken(SyntaxFactory.Literal(node.Token.ValueText.Replace("\r\n", "\r\n<br />")));
|
return node.WithToken(SyntaxFactory.Literal(
|
||||||
|
node.Token.ValueText.Replace(Environment.NewLine, Environment.NewLine + "<br />")));
|
||||||
}
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue