Fix RazorCompilerTest on Mac/Linux
This commit is contained in:
parent
83b90d1980
commit
94261ded25
|
|
@ -13,6 +13,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
|
||||||
{
|
{
|
||||||
// Arrange/Act
|
// Arrange/Act
|
||||||
var result = CompileToCSharp(
|
var result = CompileToCSharp(
|
||||||
"x:\\dir\\subdir",
|
GetArbitraryPlatformValidDirectoryPath(),
|
||||||
"Filename with spaces.cshtml",
|
"Filename with spaces.cshtml",
|
||||||
"ignored code",
|
"ignored code",
|
||||||
"ignored namespace");
|
"ignored namespace");
|
||||||
|
|
@ -45,8 +46,9 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
|
||||||
public void RejectsFilenameOutsideRoot(string filename)
|
public void RejectsFilenameOutsideRoot(string filename)
|
||||||
{
|
{
|
||||||
// Arrange/Act
|
// Arrange/Act
|
||||||
|
filename = filename.Replace('\\', Path.DirectorySeparatorChar);
|
||||||
var result = CompileToCSharp(
|
var result = CompileToCSharp(
|
||||||
"x:\\dir\\subdir",
|
GetArbitraryPlatformValidDirectoryPath(),
|
||||||
filename,
|
filename,
|
||||||
"ignored code",
|
"ignored code",
|
||||||
"ignored namespace");
|
"ignored namespace");
|
||||||
|
|
@ -69,8 +71,10 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
|
||||||
public void CreatesClassWithCorrectNameAndNamespace(string relativePath, string expectedNamespace, string expectedClassName)
|
public void CreatesClassWithCorrectNameAndNamespace(string relativePath, string expectedNamespace, string expectedClassName)
|
||||||
{
|
{
|
||||||
// Arrange/Act
|
// Arrange/Act
|
||||||
|
relativePath = relativePath.Replace(ArbitraryWindowsPath, GetArbitraryPlatformValidDirectoryPath());
|
||||||
|
relativePath = relativePath.Replace('\\', Path.DirectorySeparatorChar);
|
||||||
var result = CompileToAssembly(
|
var result = CompileToAssembly(
|
||||||
"x:\\dir\\subdir",
|
GetArbitraryPlatformValidDirectoryPath(),
|
||||||
relativePath,
|
relativePath,
|
||||||
"{* No code *}",
|
"{* No code *}",
|
||||||
"Test.Base");
|
"Test.Base");
|
||||||
|
|
@ -368,12 +372,17 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
|
||||||
{
|
{
|
||||||
var testComponentTypeName = "TestComponent";
|
var testComponentTypeName = "TestComponent";
|
||||||
var testComponentNamespace = "Test";
|
var testComponentNamespace = "Test";
|
||||||
var assemblyResult = CompileToAssembly("c:\\ignored", $"{testComponentTypeName}.cshtml", cshtmlSource, testComponentNamespace);
|
var assemblyResult = CompileToAssembly(GetArbitraryPlatformValidDirectoryPath(), $"{testComponentTypeName}.cshtml", cshtmlSource, testComponentNamespace);
|
||||||
Assert.Empty(assemblyResult.Diagnostics);
|
Assert.Empty(assemblyResult.Diagnostics);
|
||||||
var testComponentType = assemblyResult.Assembly.GetType($"{testComponentNamespace}.{testComponentTypeName}");
|
var testComponentType = assemblyResult.Assembly.GetType($"{testComponentNamespace}.{testComponentTypeName}");
|
||||||
return (IComponent)Activator.CreateInstance(testComponentType);
|
return (IComponent)Activator.CreateInstance(testComponentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const string ArbitraryWindowsPath = "x:\\dir\\subdir";
|
||||||
|
const string ArbitraryMacLinuxPath = "/dir/subdir";
|
||||||
|
private static string GetArbitraryPlatformValidDirectoryPath()
|
||||||
|
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ArbitraryWindowsPath : ArbitraryMacLinuxPath;
|
||||||
|
|
||||||
private static CompileToAssemblyResult CompileToAssembly(string cshtmlRootPath, string cshtmlRelativePath, string cshtmlContent, string outputNamespace)
|
private static CompileToAssemblyResult CompileToAssembly(string cshtmlRootPath, string cshtmlRelativePath, string cshtmlContent, string outputNamespace)
|
||||||
{
|
{
|
||||||
var csharpResult = CompileToCSharp(cshtmlRootPath, cshtmlRelativePath, cshtmlContent, outputNamespace);
|
var csharpResult = CompileToCSharp(cshtmlRootPath, cshtmlRelativePath, cshtmlContent, outputNamespace);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue