From 94261ded25074b5849d0b073a2c899c219714d92 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Wed, 14 Feb 2018 13:00:06 +0000 Subject: [PATCH] Fix RazorCompilerTest on Mac/Linux --- .../RazorCompilerTest.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs index 60d3ba7c5b..2c6b911788 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using System.Text; using Xunit; @@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test { // Arrange/Act var result = CompileToCSharp( - "x:\\dir\\subdir", + GetArbitraryPlatformValidDirectoryPath(), "Filename with spaces.cshtml", "ignored code", "ignored namespace"); @@ -45,8 +46,9 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test public void RejectsFilenameOutsideRoot(string filename) { // Arrange/Act + filename = filename.Replace('\\', Path.DirectorySeparatorChar); var result = CompileToCSharp( - "x:\\dir\\subdir", + GetArbitraryPlatformValidDirectoryPath(), filename, "ignored code", "ignored namespace"); @@ -69,8 +71,10 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test public void CreatesClassWithCorrectNameAndNamespace(string relativePath, string expectedNamespace, string expectedClassName) { // Arrange/Act + relativePath = relativePath.Replace(ArbitraryWindowsPath, GetArbitraryPlatformValidDirectoryPath()); + relativePath = relativePath.Replace('\\', Path.DirectorySeparatorChar); var result = CompileToAssembly( - "x:\\dir\\subdir", + GetArbitraryPlatformValidDirectoryPath(), relativePath, "{* No code *}", "Test.Base"); @@ -368,12 +372,17 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test { var testComponentTypeName = "TestComponent"; var testComponentNamespace = "Test"; - var assemblyResult = CompileToAssembly("c:\\ignored", $"{testComponentTypeName}.cshtml", cshtmlSource, testComponentNamespace); + var assemblyResult = CompileToAssembly(GetArbitraryPlatformValidDirectoryPath(), $"{testComponentTypeName}.cshtml", cshtmlSource, testComponentNamespace); Assert.Empty(assemblyResult.Diagnostics); var testComponentType = assemblyResult.Assembly.GetType($"{testComponentNamespace}.{testComponentTypeName}"); 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) { var csharpResult = CompileToCSharp(cshtmlRootPath, cshtmlRelativePath, cshtmlContent, outputNamespace);