From a919d3ddecdcf83a292e6c752ae226e92b6d2ca0 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sun, 6 Oct 2019 23:38:57 +0900 Subject: [PATCH] Move TryGetSolutionDirectoryInfo in test utils --- BTCPayServer.Tests/BTCPayServerTester.cs | 3 ++- BTCPayServer.Tests/TestUtils.cs | 11 +++++++++++ BTCPayServer/Services/LanguageService.cs | 16 ---------------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/BTCPayServer.Tests/BTCPayServerTester.cs b/BTCPayServer.Tests/BTCPayServerTester.cs index fef72c2df..d4a68f07b 100644 --- a/BTCPayServer.Tests/BTCPayServerTester.cs +++ b/BTCPayServer.Tests/BTCPayServerTester.cs @@ -143,6 +143,7 @@ namespace BTCPayServer.Tests _Host = new WebHostBuilder() .UseConfiguration(conf) .UseContentRoot(FindBTCPayServerDirectory()) + .UseWebRoot(Path.Combine(FindBTCPayServerDirectory(), "wwwroot")) .ConfigureServices(s => { s.AddLogging(l => @@ -267,7 +268,7 @@ namespace BTCPayServer.Tests private string FindBTCPayServerDirectory() { - var solutionDirectory = LanguageService.TryGetSolutionDirectoryInfo(Directory.GetCurrentDirectory()); + var solutionDirectory = TestUtils.TryGetSolutionDirectoryInfo(Directory.GetCurrentDirectory()); return Path.Combine(solutionDirectory.FullName, "BTCPayServer"); } diff --git a/BTCPayServer.Tests/TestUtils.cs b/BTCPayServer.Tests/TestUtils.cs index 41f3c4ab4..67a159206 100644 --- a/BTCPayServer.Tests/TestUtils.cs +++ b/BTCPayServer.Tests/TestUtils.cs @@ -9,11 +9,22 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Internal; #endif using Xunit.Sdk; +using System.Linq; namespace BTCPayServer.Tests { public static class TestUtils { + public static DirectoryInfo TryGetSolutionDirectoryInfo(string currentPath = null) + { + var directory = new DirectoryInfo( + currentPath ?? Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetFiles("*.sln").Any()) + { + directory = directory.Parent; + } + return directory; + } public static FormFile GetFormFile(string filename, string content) { File.WriteAllText(filename, content); diff --git a/BTCPayServer/Services/LanguageService.cs b/BTCPayServer/Services/LanguageService.cs index 9ca153cae..078de8b5f 100644 --- a/BTCPayServer/Services/LanguageService.cs +++ b/BTCPayServer/Services/LanguageService.cs @@ -39,11 +39,6 @@ namespace BTCPayServer.Services #else var path = environment.WebRootPath; #endif - if (string.IsNullOrEmpty(path)) - { - //test environment - path = Path.Combine(TryGetSolutionDirectoryInfo().FullName,"BTCPayServer", "wwwroot"); - } path = Path.Combine(path, "locales"); var files = Directory.GetFiles(path, "*.json"); var result = new List(); @@ -58,17 +53,6 @@ namespace BTCPayServer.Services _languages = result.ToArray(); } - - public static DirectoryInfo TryGetSolutionDirectoryInfo(string currentPath = null) - { - var directory = new DirectoryInfo( - currentPath ?? Directory.GetCurrentDirectory()); - while (directory != null && !directory.GetFiles("*.sln").Any()) - { - directory = directory.Parent; - } - return directory; - } public Language[] GetLanguages() { return _languages;