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 WatchedSectionInAppConfigValuesAreUpdatedIfAppConfigChangesAndNotificationIsFired() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section1 = source.GetSection(localSection); Assert.IsNotNull(section1); DummySection dummySection1 = section1 as DummySection; Assert.AreEqual(localSection, dummySection1.Name); Assert.AreEqual(10, dummySection1.Value); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); DummySection rwSection = rwConfiguration.GetSection(localSection) as DummySection; rwSection.Value = 15; rwConfiguration.Save(); source.ConfigSourceChanged(localSectionSource); section1 = source.GetSection(localSection); Assert.IsNotNull(section1); dummySection1 = section1 as DummySection; Assert.AreEqual(localSection, dummySection1.Name); Assert.AreEqual(15, dummySection1.Value); }
public void WatchedExistingSectionInExternalFileIsNoLongerWatchedIfRemovedFromConfigurationAndExternalFileWatcherIsRemoved() { IConfigurationSourceTest source = new SystemConfigurationSource(false); DummySection dummySection1 = source.GetSection(localSection) as DummySection; DummySection dummySection2 = source.GetSection(externalSection) as DummySection; Assert.IsNotNull(dummySection1); Assert.IsNotNull(dummySection2); Assert.AreEqual(2, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.IsTrue(source.WatchedConfigSources.Contains(externalSectionSource)); Assert.AreEqual(3, source.WatchedSections.Count); //watches ConfigurationSourceSection + externalSection + localSection Assert.IsTrue(source.WatchedSections.Contains(localSection)); Assert.IsTrue(source.WatchedSections.Contains(externalSection)); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Sections.Remove(externalSection); rwConfiguration.Save(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(2, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.IsTrue(source.WatchedConfigSources.Contains(SystemConfigurationSource.NullConfigSource)); Assert.AreEqual(3, source.WatchedSections.Count); Assert.IsTrue(source.WatchedSections.Contains(localSection)); Assert.IsTrue(source.WatchedSections.Contains(externalSection)); Assert.AreEqual(2, source.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Count); Assert.IsTrue(source.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Contains(localSection)); Assert.AreEqual(1, source.ConfigSourceWatcherMappings[SystemConfigurationSource.NullConfigSource].WatchedSections.Count); Assert.IsTrue(source.ConfigSourceWatcherMappings[SystemConfigurationSource.NullConfigSource].WatchedSections.Contains(externalSection)); }
public void RegisteredObjectForNonRequestedSectionIsNotNotified() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ConfigSourceChanged(localSectionSource); Assert.IsFalse(updatedSectionsTally.ContainsKey(localSection)); }
public void GetsNotifiedOfSingleRetrievedSection() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(localSection); source.SourceChanged += this.OnConfigurationSourceChanged; source.ConfigSourceChanged(localSectionSource); CollectionAssert.AreEquivalent(new[] { ConfigurationSourceSection.SectionName, localSection }, new List <string>(updatedSections)); }
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 RegisteredObjectIsNotifiedOfSectionChangesForAppConfig() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(localSection); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); }
public void GetsNotifiedOfMultipleRetrievedSection() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(localSection); source.GetSection(localSection2); source.SourceChanged += this.OnConfigurationSourceChanged; source.ConfigSourceChanged(localSectionSource); CollectionAssert.AreEquivalent(new[] { ConfigurationSourceSection.SectionName, localSection, localSection2 }, new List<string>(updatedSections)); }
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]); }