| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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("<appSettings>", text);
- Assert.Contains("key=\"kfkaIP\"", text);
- }
- finally { File.Delete(path); }
- }
- [Fact]
- public void Write_null_value_reads_back_empty_string()
- {
- var path = TempFile();
- try
- {
- SharedConfigStore.Write(path, "urlIp", null);
- Assert.Equal("", SharedConfigStore.Read(path, "urlIp"));
- }
- finally { File.Delete(path); }
- }
- [Fact]
- public void Write_value_with_xml_special_chars_roundtrips()
- {
- var path = TempFile();
- try
- {
- var v = "http://a&b<c>\"d\"";
- SharedConfigStore.Write(path, "urlIp", v);
- Assert.Equal(v, SharedConfigStore.Read(path, "urlIp"));
- }
- finally { File.Delete(path); }
- }
- }
- }
|