mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-10-16 23:49:19 +02:00
Split Settings into model, serializer, paths and store
698 lines did all of it at once. The mutable CaptureFromUi callback becomes an ISettingsCapture the settings view implements.
This commit is contained in:
34
StarterNG.Tests/Fakes/FakeEnvironment.cs
Normal file
34
StarterNG.Tests/Fakes/FakeEnvironment.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using StarterNG.Application.Abstractions;
|
||||
|
||||
namespace StarterNG.Tests.Fakes;
|
||||
|
||||
/// <summary>A host machine described inline: platform, home folder, env vars.</summary>
|
||||
public sealed class FakeEnvironment : IEnvironment
|
||||
{
|
||||
private readonly Dictionary<string, string> _variables = new(StringComparer.Ordinal);
|
||||
|
||||
public bool IsWindows { get; set; }
|
||||
|
||||
public bool IsLinux { get; set; } = true;
|
||||
|
||||
public bool IsMacOS { get; set; }
|
||||
|
||||
public string BaseDirectory { get; set; } = Path.Combine("game");
|
||||
|
||||
public string? GetVariable(string name) => _variables.TryGetValue(name, out var value) ? value : null;
|
||||
|
||||
public FakeEnvironment With(string name, string value)
|
||||
{
|
||||
_variables[name] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>Switches the fake to Windows, with an APPDATA folder.</summary>
|
||||
public FakeEnvironment AsWindows(string appData = "C:/Users/kolejarz/AppData/Roaming")
|
||||
{
|
||||
IsWindows = true;
|
||||
IsLinux = false;
|
||||
IsMacOS = false;
|
||||
return With("APPDATA", appData);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public sealed class InMemoryFileSystem : IFileSystem
|
||||
{
|
||||
private readonly Dictionary<string, byte[]> _files = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly HashSet<string> _directories = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly HashSet<string> _executable = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public DateTime LastWriteTimeUtc { get; set; } = new(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
@@ -115,6 +116,16 @@ public sealed class InMemoryFileSystem : IFileSystem
|
||||
|
||||
public DateTime GetLastWriteTimeUtc(string path) => LastWriteTimeUtc;
|
||||
|
||||
/// <summary>Files added through <see cref="WithExecutable"/> carry the execute bit.</summary>
|
||||
public bool IsExecutable(string path) => _executable.Contains(Normalize(path));
|
||||
|
||||
public InMemoryFileSystem WithExecutable(string path, string contents = "\u007fELF")
|
||||
{
|
||||
WithFile(path, contents);
|
||||
_executable.Add(Normalize(path));
|
||||
return this;
|
||||
}
|
||||
|
||||
private byte[] Bytes(string path) =>
|
||||
_files.TryGetValue(Normalize(path), out var bytes)
|
||||
? bytes
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Infrastructure.Adapters;
|
||||
using StarterNG.Infrastructure.Sceneries;
|
||||
using StarterNG.Infrastructure.Settings;
|
||||
using StarterNG.Infrastructure.Vehicles;
|
||||
|
||||
namespace StarterNG.Tests.Fakes;
|
||||
@@ -28,6 +29,11 @@ public sealed class TestInstallation
|
||||
Sceneries = new SceneryRepository(Files, Paths, Log, new SceneryParser(Clock, Random));
|
||||
MissingAssets = new MissingAssetScanner(Files, Paths);
|
||||
Library = new GameLibrary(Vehicles, Sceneries, MiniTextures, Physics, Log);
|
||||
|
||||
Environment = new FakeEnvironment();
|
||||
SettingsPaths = new SettingsPaths(Environment, Paths);
|
||||
Executables = new ExecutableLocator(Files, Paths, Environment, Log);
|
||||
SettingsStore = new SettingsStore(Files, Clock, Log, SettingsPaths, new SettingsSerializer(), Executables);
|
||||
}
|
||||
|
||||
public InMemoryFileSystem Files { get; }
|
||||
@@ -42,6 +48,10 @@ public sealed class TestInstallation
|
||||
public SceneryRepository Sceneries { get; }
|
||||
public MissingAssetScanner MissingAssets { get; }
|
||||
public GameLibrary Library { get; }
|
||||
public FakeEnvironment Environment { get; }
|
||||
public SettingsPaths SettingsPaths { get; }
|
||||
public ExecutableLocator Executables { get; }
|
||||
public SettingsStore SettingsStore { get; }
|
||||
|
||||
/// <summary>Path of a file inside the fake installation.</summary>
|
||||
public static string At(params string[] segments) => Path.Combine(new[] { Root }.Concat(segments).ToArray());
|
||||
|
||||
Reference in New Issue
Block a user