public void DifferentFileConfigurationSourcesDoNotShareEvents() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); FileConfigurationSource.ResetImplementation(otherConfigurationFile, true); SystemConfigurationSource.ResetImplementation(true); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { bool sysSourceChanged = false; bool otherSourceChanged = false; SystemConfigurationSource systemSource = new SystemConfigurationSource(); FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile); DummySection sysDummySection = systemSource.GetSection(localSection) as DummySection; DummySection otherDummySection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(sysDummySection != null); Assert.IsTrue(otherDummySection != null); systemSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { sysSourceChanged = true; }); otherSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.AreEqual(12, ((DummySection)otherSource.GetSection(localSection)).Value); otherSourceChanged = true; }); DummySection rwSection = new DummySection(); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(otherConfigurationFile); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = localSectionSource; rwConfiguration.SaveAs(otherConfigurationFile); Thread.Sleep(200); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void RemovingSectionCausesChangeNotification() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { bool otherSourceChanged = false; using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, true, 50)) { DummySection otherDummySection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(otherDummySection != null); otherSource.AddSectionChangeHandler( localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.IsNull(otherSource.GetSection(localSection)); otherSourceChanged = true; }); otherSource.Remove(localSection); Thread.Sleep(300); Assert.AreEqual(true, otherSourceChanged); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void RemovingSectionCausesChangeNotification() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { bool otherSourceChanged = false; using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, true, 50)) { DummySection otherDummySection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(otherDummySection != null); otherSource.AddSectionChangeHandler( localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.IsNull(otherSource.GetSection(localSection)); otherSourceChanged = true; }); otherSource.Remove(localSection); Thread.Sleep(300); Assert.AreEqual(true, otherSourceChanged); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void DifferentFileConfigurationSourcesDoNotShareEvents() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { bool sysSourceChanged = false; bool otherSourceChanged = false; using (SystemConfigurationSource systemSource = new SystemConfigurationSource(true, 50)) using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, true, 50)) { DummySection sysDummySection = systemSource.GetSection(localSection) as DummySection; DummySection otherDummySection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(sysDummySection != null); Assert.IsTrue(otherDummySection != null); systemSource.AddSectionChangeHandler( localSection, delegate(object o, ConfigurationChangedEventArgs args) { sysSourceChanged = true; }); otherSource.AddSectionChangeHandler( localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.AreEqual(12, ((DummySection)otherSource.GetSection(localSection)).Value); otherSourceChanged = true; }); DummySection rwSection = new DummySection(); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(otherConfigurationFile); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = localSectionSource; rwConfiguration.SaveAs(otherConfigurationFile); Thread.Sleep(500); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }