public void RestoredSectionGetsNotificationOnRestoreAndGetsFurtherNotifications()
        {
            SystemConfigurationSourceImplementation implementation = new SystemConfigurationSourceImplementation(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));

            // a change in system config notifies both sections
            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            rwConfiguration.Save();

            implementation.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();

            implementation.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();

            implementation.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();

            implementation.ConfigSourceChanged(localSectionSource);
            Assert.AreEqual(4, updatedSectionsTally[localSection]);
            Assert.AreEqual(3, updatedSectionsTally[localSection2]);

            // further updates notify both sections
            rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            rwConfiguration.Save();

            implementation.ConfigSourceChanged(localSectionSource);
            Assert.AreEqual(5, updatedSectionsTally[localSection]);
            Assert.AreEqual(4, updatedSectionsTally[localSection2]);
        }
Пример #2
0
        public void WatchedExistingSectionInExternalFileIsNoLongerWatchedIfRemovedFromConfigurationAndExternalFileWatcherIsRemoved()
        {
            SystemConfigurationSourceImplementation implementation = new SystemConfigurationSourceImplementation(false);
            DummySection dummySection1 = implementation.GetSection(localSection) as DummySection;
            DummySection dummySection2 = implementation.GetSection(externalSection) as DummySection;

            Assert.IsNotNull(dummySection1);
            Assert.IsNotNull(dummySection2);
            Assert.AreEqual(2, implementation.WatchedConfigSources.Count);
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(localSectionSource));
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(externalSectionSource));
            Assert.AreEqual(2, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));
            Assert.IsTrue(implementation.WatchedSections.Contains(externalSection));

            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            rwConfiguration.Sections.Remove(externalSection);
            rwConfiguration.Save();

            implementation.ConfigSourceChanged(localSectionSource);

            Assert.AreEqual(2, implementation.WatchedConfigSources.Count);
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(localSectionSource));
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(SystemConfigurationSourceImplementation.NullConfigSource));
            Assert.AreEqual(2, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));
            Assert.IsTrue(implementation.WatchedSections.Contains(externalSection));
            Assert.AreEqual(1, implementation.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Count);
            Assert.IsTrue(implementation.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Contains(localSection));
            Assert.AreEqual(1, implementation.ConfigSourceWatcherMappings[SystemConfigurationSourceImplementation.NullConfigSource].WatchedSections.Count);
            Assert.IsTrue(implementation.ConfigSourceWatcherMappings[SystemConfigurationSourceImplementation.NullConfigSource].WatchedSections.Contains(externalSection));
        }
Пример #3
0
        public void WatchedSectionInAppConfigValuesAreUpdatedIfAppConfigChangesAndNotificationIsFired()
        {
            SystemConfigurationSourceImplementation implementation = new SystemConfigurationSourceImplementation(false);

            object section1 = implementation.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();

            implementation.ConfigSourceChanged(localSectionSource);

            section1 = implementation.GetSection(localSection);
            Assert.IsNotNull(section1);
            dummySection1 = section1 as DummySection;
            Assert.AreEqual(localSection, dummySection1.Name);
            Assert.AreEqual(15, dummySection1.Value);
        }
Пример #4
0
        public void RegisteredObjectForNonRequestedSectionIsNotNotified()
        {
            SystemConfigurationSourceImplementation implementation = new SystemConfigurationSourceImplementation(false);

            implementation.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged));

            implementation.ConfigSourceChanged(localSectionSource);

            Assert.IsFalse(updatedSectionsTally.ContainsKey(localSection));
        }
Пример #5
0
        public void RemovedSectionGetsNotificationOnRemovalAndDoesNotGetFurtherNotifications()
        {
            ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(100);

            SystemConfigurationSourceImplementation implementation = new SystemConfigurationSourceImplementation(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));

            // a change in system config notifies both sections
            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            rwConfiguration.Save(ConfigurationSaveMode.Minimal, true);

            implementation.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(ConfigurationSaveMode.Minimal, true);

            implementation.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(ConfigurationSaveMode.Minimal, true);

            implementation.ConfigSourceChanged(localSectionSource);
            Assert.AreEqual(3, updatedSectionsTally[localSection]);
            Assert.AreEqual(2, updatedSectionsTally[localSection2]);
        }
Пример #6
0
        public void RegisteredObjectForExternalFileIsNotifiedOfSectionChangesForAppConfigIfConfigSourceForExternalSectionNotChanged()
        {
            SystemConfigurationSourceImplementation implementation = new SystemConfigurationSourceImplementation(false);

            implementation.GetSection(externalSection);
            implementation.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged));

            implementation.ConfigSourceChanged(localSectionSource);

            Assert.IsFalse(updatedSectionsTally.ContainsKey(externalSection));
        }
Пример #7
0
        public void RegisteredObjectIsNotifiedOfSectionChangesForAppConfig()
        {
            SystemConfigurationSourceImplementation implementation = new SystemConfigurationSourceImplementation(false);

            implementation.GetSection(localSection);
            implementation.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged));

            implementation.ConfigSourceChanged(localSectionSource);

            Assert.AreEqual(1, updatedSectionsTally[localSection]);
        }