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()
.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");
}

View File

@@ -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);

View File

@@ -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<Language>();
@@ -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;