Added another integration test

This commit is contained in:
Ajay Bhargav Baaskaran 2018-02-06 12:26:09 -08:00
parent 7490b4413c
commit 0a7edd665e
3 changed files with 39 additions and 12 deletions

View File

@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
} }
[Fact] [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() public async Task Build_AppWithWhitespaceInPath_CanBuildSuccessfully()
{ {
var result = await DotnetMSBuild( 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.dll");
Assert.FileExists(result, OutputPath, "SimpleMvc.PrecompiledViews.pdb"); 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");
}
} }
} }

View File

@ -9,20 +9,22 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
{ {
public class InitializeTestProjectAttribute : BeforeAfterTestAttribute public class InitializeTestProjectAttribute : BeforeAfterTestAttribute
{ {
private readonly string _projectName; private readonly string _originalProjectName;
private readonly string _testProjectName;
private readonly string _baseDirectory; private readonly string _baseDirectory;
private readonly string[] _additionalProjects; private readonly string[] _additionalProjects;
public InitializeTestProjectAttribute(string projectName, params 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; _baseDirectory = baseDirectory;
_additionalProjects = additionalProjects; _additionalProjects = additionalProjects ?? Array.Empty<string>();
} }
public override void Before(MethodInfo methodUnderTest) 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)}"); 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) public override void After(MethodInfo methodUnderTest)

View File

@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
public bool PreserveWorkingDirectory { get; set; } public bool PreserveWorkingDirectory { get; set; }
#endif #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()); var destinationPath = Path.Combine(Path.GetTempPath(), "Razor", baseDirectory, Path.GetRandomFileName());
Directory.CreateDirectory(destinationPath); Directory.CreateDirectory(destinationPath);
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
var binariesRoot = Path.GetDirectoryName(typeof(ProjectDirectory).Assembly.Location); 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 testAppsRoot = Path.Combine(solutionRoot, "test", "testapps");
var projectRoot = Path.Combine(testAppsRoot, project); var projectRoot = Path.Combine(testAppsRoot, project);
@ -52,13 +52,19 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
CopyDirectory(new DirectoryInfo(projectRoot), projectDestinationDir); CopyDirectory(new DirectoryInfo(projectRoot), projectDestinationDir);
SetupDirectoryBuildFiles(solutionRoot, binariesRoot, testAppsRoot, projectDestination); 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); CopyGlobalJson(solutionRoot, destinationPath);
return new ProjectDirectory( return new ProjectDirectory(
destinationPath, destinationPath,
Path.Combine(destinationPath, projectName), directoryPath,
Path.Combine(destinationPath, projectName, projectName + ".csproj")); newProjectFilePath);
} }
catch catch
{ {