65 lines
2.5 KiB
C#
65 lines
2.5 KiB
C#
using MediaBrowser.Common.Configuration;
|
|
|
|
namespace Jellyfin.Plugin.Multilang.Tests;
|
|
|
|
internal sealed class TestApplicationPaths(string root) : IApplicationPaths
|
|
{
|
|
public string ProgramDataPath { get; } = root;
|
|
public string WebPath { get; } = Path.Combine(root, "web");
|
|
public string ProgramSystemPath { get; } = Path.Combine(root, "system");
|
|
public string DataPath { get; } = Path.Combine(root, "data");
|
|
public string ImageCachePath { get; } = Path.Combine(root, "images");
|
|
public string PluginsPath { get; } = Path.Combine(root, "plugins");
|
|
public string PluginConfigurationsPath { get; } = Path.Combine(root, "plugin-configs");
|
|
public string LogDirectoryPath { get; } = Path.Combine(root, "logs");
|
|
public string ConfigurationDirectoryPath { get; } = Path.Combine(root, "config");
|
|
public string SystemConfigurationFilePath { get; } = Path.Combine(root, "config", "system.xml");
|
|
public string CachePath { get; } = Path.Combine(root, "cache");
|
|
public string TempDirectory { get; } = Path.Combine(root, "temp");
|
|
public string VirtualDataPath { get; } = "%AppDataPath%";
|
|
public string TrickplayPath { get; } = Path.Combine(root, "trickplay");
|
|
public string BackupPath { get; } = Path.Combine(root, "backups");
|
|
|
|
public void MakeSanityCheckOrThrow()
|
|
{
|
|
}
|
|
|
|
public void CreateAndCheckMarker(string path, string marker, bool isTemporary = false)
|
|
{
|
|
}
|
|
}
|
|
|
|
internal sealed class TestHttpClientFactory(Func<HttpRequestMessage, HttpResponseMessage> responseFactory) : IHttpClientFactory
|
|
{
|
|
public List<string> Requests { get; } = [];
|
|
|
|
public HttpClient CreateClient(string name)
|
|
=> new(new TestHttpMessageHandler(request =>
|
|
{
|
|
Requests.Add(request.RequestUri?.ToString() ?? string.Empty);
|
|
return responseFactory(request);
|
|
}));
|
|
}
|
|
|
|
internal sealed class TestHttpMessageHandler(Func<HttpRequestMessage, HttpResponseMessage> responseFactory) : HttpMessageHandler
|
|
{
|
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
=> Task.FromResult(responseFactory(request));
|
|
}
|
|
|
|
internal static class TestPaths
|
|
{
|
|
public static string CreateRoot()
|
|
{
|
|
var path = Path.Combine(Path.GetTempPath(), "multilang-test-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(path);
|
|
return path;
|
|
}
|
|
|
|
public static void DeleteRoot(string root)
|
|
{
|
|
if (Directory.Exists(root))
|
|
Directory.Delete(root, recursive: true);
|
|
}
|
|
}
|