using System.IO; using ivf_tl_Operate.Helpers; using Xunit; namespace ivf_tl_Operate.Tests { public class SharedConfigStoreTests { private static string TempFile() => Path.Combine(Path.GetTempPath(), "tl-shared-test-" + Path.GetRandomFileName() + ".config"); [Fact] public void Read_missing_file_returns_null() { var path = TempFile(); Assert.Null(SharedConfigStore.Read(path, "urlIp")); } [Fact] public void Write_then_Read_roundtrips() { var path = TempFile(); try { SharedConfigStore.Write(path, "urlIp", "http://10.0.0.5"); SharedConfigStore.Write(path, "urlPort", "10010"); Assert.Equal("http://10.0.0.5", SharedConfigStore.Read(path, "urlIp")); Assert.Equal("10010", SharedConfigStore.Read(path, "urlPort")); } finally { File.Delete(path); } } [Fact] public void Write_existing_key_updates_value() { var path = TempFile(); try { SharedConfigStore.Write(path, "mqttIp", "192.168.0.108"); SharedConfigStore.Write(path, "mqttIp", "192.168.0.200"); Assert.Equal("192.168.0.200", SharedConfigStore.Read(path, "mqttIp")); } finally { File.Delete(path); } } [Fact] public void Written_file_is_appSettings_fragment() { var path = TempFile(); try { SharedConfigStore.Write(path, "kfkaIP", "192.168.0.108"); var text = File.ReadAllText(path); Assert.Contains("", text); Assert.Contains("key=\"kfkaIP\"", text); } finally { File.Delete(path); } } } }