public async Task WatchesForChangesInTheGraphicsConfigurationFiles() { using var dirMain = new TestFolder(_gif.FullName); using var dirOpts = new TestFolder(_gof.FullName); using var watcher = new GraphicsConfigWatcher(new GameInstallFolder(dirMain.Name), new GameOptionsFolder(dirOpts.Name)); watcher.Start(); var evs = new EventCollector <GraphicsConfig>(h => watcher.Changed += h, h => watcher.Changed -= h); var xmlMain = dirMain.ReadText(_mainFile); var config = await evs.WaitAsync(() => dirMain.WriteText(_mainFile, string.Empty), 100).ConfigureAwait(false); Assert.Null(config); config = await evs.WaitAsync(() => dirMain.WriteText(_mainFile, xmlMain)).ConfigureAwait(false); Assert.Equal(0, config.GuiColour.Default[0, 0]); config = await evs.WaitAsync(() => dirOpts.WriteText(_overrideFile, string.Empty), 100).ConfigureAwait(false); Assert.Null(config); config = await evs.WaitAsync(() => dirOpts.WriteText(_overrideFile, _minimalConfig)).ConfigureAwait(false); Assert.Equal(1, config.GuiColour.Default[0, 0]); }
public async Task WatcherRaisesEventsForNewJournalEntries() { using var dir = new TestFolder(_jf.FullName); using var watcher = new JournalWatcher(new JournalFolder(dir.Name)); var ecEntries = new EventCollector <JournalEntry>(h => watcher.EntryAdded += h, h => watcher.EntryAdded -= h, nameof(WatcherRaisesEventsForNewJournalEntries)); var ecReady = new EventCollector <EventArgs>(h => watcher.Started += h, h => watcher.Started -= h, nameof(WatcherRaisesEventsForNewJournalEntries)); var ev = await ecReady.WaitAsync(watcher.Start).ConfigureAwait(false); Assert.NotNull(ev); Assert.True(watcher.IsWatching); ev = await ecReady.WaitAsync(watcher.Start, 100).ConfigureAwait(false); Assert.Null(ev); var entry = await ecEntries.WaitAsync(() => dir.WriteText(_journalFile1, "{ \"event\":\"One\" }\r\n", true)).ConfigureAwait(false); Assert.Equal("One", entry.Event); var file2 = _journalFile1.Replace(".01.log", ".02.log", StringComparison.Ordinal); entry = await ecEntries.WaitAsync(() => dir.WriteText(file2, "{ \"event\":\"Two\" }\r\n")).ConfigureAwait(false); Assert.Equal("Two", entry.Event); watcher.Stop(); Assert.False(watcher.IsWatching); }
public async Task WatcherRaisesTheChangedEventOnStart() { using var watcher = new BindingsWatcher(_gif, _gof); var evs = new EventCollector <BindingPreset>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatcherRaisesTheChangedEventOnStart)); var binds = await evs.WaitAsync(() => { watcher.Start(); watcher.Stop(); }).ConfigureAwait(false); Assert.Null(binds.PresetName); // "Custom" and "Custom2" get merged to null. Assert.Equal(new Version(3, 0), binds.Version); Assert.Equal("es-ES", binds.KeyboardLayout); var k = binds.Bindings["Supercruise"].Primary; Assert.Equal("Keyboard", k.Device); Assert.Equal("Key_H", k.Key); Assert.Equal(2, k.Modifiers.Count); var modifiers = k.Modifiers.OrderBy(x => x.Key).ToList(); Assert.Equal("Keyboard", modifiers[0].Device); Assert.Equal("Key_LeftAlt", modifiers[0].Key); Assert.Equal("Keyboard", modifiers[1].Device); Assert.Equal("Key_LeftShift", modifiers[1].Key); }
public async Task WatcherRaisesEventsForHistoricalEntriesOnStart() { using var watcher = new JournalWatcher(_jf); var ecEntries = new EventCollector <JournalEntry>(h => watcher.EntryAdded += h, h => watcher.EntryAdded -= h, nameof(WatcherRaisesEventsForHistoricalEntriesOnStart)); var ecReady = new EventCollector <EventArgs>(h => watcher.Started += h, h => watcher.Started -= h, nameof(WatcherRaisesEventsForHistoricalEntriesOnStart)); var readyTask = ecReady.WaitAsync(() => { }); var entries = new Queue <JournalEntry>(await ecEntries.WaitAsync(_journalFile1Count, () => { watcher.Start(); Assert.False(watcher.IsWatching); }).ConfigureAwait(false)); var ready = await readyTask.ConfigureAwait(false); Assert.NotNull(ready); Assert.True(watcher.IsWatching); watcher.Stop(); Assert.False(watcher.IsWatching); Assert.Equal(_journalFile1Count, entries.Count); Assert.IsType <FileHeader>(entries.Dequeue()); Assert.IsType <Music>(entries.Dequeue()); Assert.IsType <UnderAttack>(entries.Dequeue()); Assert.IsType <StartJump>(entries.Dequeue()); Assert.IsType <JournalEntry>(entries.Dequeue()); Assert.IsType <Shutdown>(entries.Dequeue()); }
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 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 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 WatcherRaisesTheChangedEventOnStart() { using var watcher = new GraphicsConfigWatcher(_gif, _gof); var evs = new EventCollector <GraphicsConfig>(h => watcher.Changed += h, h => watcher.Changed -= h); var config = await evs.WaitAsync(() => { watcher.Start(); watcher.Stop(); }).ConfigureAwait(false); Assert.Null(config.GuiColour.Default.LocalisationName); }
public async Task RazerChromaApiGetsCalledOnGameEvents() { const string statusFile = "Status.json"; const string journalFile = "Journal.190101020000.01.log"; var chromaApi = new ChromaApiMock(); var evs = new EventCollector <ChromaApiMock.MockCall>(h => chromaApi.Called += h, h => chromaApi.Called -= h); using TestFolder dirRoot = new TestFolder(_gameRootFolder), dirOpts = new TestFolder(_gameOptionsFolder), dirJournal = new TestFolder(); dirJournal.WriteText(statusFile, EventSequence.BuildEvent("Status", new { Flags = 0 })); dirJournal.WriteText(journalFile, EventSequence.BuildEvent("Fileheader", new { part = 1, language = @"English\UK", gameversion = "3.5.0.200 EDH", build = "r210198/r0 " })); using var cc = new ChromaController(dirRoot.Name, dirOpts.Name, dirJournal.Name) { ChromaApi = chromaApi, AnimationFrameRate = 0, DetectGameInForeground = false, }; var mcs = await evs.WaitAsync(5, cc.Start, 1000).ConfigureAwait(false); Assert.Equal("InitializeAsync", mcs[0].Method); Assert.Equal("CreateKeyboardEffectAsync", mcs[1].Method); var seq = BuildEventSequence(); mcs = await evs.WaitAsync(seq.Count, () => seq.Play(dirJournal, journalFile, statusFile), 200 *seq.Count).ConfigureAwait(false); Assert.Equal(seq.Count, mcs.Count); var mc = await evs.WaitAsync(cc.Stop, 1000).ConfigureAwait(false); Assert.Equal("UninitializeAsync", mc.Method); }
public async Task WatchesForChangesInTheBidingsFiles() { using var dirMain = new TestFolder(_gif.FullName); using var dirOpts = new TestFolder(_gof.FullName); using var watcher = new BindingsWatcher(new GameInstallFolder(dirMain.Name), new GameOptionsFolder(dirOpts.Name)); watcher.Start(); var evs = new EventCollector <BindingPreset>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatchesForChangesInTheBidingsFiles)); var bindsCustom = dirOpts.ReadText(_customFile); var binds = await evs.WaitAsync(() => dirOpts.WriteText(_customFile, string.Empty), 100).ConfigureAwait(false); Assert.Null(binds); binds = await evs.WaitAsync(() => dirOpts.WriteText(_customFile, bindsCustom)).ConfigureAwait(false); Assert.NotNull(binds); binds = await evs.WaitAsync(() => dirOpts.WriteText(_startPresetFile, "Keyboard")).ConfigureAwait(false); Assert.NotNull(binds); }
public async Task WatcherToleratesEmptyGraphicsConfigurationOverrideFiles() { using var dirOpts = new TestFolder(_gof.FullName); dirOpts.WriteText(_overrideFile, string.Empty); using var watcher = new GraphicsConfigWatcher(_gif, new GameOptionsFolder(dirOpts.Name)); var evs = new EventCollector <GraphicsConfig>(h => watcher.Changed += h, h => watcher.Changed -= h, nameof(WatcherRaisesTheChangedEventOnStart)); var config = await evs.WaitAsync(() => { watcher.Start(); watcher.Stop(); }).ConfigureAwait(false); Assert.Equal("Standard", config.GuiColour.Default.LocalisationName); }