public void MultipleRequestsForExistingAndNonExistingSectionsAreRecordedOnce() { Mocks.TestsConfigurationSection existingSection1 = new Mocks.TestsConfigurationSection(); configuration.Sections.Add("section1", existingSection1); Mocks.TestsConfigurationSection existingSection4 = new Mocks.TestsConfigurationSection(); configuration.Sections.Add("section4", existingSection4); ConfigurationSection section = configurationAccessor.GetSection("section1"); Assert.AreSame(existingSection1, section); section = configurationAccessor.GetSection("section2"); Assert.IsNull(section); section = configurationAccessor.GetSection("section3"); Assert.IsNull(section); section = configurationAccessor.GetSection("section4"); Assert.AreSame(existingSection4, section); List <String> sectionNames = CreateCollectionFromEnumerable(configurationAccessor.GetRequestedSectionNames()); Assert.AreEqual(4, sectionNames.Count); Assert.IsTrue(sectionNames.Contains("section1")); Assert.IsTrue(sectionNames.Contains("section2")); Assert.IsTrue(sectionNames.Contains("section3")); Assert.IsTrue(sectionNames.Contains("section4")); }
public void CanGetUpdatedConfigurationValuesAfterFileChangeNotification() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(localSection1, externalSection1); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); manageabilityHelper.updateCalled = false; Mocks.TestsConfigurationSection testConfigurationSection = (Mocks.TestsConfigurationSection)instance.GetSection(localSection1); Assert.IsNotNull(testConfigurationSection); Assert.AreEqual("value1", testConfigurationSection.Value); Mocks.TestsConfigurationSection rwTestConfigurationSection = (Mocks.TestsConfigurationSection)rwConfiguration.GetSection(localSection1); rwTestConfigurationSection.Value = "value2"; rwConfiguration.Save(); watcherCoordinator.OnConfigurationChanged(null, new ConfigurationChangedEventArgs(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); testConfigurationSection = (Mocks.TestsConfigurationSection)instance.GetSection(localSection1); Assert.IsNotNull(testConfigurationSection); Assert.AreEqual("value2", testConfigurationSection.Value); Assert.AreNotSame(rwTestConfigurationSection, testConfigurationSection); }
private void OnConfigurationSectionChange(object sender, ConfigurationChangedEventArgs e) { Mocks.TestsConfigurationSection section = (TestsConfigurationSection)instance.GetSection(e.SectionName); valuesForNotifiedSections[e.SectionName] = section != null ? section.Value : null; }
public void CanRequestExistingSection() { Mocks.TestsConfigurationSection existingSection = new Mocks.TestsConfigurationSection(); configuration.Sections.Add("section", existingSection); ConfigurationSection section = configurationAccessor.GetSection("section"); Assert.AreSame(existingSection, section); }
public void CanRemoveExistingSection() { Mocks.TestsConfigurationSection existingSection = new Mocks.TestsConfigurationSection(); configuration.Sections.Add("section", existingSection); Assert.IsNotNull(configurationAccessor.GetSection("section")); configurationAccessor.RemoveSection("section"); Assert.IsNull(configurationAccessor.GetSection("section")); }
public void RequestForExistingSectionIsRecorded() { Mocks.TestsConfigurationSection existingSection = new Mocks.TestsConfigurationSection(); configuration.Sections.Add("section", existingSection); ConfigurationSection section = configurationAccessor.GetSection("section"); List <String> sectionNames = CreateCollectionFromEnumerable(configurationAccessor.GetRequestedSectionNames()); Assert.AreEqual(1, sectionNames.Count); Assert.IsTrue(sectionNames.Contains("section")); }
public void CanGetSection() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(localSection1, externalSection1); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); Mocks.TestsConfigurationSection testConfigurationSection = (Mocks.TestsConfigurationSection)instance.GetSection(externalSection1); Assert.IsNotNull(testConfigurationSection); Assert.AreEqual("value1", testConfigurationSection.Value); }
public void RequestForNonExistingSectionDoesNotAddWatcher() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); Assert.IsTrue(manageabilityHelper.updateCalled); Assert.AreEqual(1, watcherCoordinator.WatchedConfigSources.Count); Assert.IsTrue(watcherCoordinator.WatchedConfigSources.Contains(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Mocks.TestsConfigurationSection testConfigurationSection = (Mocks.TestsConfigurationSection)instance.GetSection("non.existing"); Assert.IsTrue(manageabilityHelper.updateCalled); Assert.AreEqual(1, watcherCoordinator.WatchedConfigSources.Count); Assert.IsTrue(watcherCoordinator.WatchedConfigSources.Contains(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); }
public void WatcherForNonManagedSectionIsSetOnFirstRequest() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); Assert.IsTrue(manageabilityHelper.updateCalled); Assert.AreEqual(1, watcherCoordinator.WatchedConfigSources.Count); Assert.IsTrue(watcherCoordinator.WatchedConfigSources.Contains(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Mocks.TestsConfigurationSection testConfigurationSection = (Mocks.TestsConfigurationSection)instance.GetSection(externalSection1); Assert.IsNotNull(testConfigurationSection); Assert.AreEqual("value1", testConfigurationSection.Value); Assert.AreEqual(2, watcherCoordinator.WatchedConfigSources.Count); Assert.IsTrue(watcherCoordinator.WatchedConfigSources.Contains(ConfigurationChangeWatcherCoordinator.MainConfigurationFileSource)); Assert.IsTrue(watcherCoordinator.WatchedConfigSources.Contains("test.external.config")); }
public override bool OverrideWithGroupPoliciesAndGenerateWmiObjects(ConfigurationSection configurationObject, bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey, bool generateWmiObjects, ICollection <ConfigurationSetting> wmiSettings) { called = true; this.configurationObject = configurationObject; this.readGroupPolicies = readGroupPolicies; this.machineKey = machineKey; this.userKey = userKey; this.generateWmiObjects = generateWmiObjects; IRegistryKey policyKey = GetPolicyKey(machineKey, userKey); if (policyKey != null) { if (!policyKey.GetBoolValue(PolicyValueName).Value) { return(false); } TestsConfigurationSection section = configurationObject as TestsConfigurationSection; if (section != null) { try { section.Value = policyKey.GetStringValue(ValuePropertyName); } catch (RegistryAccessException) { } } } if (generateWmiObjects) { TestConfigurationSettings setting = new TestConfigurationSettings(configurationObject.ToString()); setting.SourceElement = configurationObject; wmiSettings.Add(setting); } return(true); }
public void RegisteredForChangesOnLocalReceivesNotificationsOnMainConfigurationFileUpdateWithUpdatedValuesAvailable() { MockManageabilityHelper manageabilityHelper = new MockManageabilityHelper(); instance = new ManageableConfigurationSourceImplementation(testConfigurationFile, manageabilityHelper, groupPolicyWatcher, watcherCoordinator, notificationCoordinator); instance.GetSection(localSection1); instance.AddSectionChangeHandler(localSection1, OnConfigurationSectionChange); Mocks.TestsConfigurationSection rwTestConfigurationSection = (Mocks.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]); }