改进 Config 的延迟写入
This commit is contained in:
1 parent
2d811e8f58
commit
204fc52ba2
2 files changed
+43
-39
No files matched your search
@@ -66,6 +66,21 @@ public class ConfigTest : TestWithFolder {
|
||||
await Assert.That(FileUtils.ReadAsString(configFile)).Contains("\"text\": \"plain text 中文\"");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task JsonConfigProvider_SaveBeforeExit_WritesPendingChangesImmediately() {
|
||||
string configFile = Path.Combine(tempFolder, "config.json");
|
||||
var provider = new JsonConfigProvider(configFile);
|
||||
var entry = new ConfigEntry<string>("text", "fallback", provider);
|
||||
|
||||
entry.Set("pending 中文");
|
||||
provider.SaveBeforeExit();
|
||||
provider.SaveBeforeExit();
|
||||
|
||||
var reloadedEntry = new ConfigEntry<string>("text", "fallback", new JsonConfigProvider(configFile));
|
||||
await Assert.That(reloadedEntry.Get()).IsEqualTo("pending 中文");
|
||||
await Assert.That(FileUtils.ReadAsString(configFile)).Contains("\"text\": \"pending 中文\"");
|
||||
}
|
||||
|
||||
public class TestConfigItem {
|
||||
public string Name { get; set; } = "";
|
||||
public int Count { get; set; }
|
||||
|
||||
Reference in new issue
Block a user