public void RaisesEventsForEachGameStateChange() { var expected = new[] { ChangeType.StatusEntry, ChangeType.BindingPreset, ChangeType.GraphicsConfig, ChangeType.DeviceKeySet, ChangeType.GameProcessState, ChangeType.JournalEntry, ChangeType.JournalEntry, ChangeType.JournalEntry, ChangeType.JournalDrain, }; using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder) { RaisePreStartupEvents = true, }; var evs = new EventCollector <ChangeType>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(RaisesEventsForEachGameStateChange)); var events = evs.Wait(expected.Length, watcher.Start, 5000); watcher.Stop(); var mismatches = expected.Except(events); Assert.Empty(mismatches); }
public async Task RaisesEventsForEachGameStateChange() { using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder); var evs = new EventCollector <EventArgs>(h => watcher.Changed += h, h => watcher.Changed -= h); await evs.WaitAsync(10, watcher.Start, 5000).ConfigureAwait(false); watcher.Stop(); }
public void StartAndStopAreNotReentrant() { using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder); 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 void RaisesEventsForEachGameStateChange() { using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder) { RaisePreStartupEvents = true, }; var evs = new EventCollector <EventArgs>(h => watcher.Changed += h, h => watcher.Changed -= h); evs.Wait(8, watcher.Start, 5000); watcher.Stop(); }
public void OnChangedIsNotReentrant() { using var watcher = new GameStateWatcher(_gameRootFolder, _gameOptionsFolder, _journalFolder) { RaisePreStartupEvents = false, }; var evs = new EventCollector <ChangeType>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(OnChangedIsNotReentrant)); evs.Wait(watcher.Start, 5000); var nOnChangedCalls = 0; using var mre = new ManualResetEventSlim(); watcher.Changed += (sender, e) => { Interlocked.Increment(ref nOnChangedCalls); mre.Wait(); }; void OnChanged() { watcher.InvokePrivateMethod <object>("OnChanged", new object[] { null }); mre.Set(); } Task.WaitAll(new[] { Task.Run(OnChanged), Task.Run(OnChanged), }); watcher.Stop(); Assert.Equal(1, nOnChangedCalls); }