refactor(terminal): decouple scanner via IFingerprintScanner factory and fix test cancellation token
This commit is contained in:
parent
39f0840087
commit
29c70e0107
2 changed files with 9 additions and 3 deletions
|
|
@ -88,7 +88,7 @@ public class ScannerRecoveryTests
|
||||||
int retries = 0;
|
int retries = 0;
|
||||||
while (retries < 5)
|
while (retries < 5)
|
||||||
{
|
{
|
||||||
await Task.Delay(10);
|
await Task.Delay(10, TestContext.Current.CancellationToken);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
scanner.Connect(0, Array.Empty<(int, string)>());
|
scanner.Connect(0, Array.Empty<(int, string)>());
|
||||||
|
|
@ -106,7 +106,7 @@ public class ScannerRecoveryTests
|
||||||
|
|
||||||
scanner.SimulateDisconnect();
|
scanner.SimulateDisconnect();
|
||||||
// Emulate the hardware coming back after a short delay
|
// Emulate the hardware coming back after a short delay
|
||||||
await Task.Delay(20);
|
await Task.Delay(20, TestContext.Current.CancellationToken);
|
||||||
scanner.AddVirtualDevice(0, "SLK20R", "SERIAL"); // ensure device is discoverable if it was cleared
|
scanner.AddVirtualDevice(0, "SLK20R", "SERIAL"); // ensure device is discoverable if it was cleared
|
||||||
|
|
||||||
await reconnectTcs.Task;
|
await reconnectTcs.Task;
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,12 @@ public sealed partial class MainPage : Page
|
||||||
private readonly AttendanceSyncService _attendanceSync = new();
|
private readonly AttendanceSyncService _attendanceSync = new();
|
||||||
private readonly AttendanceTracker _attendanceTracker = new();
|
private readonly AttendanceTracker _attendanceTracker = new();
|
||||||
private readonly TerminalIpcClient _ipcClient = new();
|
private readonly TerminalIpcClient _ipcClient = new();
|
||||||
private readonly FingerprintScanner _scanner = new();
|
private readonly IFingerprintScanner _scanner;
|
||||||
private readonly IUpdateSource _updateSource = new ForgejoUpdateSource();
|
private readonly IUpdateSource _updateSource = new ForgejoUpdateSource();
|
||||||
|
|
||||||
|
/// <summary>Инъекция фабрики для тестирования. По умолчанию создаёт реальный FingerprintScanner.</summary>
|
||||||
|
public static Func<IFingerprintScanner>? ScannerFactory { get; set; }
|
||||||
|
|
||||||
private TerminalState _state = new();
|
private TerminalState _state = new();
|
||||||
private bool _loaded;
|
private bool _loaded;
|
||||||
private TaskCompletionSource<bool>? _adminAuthCompletion;
|
private TaskCompletionSource<bool>? _adminAuthCompletion;
|
||||||
|
|
@ -57,6 +61,8 @@ public sealed partial class MainPage : Page
|
||||||
CrashLogService.Write(exception);
|
CrashLogService.Write(exception);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_scanner = ScannerFactory?.Invoke() ?? new FingerprintScanner();
|
||||||
_scanner.StatusChanged += message => Enqueue(() => SetStatus(message));
|
_scanner.StatusChanged += message => Enqueue(() => SetStatus(message));
|
||||||
_scanner.StateChanged += (state, message) => Enqueue(() => HandleScannerStateChanged(state, message));
|
_scanner.StateChanged += (state, message) => Enqueue(() => HandleScannerStateChanged(state, message));
|
||||||
_scanner.RegistrationProgress += count => Enqueue(() => SetStatus($"Мастер регистрации: принят скан {count}/3. Уберите палец и приложите снова."));
|
_scanner.RegistrationProgress += count => Enqueue(() => SetStatus($"Мастер регистрации: принят скан {count}/3. Уберите палец и приложите снова."));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue