diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildServerIntegrationTest.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildServerIntegrationTest.cs index 94607ec259..1adb5152ab 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildServerIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildServerIntegrationTest.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests } [Fact] - [InitializeTestProject("SimpleMvc", baseDirectory: "Whitespace in path", additionalProjects: new string[] { })] + [InitializeTestProject(originalProjectName: "SimpleMvc", targetProjectName: "SimpleMvc", baseDirectory: "Whitespace in path")] public async Task Build_AppWithWhitespaceInPath_CanBuildSuccessfully() { var result = await DotnetMSBuild( @@ -48,5 +48,24 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.FileExists(result, OutputPath, "SimpleMvc.PrecompiledViews.dll"); Assert.FileExists(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb"); } + + [Fact] + [InitializeTestProject(originalProjectName: "SimpleMvc", targetProjectName: "Whitespace in name", baseDirectory: "")] + public async Task Build_AppWithWhitespaceInName_CanBuildSuccessfully() + { + var result = await DotnetMSBuild( + "Build", + $"/p:RazorCompileOnBuild=true /p:UseRazorBuildServer=true /p:_RazorBuildServerPipeName={_pipeName}"); + + Assert.BuildPassed(result); + Assert.FileExists(result, OutputPath, "Whitespace in name.dll"); + Assert.FileExists(result, OutputPath, "Whitespace in name.pdb"); + Assert.FileExists(result, OutputPath, "Whitespace in name.PrecompiledViews.dll"); + Assert.FileExists(result, OutputPath, "Whitespace in name.PrecompiledViews.pdb"); + + Assert.FileExists(result, IntermediateOutputPath, "Whitespace in name.PrecompiledViews.dll"); + Assert.FileExists(result, IntermediateOutputPath, "Whitespace in name.RazorCoreGenerate.cache"); + Assert.FileExists(result, RazorIntermediateOutputPath, "Views", "Home", "Index.cs"); + } } } diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/InitializeTestProjectAttribute.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/InitializeTestProjectAttribute.cs index 17c6fcf8a9..f2e69b2578 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/InitializeTestProjectAttribute.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/InitializeTestProjectAttribute.cs @@ -9,20 +9,22 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { public class InitializeTestProjectAttribute : BeforeAfterTestAttribute { - private readonly string _projectName; + private readonly string _originalProjectName; + private readonly string _testProjectName; private readonly string _baseDirectory; private readonly string[] _additionalProjects; public InitializeTestProjectAttribute(string projectName, params string[] additionalProjects) - : this (projectName, string.Empty, additionalProjects) + : this (projectName, projectName, string.Empty, additionalProjects) { } - public InitializeTestProjectAttribute(string projectName, string baseDirectory, string[] additionalProjects) + public InitializeTestProjectAttribute(string originalProjectName, string targetProjectName, string baseDirectory, string[] additionalProjects = null) { - _projectName = projectName; + _originalProjectName = originalProjectName; + _testProjectName = targetProjectName; _baseDirectory = baseDirectory; - _additionalProjects = additionalProjects; + _additionalProjects = additionalProjects ?? Array.Empty(); } public override void Before(MethodInfo methodUnderTest) @@ -32,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests throw new InvalidOperationException($"This should be used on a class derived from {typeof(MSBuildIntegrationTestBase)}"); } - MSBuildIntegrationTestBase.Project = ProjectDirectory.Create(_projectName, _baseDirectory, _additionalProjects); + MSBuildIntegrationTestBase.Project = ProjectDirectory.Create(_originalProjectName, _testProjectName, _baseDirectory, _additionalProjects); } public override void After(MethodInfo methodUnderTest) diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/ProjectDirectory.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/ProjectDirectory.cs index aa9011fb2b..26ad2a4e69 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/ProjectDirectory.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/ProjectDirectory.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests public bool PreserveWorkingDirectory { get; set; } #endif - public static ProjectDirectory Create(string projectName, string baseDirectory, string[] additionalProjects) + public static ProjectDirectory Create(string originalProjectName, string targetProjectName, string baseDirectory, string[] additionalProjects) { var destinationPath = Path.Combine(Path.GetTempPath(), "Razor", baseDirectory, Path.GetRandomFileName()); Directory.CreateDirectory(destinationPath); @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests var binariesRoot = Path.GetDirectoryName(typeof(ProjectDirectory).Assembly.Location); - foreach (var project in new string[] { projectName, }.Concat(additionalProjects)) + foreach (var project in new string[] { originalProjectName, }.Concat(additionalProjects)) { var testAppsRoot = Path.Combine(solutionRoot, "test", "testapps"); var projectRoot = Path.Combine(testAppsRoot, project); @@ -52,13 +52,19 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests CopyDirectory(new DirectoryInfo(projectRoot), projectDestinationDir); SetupDirectoryBuildFiles(solutionRoot, binariesRoot, testAppsRoot, projectDestination); } - + + // Rename the csproj + var directoryPath = Path.Combine(destinationPath, originalProjectName); + var oldProjectFilePath = Path.Combine(directoryPath, originalProjectName + ".csproj"); + var newProjectFilePath = Path.Combine(directoryPath, targetProjectName + ".csproj"); + File.Move(oldProjectFilePath, newProjectFilePath); + CopyGlobalJson(solutionRoot, destinationPath); return new ProjectDirectory( destinationPath, - Path.Combine(destinationPath, projectName), - Path.Combine(destinationPath, projectName, projectName + ".csproj")); + directoryPath, + newProjectFilePath); } catch {