public void CreateWatchedConfig_AddConfigToCollection_ConfigRemovedFromCollectionWhenFileChanged() { var configs = new ConfigCollection(); File.WriteAllText(filePath, @"<configuration><test value=""Hello World"" /></configuration>"); IConfig config1 = FileConfigFactory.CreateWithWatcher("myCustomKey", filePath); configs.Add(config1); Assert.AreEqual("Hello World", configs["myCustomKey"].GetValue("test")); File.WriteAllText(filePath, @"<configuration><test value=""Hello Universe"" /></configuration>"); for (int retries = 100; retries >= 0; retries--) { if (config1.IsDiscarded) { break; } Thread.Sleep(10); } Assert.IsTrue(config1.IsDiscarded, "config not discarded after 1 second"); Assert.IsFalse(configs.Contains("myCustomKey")); IConfig config2 = FileConfigFactory.Create("myCustomKey", filePath); Assert.AreEqual("Hello Universe", config2.GetValue("test")); }
public void Create_CreateFromFileInfo_ReturnConfigWithoutWatcher() { Assume.That(File.Exists(systemConfigPath)); var config = FileConfigFactory.Create(new FileInfo(systemConfigPath)); Assert.IsNotNull(config); Assert.IsNotNull(config.ConfigSource); Assert.IsNull(config.ConfigSource.Watcher); Assert.AreEqual("System", config.ConfigKey); }
public void Create_CreateFromPathWithCustomKey_ReturnConfigWithoutWatcher() { Assume.That(File.Exists(systemConfigPath)); string key = "myKey"; var config = FileConfigFactory.Create(key, systemConfigPath); Assert.IsNotNull(config); Assert.IsNotNull(config.ConfigSource); Assert.IsNull(config.ConfigSource.Watcher); Assert.AreEqual(key, config.ConfigKey); }
public void Create_CreateFromPathWithCustomSource_ReturnConfigWithCustomSource() { Assume.That(File.Exists(systemConfigPath)); const string key = "myKey"; var source = A.Fake <IConfigSource>(); var config = FileConfigFactory.Create(key, systemConfigPath, source); Assert.IsNotNull(config); Assert.AreEqual(source, config.ConfigSource); Assert.AreEqual(key, config.ConfigKey); }
public void CreateWithWatcher_CreateFromPathNonExistingFile_ReturnConfigWithWatcher() { Assume.That(!File.Exists(nonExistingFile)); Assert.Throws <FileNotFoundException>(() => FileConfigFactory.CreateWithWatcher(nonExistingFile)); }
public void Create_PassingNullFileInfo_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => FileConfigFactory.Create((FileInfo)null, A.Fake <IConfigSource>())); }