Make `TestProject.GetProjectDirectory` more thorough when finding project directory.

- Used our test path utilities to properly navigate to the project directory.
- Added some logic to make future debugging/test failures more diagnosable.

#2184
This commit is contained in:
N. Taylor Mullen 2018-03-23 16:53:51 -07:00
parent 7bc54b99e0
commit da255ff9db
1 changed files with 9 additions and 7 deletions

View File

@ -3,7 +3,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Reflection; using Microsoft.AspNetCore.Testing;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
@ -11,16 +11,18 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
public static string GetProjectDirectory(Type type) public static string GetProjectDirectory(Type type)
{ {
var currentDirectory = new DirectoryInfo(AppContext.BaseDirectory); var solutionDir = TestPathUtilities.GetSolutionRootDirectory("Razor");
var name = type.GetTypeInfo().Assembly.GetName().Name;
while (currentDirectory != null && var assemblyName = type.Assembly.GetName().Name;
!string.Equals(currentDirectory.Name, name, StringComparison.Ordinal)) var projectDirectory = Path.Combine(solutionDir, "test", assemblyName);
if (!Directory.Exists(projectDirectory))
{ {
currentDirectory = currentDirectory.Parent; throw new InvalidOperationException(
$@"Could not locate project directory for type {type.FullName}.
Directory probe path: {projectDirectory}.");
} }
return currentDirectory.FullName; return projectDirectory;
} }
} }
} }