using Febe.Core.Abstractions; using Febe.Desktop.Core; namespace Febe.Tests.Windows.Support; /// /// A clock that compresses time, like the one of the Linux suite: waits for real only a fraction /// of the requested time and moves on by the whole of it, so the engine keeps its order of events /// while a session lasts minutes instead of hours. /// internal sealed class CompressedClock(double factor, TimeZoneInfo zone) : IClock { private readonly Lock _gate = new(); private TimeSpan _offset; public TimeZoneInfo LocalZone { get; } = zone; public DateTimeOffset Now { get { lock (_gate) { return DateTimeOffset.UtcNow + _offset; } } } public async Task Delay(TimeSpan time, CancellationToken ct) { if (time <= TimeSpan.Zero) { ct.ThrowIfCancellationRequested(); return; } var real = TimeSpan.FromTicks((long)(time.Ticks / factor)); if (real >= TimeSpan.FromMilliseconds(1)) { await Task.Delay(real, ct).ConfigureAwait(false); } else { ct.ThrowIfCancellationRequested(); await Task.Yield(); } lock (_gate) { _offset += time - real; } } } internal static class TestZones { /// /// A fixed-offset zone where it is between 12:00 and 13:00 now: inside the active window of every caution profile, /// whatever the hour of the test. /// public static TimeZoneInfo Noon() { var offset = 12 - DateTimeOffset.UtcNow.Hour; return TimeZoneInfo.CreateCustomTimeZone("Febe/Mezzogiorno", TimeSpan.FromHours(offset), "Mezzogiorno di prova", "Mezzogiorno di prova"); } } /// The registry values «CartellaDati» and «NuovaCartellaDati», in memory. internal sealed class MemoryLocations : IDataFolderLocationStore { public string? Current { get; private set; } public string? Pending { get; private set; } public void SetCurrent(string? folder) => Current = folder; public void SetPending(string? folder) => Pending = folder; }