namespace Nonemm.Recorder.Tests; public class RecorderConfigStoreTests : IDisposable { private readonly string folder = Path.Combine(Path.GetTempPath(), $"recorder-{Guid.NewGuid():N}"); public void Dispose() { if (Directory.Exists(folder)) { Directory.Delete(folder, true); } } [Fact] public void A_missing_file_gives_32_kbps_and_no_channels() { RecorderConfig config = new RecorderConfigStore(Path.Combine(folder, "none.json")).Load(); Assert.Equal(32, config.BitrateKbps); Assert.Empty(config.Channels); } [Fact] public void Channels_that_were_saved_come_back_in_order() { RecorderConfigStore store = new(Path.Combine(folder, "config.json")); store.Save(new RecorderConfig { BitrateKbps = 48, Channels = [new("Line In", false, 1, 2), new("Speakers", true, 0, 2)], }); RecorderConfig loaded = store.Load(); Assert.Equal(48, loaded.BitrateKbps); Assert.Equal(["Line In R", "Speakers (output) L"], loaded.Channels.Select(channel => channel.Label)); } [Fact] public void A_file_that_is_not_json_throws_with_its_path() { Directory.CreateDirectory(folder); string path = Path.Combine(folder, "config.json"); File.WriteAllText(path, "not json"); InvalidDataException error = Assert.Throws(() => new RecorderConfigStore(path).Load()); Assert.Contains(path, error.Message); } }