Move TryGetSolutionDirectoryInfo in test utils

This commit is contained in:
nicolas.dorier
2019-10-06 23:38:57 +09:00
parent 102b38b5a8
commit a919d3ddec
3 changed files with 13 additions and 17 deletions

View File

@@ -143,6 +143,7 @@ namespace BTCPayServer.Tests
_Host = new WebHostBuilder() _Host = new WebHostBuilder()
.UseConfiguration(conf) .UseConfiguration(conf)
.UseContentRoot(FindBTCPayServerDirectory()) .UseContentRoot(FindBTCPayServerDirectory())
.UseWebRoot(Path.Combine(FindBTCPayServerDirectory(), "wwwroot"))
.ConfigureServices(s => .ConfigureServices(s =>
{ {
s.AddLogging(l => s.AddLogging(l =>
@@ -267,7 +268,7 @@ namespace BTCPayServer.Tests
private string FindBTCPayServerDirectory() private string FindBTCPayServerDirectory()
{ {
var solutionDirectory = LanguageService.TryGetSolutionDirectoryInfo(Directory.GetCurrentDirectory()); var solutionDirectory = TestUtils.TryGetSolutionDirectoryInfo(Directory.GetCurrentDirectory());
return Path.Combine(solutionDirectory.FullName, "BTCPayServer"); return Path.Combine(solutionDirectory.FullName, "BTCPayServer");
} }

View File

@@ -9,11 +9,22 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Http.Internal;
#endif #endif
using Xunit.Sdk; using Xunit.Sdk;
using System.Linq;
namespace BTCPayServer.Tests namespace BTCPayServer.Tests
{ {
public static class TestUtils 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) public static FormFile GetFormFile(string filename, string content)
{ {
File.WriteAllText(filename, content); File.WriteAllText(filename, content);

View File

@@ -39,11 +39,6 @@ namespace BTCPayServer.Services
#else #else
var path = environment.WebRootPath; var path = environment.WebRootPath;
#endif #endif
if (string.IsNullOrEmpty(path))
{
//test environment
path = Path.Combine(TryGetSolutionDirectoryInfo().FullName,"BTCPayServer", "wwwroot");
}
path = Path.Combine(path, "locales"); path = Path.Combine(path, "locales");
var files = Directory.GetFiles(path, "*.json"); var files = Directory.GetFiles(path, "*.json");
var result = new List<Language>(); var result = new List<Language>();
@@ -58,17 +53,6 @@ namespace BTCPayServer.Services
_languages = result.ToArray(); _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() public Language[] GetLanguages()
{ {
return _languages; return _languages;