public void RestoredSectionGetsNotificationOnRestoreAndGetsFurtherNotifications() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section1 = source.GetSection(localSection); Assert.IsNotNull(section1); object section2 = source.GetSection(localSection2); Assert.IsNotNull(section2); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(localSection2, new ConfigurationChangedEventHandler(OnConfigurationChanged)); // a change in system config notifies both sections System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Save(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); Assert.AreEqual(1, updatedSectionsTally[localSection2]); // removal of the section notifies both sections rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Sections.Remove(localSection2); rwConfiguration.Save(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(2, updatedSectionsTally[localSection]); Assert.AreEqual(2, updatedSectionsTally[localSection2]); // further updates only notify the remaining section rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Save(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(3, updatedSectionsTally[localSection]); Assert.AreEqual(2, updatedSectionsTally[localSection2]); // restore of section gets notified DummySection rwSection = new DummySection(); rwSection.Name = localSection2; rwSection.Value = 30; rwSection.SectionInformation.ConfigSource = localSectionSource; rwConfiguration.Sections.Add(localSection2, rwSection); rwConfiguration.Save(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(4, updatedSectionsTally[localSection]); Assert.AreEqual(3, updatedSectionsTally[localSection2]); // further updates notify both sections rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Save(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(5, updatedSectionsTally[localSection]); Assert.AreEqual(4, updatedSectionsTally[localSection2]); }
public void AllRegisteredObjectsAreNotifiedOfSectionChangesForExternalFile() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(externalSection); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[externalSection]); }
public void AllRegisteredObjectsAreNotifiedOfDifferentSectionsChangesForAppConfig() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(localSection); source.GetSection(localSection2); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(localSection2, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); Assert.AreEqual(1, updatedSectionsTally[localSection2]); }
public void CanStopReceivingNotificationsFromImplementation() { SystemConfigurationSource.ResetImplementation(false); SystemConfigurationSource source = new SystemConfigurationSource(); source.GetSection(localSection); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); SystemConfigurationSource.Implementation.ConfigSourceChanged(localSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); source.RemoveSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); SystemConfigurationSource.Implementation.ConfigSourceChanged(localSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); SystemConfigurationSource.Implementation.ConfigSourceChanged(localSectionSource); Assert.AreEqual(2, updatedSectionsTally[localSection]); }
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 RegisteredObjectForNonRequestedSectionIsNotNotified() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ConfigSourceChanged(localSectionSource); Assert.IsFalse(updatedSectionsTally.ContainsKey(localSection)); }
public void CanAddAndRemoveHandlers() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section = source.GetSection(externalSection); Assert.IsNotNull(section); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(2, updatedSectionsTally[externalSection]); source.RemoveSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[externalSection]); source.RemoveSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[externalSection]); }
public void RegisteredObjectForExternalFileIsNotifiedOfSectionChangesForAppConfigIfConfigSourceForExternalSectionNotChanged() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(externalSection); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ConfigSourceChanged(localSectionSource); Assert.IsFalse(updatedSectionsTally.ContainsKey(externalSection)); }
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); } } }
public void DifferentSqlConfigurationSourcesDoNotShareEvents() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); SqlConfigurationSource.ResetImplementation(data1, true); SystemConfigurationSource.ResetImplementation(true); bool sysSourceChanged = false; bool otherSourceChanged = false; SystemConfigurationSource systemSource = new SystemConfigurationSource(); DummySection sysDummySerializableSection = systemSource.GetSection(localSection) as DummySection; SqlConfigurationSource otherSource = new SqlConfigurationSource( data1.ConnectionString, data1.GetStoredProcedure, data1.SetStoredProcedure, data1.RefreshStoredProcedure, data1.RemoveStoredProcedure); SqlConfigurationParameter parameter = new SqlConfigurationParameter( data1.ConnectionString, data1.GetStoredProcedure, data1.SetStoredProcedure, data1.RefreshStoredProcedure, data1.RemoveStoredProcedure); otherSource.Add(parameter, localSection, sysDummySerializableSection); DummySection otherDummySerializableSection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(sysDummySerializableSection != null); Assert.IsTrue(otherDummySerializableSection != 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.OpenMachineConfiguration(); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = data1.ConnectionString; SqlConfigurationManager.SaveSection(rwSection.Name, rwSection, data1); Thread.Sleep(200); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); }