public void RemovedHandlerReceivesNoFurtherNotifications() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(2, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[localSection1]); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); instance.RemoveSectionChangeHandler(localSection1, OnConfigurationSectionChange); valuesForNotifiedSections.Clear(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }
public void ChangeOnExternalConfigurationFileNotifiesHandlersForTheExternalSectionOnlyIfNoOtherSectionsWereRemoved() { // if the file for a section's config source changes only that section can be affected. // even though the configuration object is reloaded entirely, changes for other sections are not notified // if there were any changes in other sections, then other configuration files would have changed and // notifications for these changes would be issued before of after the section's configuration source file // i.e. the appropriate notifications will be issued, eventually // the only exception is for removed or restored sections, tested elsewhere MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs("test.external.config")); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }
public void ChangeOnMainConfigurationFileNotifiesHandlersForAllSections() { // if the main configuration file changes, sections with specified config sources might have changed // since the configuration object must be reload entirely, and config sections with specified config sources are // rare, notifying all the sections is a sensible trade off MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(2, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[localSection1]); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }
public void ChangeOnExternalConfigurationFileNotifiesHandlersForOtherRemovedSections() { // if a removed section is detected it should be notified when the external file changes // as processing the main change file later will break the logic that deals with deletions MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); rwConfiguration.Sections.Remove(localSection1); rwConfiguration.Save(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs("test.external.config")); Assert.AreEqual(2, valuesForNotifiedSections.Count); Assert.AreEqual(null, valuesForNotifiedSections[localSection1]); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }
public void RegisteredForChangesOnLocalReceivesNotificationsOnMainConfigurationFileUpdateWithUpdatedValuesAvailable() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.GetSection(localSection1); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); TestsConfigurationSection rwTestConfigurationSection = (TestsConfigurationSection)rwConfiguration.GetSection(localSection1); rwTestConfigurationSection.Value = "value2"; rwConfiguration.Save(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("value2", valuesForNotifiedSections[localSection1]); }
public void ChangeOnMainConfigurationFileNotifiesHandlerForRestoredSection() { // if the section existed once, then registered handlers must be notified when the removal // is detected, but after that they shouldn't be notified while the section is still deleted // and they should be notified if the configuration section shows MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); TestsConfigurationSection section = (TestsConfigurationSection)instance.GetSection(localSection1); Assert.IsNotNull(section); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[localSection1]); rwConfiguration.Sections.Remove(localSection1); rwConfiguration.Save(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual(null, valuesForNotifiedSections[localSection1]); valuesForNotifiedSections.Clear(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(0, valuesForNotifiedSections.Count); // second time, no notification // restore the section and notify again rwConfiguration.Sections.Add(localSection1, new TestsConfigurationSection("valuenew")); rwConfiguration.Save(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("valuenew", valuesForNotifiedSections[localSection1]); }
public void ChangeOnGroupPoliciesNotifiesHandlersForAllSections() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); policyRegistrationBuilder.LastRegistration.MachinePolicyEvent.Set(); // fire the notification Thread.Sleep(250); Assert.AreEqual(2, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[localSection1]); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }
public void ChangeOnMainConfigurationFileDoesNotNotifyHandlerForNonExistingSection() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler("non existing", OnConfigurationSectionChange); ConfigurationSection section = instance.GetSection("non existing"); Assert.IsNull(section); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(0, valuesForNotifiedSections.Count); }
public void ChangeOnMainConfigurationFileDoesNotNotifyHandlerForExistingSectionNeverRequested() { // if the section has never been requested, then there's no point in notifying // for its (possible) changes. MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); // make sure it's not requested instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(0, valuesForNotifiedSections.Count); }
public void ChangeOnMainConfigurationFileNotifiesHandlerForRestoredSection() { // if the section existed once, then registered handlers must be notified when the removal // is detected, but after that they shouldn't be notified while the section is still deleted // and they should be notified if the configuration section shows MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); TestsConfigurationSection section = (TestsConfigurationSection)instance.GetSection(localSection1); Assert.IsNotNull(section); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[localSection1]); rwConfiguration.Sections.Remove(localSection1); rwConfiguration.Save(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual(null, valuesForNotifiedSections[localSection1]); valuesForNotifiedSections.Clear(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(0, valuesForNotifiedSections.Count); // second time, no notification // restore the section and notify again rwConfiguration.Sections.Add(localSection1, new TestsConfigurationSection("valuenew")); rwConfiguration.Save(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("valuenew", valuesForNotifiedSections[localSection1]); }
public void ChangeOnMainConfigurationFileNotifiesHandlersForAllSections() { // if the main configuration file changes, sections with specified config sources might have changed // since the configuration object must be reload entirely, and config sections with specified config sources are // rare, notifying all the sections is a sensible trade off MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(2, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[localSection1]); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }
public void ChangeOnGroupPoliciesNotifiesHandlersForAllSections() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); Thread.Sleep(100); // let the watching thread start policyRegistrationBuilder.LastRegistration.MachinePolicyEvent.Set(); // fire the notification Thread.Sleep(250); Assert.AreEqual(2, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[localSection1]); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }
public void RemovedHandlerReceivesNoFurtherNotifications() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(2, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[localSection1]); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); instance.RemoveSectionChangeHandler(localSection1, OnConfigurationSectionChange); valuesForNotifiedSections.Clear(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }
public void ChangeOnExternalConfigurationFileNotifiesHandlersForTheExternalSectionOnlyIfNoOtherSectionsWereRemoved() { // if the file for a section's config source changes only that section can be affected. // even though the configuration object is reloaded entirely, changes for other sections are not notified // if there were any changes in other sections, then other configuration files would have changed and // notifications for these changes would be issued before of after the section's configuration source file // i.e. the appropriate notifications will be issued, eventually // the only exception is for removed or restored sections, tested elsewhere MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs("test.external.config")); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }
public void RegisteredForChangesOnLocalReceivesNotificationsOnMainConfigurationFileUpdateWithUpdatedValuesAvailable() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.GetSection(localSection1); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); TestsConfigurationSection rwTestConfigurationSection = (TestsConfigurationSection)rwConfiguration.GetSection(localSection1); rwTestConfigurationSection.Value = "value2"; rwConfiguration.Save(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(1, valuesForNotifiedSections.Count); Assert.AreEqual("value2", valuesForNotifiedSections[localSection1]); }
public void ChangeOnMainConfigurationFileDoesNotNotifyHandlerForNonExistingSection() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler("non existing", OnConfigurationSectionChange); ConfigurationSection section = instance.GetSection("non existing"); Assert.IsNull(section); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(0, valuesForNotifiedSections.Count); }
public void ChangeOnMainConfigurationFileDoesNotNotifyHandlerForExistingSectionNeverRequested() { // if the section has never been requested, then there's no point in notifying // for its (possible) changes. MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); // make sure it's not requested instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.AreEqual(0, valuesForNotifiedSections.Count); }
public void ChangeOnExternalConfigurationFileNotifiesHandlersForOtherRestoredSections() { // if a removed section is detected it should be notified when the external file changes // as processing the main change file later will break the logic that deals with deletions MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); instance.AddSectionChangeHandler(externalSection1, OnConfigurationSectionChange); instance.GetSection(localSection1); instance.GetSection(externalSection1); rwConfiguration.Sections.Remove(localSection1); rwConfiguration.Save(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs("test.external.config")); rwConfiguration.Sections.Add(localSection1, new TestsConfigurationSection("valuerestored")); rwConfiguration.Save(); valuesForNotifiedSections.Clear(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs("test.external.config")); Assert.AreEqual(2, valuesForNotifiedSections.Count); Assert.AreEqual("valuerestored", valuesForNotifiedSections[localSection1]); Assert.AreEqual("value1", valuesForNotifiedSections[externalSection1]); }