public void RemovedSectionGetsNotificationOnRemovalAndDoesNotGetFurtherNotifications() { ConfigurationChangeSqlWatcher.SetDefaultPollDelayInMilliseconds(100); SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false); object section1 = implementation.GetSection(localSection); Assert.IsNotNull(section1); object section2 = implementation.GetSection(localSection2); Assert.IsNotNull(section2); implementation.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.AddSectionChangeHandler(localSection2, new ConfigurationChangedEventHandler(OnConfigurationChanged)); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Save(ConfigurationSaveMode.Minimal, true); // config source changed notifies both sections implementation.ConfigSourceChanged(externalSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); Assert.AreEqual(1, updatedSectionsTally[localSection2]); rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); implementation.RemoveSection(localSection2); //since localsection2 is removed, localsection2 only gets initial notification Assert.AreEqual(2, updatedSectionsTally[localSection]); Assert.AreEqual(2, updatedSectionsTally[localSection2]); implementation.ConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[localSection]); Assert.AreEqual(2, updatedSectionsTally[localSection2]); }
public void AllRegisteredObjectsAreNotifiedOfDifferentSectionsChanges() { SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false); implementation.GetSection(localSection); implementation.GetSection(localSection2); implementation.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.AddSectionChangeHandler(localSection2, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.ConfigSourceChanged(externalSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); Assert.AreEqual(1, updatedSectionsTally[localSection2]); }
public void AllRegisteredObjectsAreNotifiedOfSectionChanges() { SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false); implementation.GetSection(externalSection); implementation.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[externalSection]); }
public void RestoredSectionGetsNotificationOnRestoreAndGetsFurtherNotifications() { SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false); object section1 = implementation.GetSection(localSection); Assert.IsNotNull(section1); object section2 = implementation.GetSection(localSection2); Assert.IsNotNull(section2); implementation.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.AddSectionChangeHandler(localSection2, new ConfigurationChangedEventHandler(OnConfigurationChanged)); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); implementation.ConfigSourceChanged(externalSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); Assert.AreEqual(1, updatedSectionsTally[localSection2]); // removal of the section notifies both sections rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); implementation.RemoveSection(localSection2); Assert.AreEqual(2, updatedSectionsTally[localSection]); Assert.AreEqual(2, updatedSectionsTally[localSection2]); implementation.ConfigSourceChanged(externalSectionSource); 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 = externalSectionSource; implementation.SaveSection(rwSection.Name, rwSection); implementation.ConfigSourceChanged(externalSectionSource); Assert.AreEqual(4, updatedSectionsTally[localSection]); Assert.AreEqual(3, updatedSectionsTally[localSection2]); }
public void RegisteredObjectForNonRequestedSectionIsNotNotified() { SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false); implementation.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.ConfigSourceChanged(externalSectionSource); Assert.IsFalse(updatedSectionsTally.ContainsKey(localSection)); }
public void CanAddAndRemoveHandlers() { SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false); object section = implementation.GetSection(externalSection); Assert.IsNotNull(section); implementation.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(2, updatedSectionsTally[externalSection]); implementation.RemoveSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[externalSection]); implementation.RemoveSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[externalSection]); }
public void RegisteredObjectIsNotifiedOfSectionChangesIfConfigSourceHasChanged() { SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false); implementation.GetSection(externalSection); implementation.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.ConfigSourceChanged(externalSectionSource); Assert.IsTrue(updatedSectionsTally.ContainsKey(externalSection)); }
public void RegisteredObjectIsNotifiedOfSectionChanges() { SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false); implementation.GetSection(externalSection); implementation.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); implementation.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(1, updatedSectionsTally[externalSection]); }