From 18bb31cee42ee5ebbdd1a7178aee6e27f31843f2 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 7 Dec 2016 16:29:50 -0800 Subject: [PATCH] Change IntegrationTestBase to properly locate baseline files in net451. - Net451 tests would have their current directory set to the dll that was located in bin/debug/framework/rid/... when run via `dotnet test`. #885 --- .../IntegrationTests/IntegrationTestBase.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/IntegrationTestBase.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/IntegrationTestBase.cs index df3c3476aa..8e7d0f6b4f 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/IntegrationTestBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/IntegrationTestBase.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Reflection; #if NET451 using System.Runtime.Remoting; using System.Runtime.Remoting.Messaging; @@ -18,6 +19,23 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests [IntializeTestFile] public abstract class IntegrationTestBase { + private static readonly string ThisProjectName = typeof(IntializeTestFileAttribute).GetTypeInfo().Assembly.GetName().Name; + private static readonly string TestProjectRoot = FindTestProjectRoot(); + + private static string FindTestProjectRoot() + { + var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory()); + + while (currentDirectory != null && + !string.Equals(currentDirectory.Name, ThisProjectName, StringComparison.Ordinal)) + { + currentDirectory = currentDirectory.Parent; + } + + var normalizedSeparators = currentDirectory.FullName.Replace(Path.DirectorySeparatorChar, '/'); + return currentDirectory.FullName; + } + #if GENERATE_BASELINES private static readonly bool GenerateBaselines = true; #else @@ -77,7 +95,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests if (GenerateBaselines) { - File.WriteAllText(baselineFilename, RazorIRNodeSerializer.Serialize(document)); + var baselineFullPath = Path.Combine(TestProjectRoot, baselineFilename); + File.WriteAllText(baselineFullPath, RazorIRNodeSerializer.Serialize(document)); return; }