From 356d77b1abd609cd077ea165b394caa10e6f1427 Mon Sep 17 00:00:00 2001 From: Andrea Spadaccini Date: Fri, 2 Nov 2018 15:47:30 +0000 Subject: [PATCH] Fix resources path computation in test setup The resources path is set based on the path of the current assembly. The problem is that the assembly directory has a different number of components, depending on whether the Configuration environment variable is set or not. Therefore, the previous code, that depended on the number of subdirs, would fail if there is no value for the Configuration environment variable. The new code looks for the occurrence of a well-known string in the path and bases the path of the test resources off that position. It is still pretty sub-optimal, but I think it's a bit less sub-optimal than it was. Tested in the following ways: - run dotnet test on one test from the command line on Windows; - click on "Run Test" from Visual Studio Code. Fixes #1629. --- LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs index daa7451ae..762037637 100644 --- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs +++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs @@ -64,9 +64,8 @@ private static void SetUpTestEnvironment() if (resourcesPath == null) { string initialAssemblyParentFolder = Directory.GetParent(new Uri(typeof(BaseFixture).GetTypeInfo().Assembly.CodeBase).LocalPath).FullName; - const string sourceRelativePath = @"../../../../LibGit2Sharp.Tests/Resources"; - - resourcesPath = Path.Combine(initialAssemblyParentFolder, sourceRelativePath); + int pos = initialAssemblyParentFolder.IndexOf("LibGit2Sharp.Tests"); + resourcesPath = Path.Combine(initialAssemblyParentFolder.Substring(0, pos), "../LibGit2Sharp.Tests/Resources"); } ResourcesDirectory = new DirectoryInfo(resourcesPath);