public void StartAndStopAreNotReentrant() { using var watcher = new StatusWatcher(_jf); bool IsRunning() => watcher.GetPrivateField <bool>("_running"); Assert.False(IsRunning()); watcher.Start(); Assert.True(IsRunning()); watcher.Start(); Assert.True(IsRunning()); watcher.Stop(); Assert.False(IsRunning()); watcher.Stop(); Assert.False(IsRunning()); }
public async Task WatcherRaisesTheChangedEventOnStart() { using var watcher = new StatusWatcher(_jf); var ecs = new EventCollector <StatusEntry>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatcherRaisesTheChangedEventOnStart)); var status = await ecs.WaitAsync(() => { watcher.Start(); watcher.Stop(); }).ConfigureAwait(false); Assert.Equal("Status", status.Event); }
public async Task WatchesForChangesInTheStatusFile() { using var dir = new TestFolder(_jf.FullName); using var watcher = new StatusWatcher(new JournalFolder(dir.Name)); watcher.Start(); var ec = new EventCollector <StatusEntry>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatchesForChangesInTheStatusFile)); var status = await ec.WaitAsync(() => dir.WriteText("Status.json", "{\"event\":\"One\"}\r\n")).ConfigureAwait(false); Assert.Equal("One", status.Event); status = await ec.WaitAsync(() => dir.WriteText("Status.json", string.Empty), 100).ConfigureAwait(false); Assert.Null(status); status = await ec.WaitAsync(() => dir.WriteText("Status.json", "{\"event\":\"Two\"}\r\n")).ConfigureAwait(false); Assert.Equal("Two", status.Event); }
public void Start() { if (_running) { return; } _running = true; _graphicsConfig.Start(); _bindingsWatcher.Start(); _statusWatcher.Start(); _modifierKeysWatcher.Start(); _journalWatcher.Start(); if (DetectForegroundProcess) { _gameProcessWatcher.Start(); } }