コード例 #1
0
        public void GetsNullIfSectionDoesNotExist()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);
            object section = implementation.GetSection(nonExistingSection);

            Assert.IsNull(section);
        }
コード例 #2
0
        public void WatchedExistingSectionIsNoLongerWatchedIfRemovedFromConfiguration()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);
            DummySection dummySection1 = implementation.GetSection(localSection) as DummySection;
            DummySection dummySection2 = implementation.GetSection(localSection2) as DummySection;

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

            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            implementation.RemoveSection(localSection2);

            implementation.ConfigSourceChanged(externalSectionSource);

            Assert.AreEqual(2, implementation.WatchedConfigSources.Count);
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(externalSectionSource));
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(SqlConfigurationSourceImplementation.NullConfigSource));
            Assert.AreEqual(1, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));
            Assert.AreEqual(1, implementation.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Count);
            Assert.IsTrue(implementation.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Contains(localSection));
            Assert.AreEqual(1, implementation.ConfigSourceWatcherMappings[SqlConfigurationSourceImplementation.NullConfigSource].WatchedSections.Count);
        }
コード例 #3
0
        public void WatchedSectionIsUpdatedIfNotificationIsFired()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, 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;
            implementation.SaveSection(localSection, rwSection);

            implementation.ConfigSourceChanged(externalSectionSource);

            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 CanGetExistingSection()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);
            object section = implementation.GetSection(localSection);

            Assert.IsNotNull(section);
        }
コード例 #5
0
        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]);
        }
コード例 #6
0
        public void NewInstanceHasNoWatchers()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);

            Assert.AreEqual(0, implementation.WatchedConfigSources.Count);
            Assert.AreEqual(0, implementation.WatchedSections.Count);
        }
コード例 #7
0
        public void DifferentConfigationInfoDoesNotShareImplementation()
        {
            SqlConfigurationSourceImplementation configSourceImpl1 = SqlConfigurationSource.GetImplementation(data1);
            SqlConfigurationSourceImplementation configSourceImpl2 = SqlConfigurationSource.GetImplementation(data2);

            Assert.IsFalse(object.ReferenceEquals(configSourceImpl1, configSourceImpl2));
        }
コード例 #8
0
        public void GetsNullForSectionWithEmptyValue()
        {
            UpdateSection(localSection, typeof(DummySection).FullName, null);
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);
            object section = implementation.GetSection(localSection);

            Assert.IsNull(section);
        }
コード例 #9
0
        public void RequestForNonexistentSectionCreatesNoWatcher()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);

            object section = implementation.GetSection(nonExistingSection);

            Assert.IsNull(section);
            Assert.AreEqual(0, implementation.WatchedConfigSources.Count);
            Assert.AreEqual(0, implementation.WatchedSections.Count);
        }
コード例 #10
0
        public void RegisteredObjectForNonRequestedSectionIsNotNotified()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);

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

            implementation.ConfigSourceChanged(externalSectionSource);

            Assert.IsFalse(updatedSectionsTally.ContainsKey(localSection));
        }
コード例 #11
0
        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]);
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        public void SecondRequestForDifferentSectionDoesNotCreateSecondConfigSourceWatcher()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);

            object section1 = implementation.GetSection(localSection);
            object section2 = implementation.GetSection(localSection2);

            Assert.IsNotNull(section1);
            Assert.IsNotNull(section2);
            Assert.AreEqual(1, implementation.WatchedConfigSources.Count);
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(externalSectionSource));
        }
コード例 #14
0
        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]);
        }
コード例 #15
0
        public void RequestsForTwoSectionsCreatesSectionWatchersForBoth()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);

            object section1 = implementation.GetSection(localSection);
            object section2 = implementation.GetSection(externalSection);

            Assert.IsNotNull(section1);
            Assert.IsNotNull(section2);
            Assert.AreEqual(2, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));
            Assert.IsTrue(implementation.WatchedSections.Contains(externalSection));
        }
コード例 #16
0
        public void SharedConfigurationFilesCanHaveDifferentCasing()
        {
            SqlConfigurationSourceImplementation configSourceImpl1 = SqlConfigurationSource.GetImplementation(data1);

            SqlConfigurationData tempData = new SqlConfigurationData(
                data1.ConnectionString.ToUpper(),
                data1.GetStoredProcedure.ToUpper(),
                data1.SetStoredProcedure.ToUpper(),
                data1.RefreshStoredProcedure.ToUpper(),
                data1.RemoveStoredProcedure.ToUpper());
            SqlConfigurationSourceImplementation configSourceImpl2 = SqlConfigurationSource.GetImplementation(tempData);

            Assert.AreSame(configSourceImpl1, configSourceImpl2);
        }
コード例 #17
0
        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]);
        }
コード例 #18
0
        public void FirstRequestForSectionCreatesWatcher()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, true);

            object section = implementation.GetSection(localSection);

            Assert.IsNotNull(section);
            Assert.AreEqual(1, implementation.WatchedConfigSources.Count);
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(externalSectionSource));
            Assert.AreEqual(1, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));

            Assert.IsNotNull(implementation.ConfigSourceWatcherMappings[externalSectionSource].Watcher);
            Assert.AreEqual(implementation.ConfigSourceWatcherMappings[externalSectionSource].Watcher.GetType(), typeof(ConfigurationChangeSqlWatcher));

            implementation.Dispose();
        }
コード例 #19
0
        public void Setup()
        {
            string connectString     = @"server=(local)\SQLExpress;database=Northwind;Integrated Security=true";
            string getStoredProc     = @"EntLib_GetConfig";
            string setStoredProc     = @"EntLib_SetConfig";
            string refreshStoredProc = @"UpdateSectionDate";
            string removeStoredProc  = @"EntLib_RemoveSection";

            this.data = new SqlConfigurationData(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc);

            SqlConfigurationSource.ResetImplementation(data, false);

            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            DummySection rwSection;

            rwConfiguration.Sections.Remove(localSection);
            rwConfiguration.Sections.Add(localSection, rwSection = new DummySection());
            rwSection.Name  = localSection;
            rwSection.Value = 10;
            SqlConfigurationSourceImplementation configSourceImpl = new SqlConfigurationSourceImplementation(this.data, false);

            configSourceImpl.SaveSection(rwSection.Name, rwSection);

            rwConfiguration.Sections.Remove(externalSection);
            rwConfiguration.Sections.Add(externalSection, rwSection = new DummySection());
            rwSection.Name  = externalSection;
            rwSection.Value = 20;
            configSourceImpl.SaveSection(rwSection.Name, rwSection);

            rwConfiguration.Sections.Remove(localSection2);
            rwConfiguration.Sections.Add(localSection2, rwSection = new DummySection());
            rwSection.Name  = localSection2;
            rwSection.Value = 30;
            configSourceImpl.SaveSection(rwSection.Name, rwSection);

            rwConfiguration.Save();

            SqlConfigurationManager.RefreshSection(localSection, this.data);
            SqlConfigurationManager.RefreshSection(localSection2, this.data);
            SqlConfigurationManager.RefreshSection(externalSection, this.data);

            ConfigurationChangeSqlWatcher.ResetDefaultPollDelay();

            updatedSectionsTally = new Dictionary <string, int>(0);
        }
コード例 #20
0
        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]);
        }
コード例 #21
0
        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]);
        }
コード例 #22
0
        public void CanGetExistingSection()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);
            object section = implementation.GetSection(localSection);

            Assert.IsNotNull(section);
        }
コード例 #23
0
        public void FirstRequestForSectionCreatesWatcher()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, true);

            object section = implementation.GetSection(localSection);

            Assert.IsNotNull(section);
            Assert.AreEqual(1, implementation.WatchedConfigSources.Count);
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(externalSectionSource));
            Assert.AreEqual(1, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));

            Assert.IsNotNull(implementation.ConfigSourceWatcherMappings[externalSectionSource].Watcher);
            Assert.AreEqual(implementation.ConfigSourceWatcherMappings[externalSectionSource].Watcher.GetType(), typeof(ConfigurationChangeSqlWatcher));

            implementation.Dispose();
        }
コード例 #24
0
        public void GetsNullForSectionWithEmptyValue()
        {
            UpdateSection(localSection, typeof(DummySection).FullName, null);
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);
            object section = implementation.GetSection(localSection);

            Assert.IsNull(section);
        }
コード例 #25
0
        public void GetsNullIfSectionDoesNotExist()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);
            object section = implementation.GetSection(nonExistingSection);

            Assert.IsNull(section);
        }
コード例 #26
0
        public void NewInstanceHasNoWatchers()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);

            Assert.AreEqual(0, implementation.WatchedConfigSources.Count);
            Assert.AreEqual(0, implementation.WatchedSections.Count);
        }
コード例 #27
0
        public void WatchedExistingSectionIsNoLongerWatchedIfRemovedFromConfiguration()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data,  false);
            DummySection dummySection1 = implementation.GetSection(localSection) as DummySection;
            DummySection dummySection2 = implementation.GetSection(localSection2) as DummySection;
            Assert.IsNotNull(dummySection1);
            Assert.IsNotNull(dummySection2);
            Assert.AreEqual(1, implementation.WatchedConfigSources.Count);
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(externalSectionSource));
            Assert.AreEqual(2, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection2));

            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            implementation.RemoveSection(localSection2);

            implementation.ConfigSourceChanged(externalSectionSource);

            Assert.AreEqual(2, implementation.WatchedConfigSources.Count);
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(externalSectionSource));
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(SqlConfigurationSourceImplementation.NullConfigSource));
            Assert.AreEqual(1, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));
            Assert.AreEqual(1, implementation.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Count);
            Assert.IsTrue(implementation.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Contains(localSection));
            Assert.AreEqual(1, implementation.ConfigSourceWatcherMappings[SqlConfigurationSourceImplementation.NullConfigSource].WatchedSections.Count);
        }
コード例 #28
0
        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));
        }
コード例 #29
0
        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]);
        }
コード例 #30
0
        public void RequestForNonexistentSectionCreatesNoWatcher()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);

            object section = implementation.GetSection(nonExistingSection);

            Assert.IsNull(section);
            Assert.AreEqual(0, implementation.WatchedConfigSources.Count);
            Assert.AreEqual(0, implementation.WatchedSections.Count);
        }
コード例 #31
0
        public void RequestsForTwoSectionsCreatesSectionWatchersForBoth()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data,  false);

            object section1 = implementation.GetSection(localSection);
            object section2 = implementation.GetSection(externalSection);

            Assert.IsNotNull(section1);
            Assert.IsNotNull(section2);
            Assert.AreEqual(2, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));
            Assert.IsTrue(implementation.WatchedSections.Contains(externalSection));
        }
コード例 #32
0
        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]);
        }
コード例 #33
0
        public void SecondRequestForSameSectionDoesNotCreateSecondWatcher()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data, false);

            object section1 = implementation.GetSection(localSection);
            object section2 = implementation.GetSection(localSection);

            Assert.IsNotNull(section1);
            Assert.IsNotNull(section2);
            Assert.AreEqual(1, implementation.WatchedConfigSources.Count);
            Assert.IsTrue(implementation.WatchedConfigSources.Contains(externalSectionSource));
            Assert.AreEqual(1, implementation.WatchedSections.Count);
            Assert.IsTrue(implementation.WatchedSections.Contains(localSection));
        }
コード例 #34
0
        public void Setup()
        {
            string connectString = @"server=(local)\SQLExpress;database=Northwind;Integrated Security=true";
            string getStoredProc = @"EntLib_GetConfig";
            string setStoredProc = @"EntLib_SetConfig";
            string refreshStoredProc = @"UpdateSectionDate";
            string removeStoredProc = @"EntLib_RemoveSection";

            this.data = new SqlConfigurationData(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc);

            SqlConfigurationSource.ResetImplementation(data, false);

            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            DummySection rwSection;

            rwConfiguration.Sections.Remove(localSection);
            rwConfiguration.Sections.Add(localSection, rwSection = new DummySection());
            rwSection.Name = localSection;
            rwSection.Value = 10;
            SqlConfigurationSourceImplementation configSourceImpl = new SqlConfigurationSourceImplementation(this.data,  false);
            configSourceImpl.SaveSection(rwSection.Name,rwSection);

            rwConfiguration.Sections.Remove(externalSection);
            rwConfiguration.Sections.Add(externalSection, rwSection = new DummySection());
            rwSection.Name = externalSection;
            rwSection.Value = 20;
            configSourceImpl.SaveSection(rwSection.Name, rwSection);

            rwConfiguration.Sections.Remove(localSection2);
            rwConfiguration.Sections.Add(localSection2, rwSection = new DummySection());
            rwSection.Name = localSection2;
            rwSection.Value = 30;
            configSourceImpl.SaveSection(rwSection.Name, rwSection);

            rwConfiguration.Save();

            SqlConfigurationManager.RefreshSection(localSection, this.data);
            SqlConfigurationManager.RefreshSection(localSection2, this.data);
            SqlConfigurationManager.RefreshSection(externalSection, this.data);

            ConfigurationChangeSqlWatcher.ResetDefaultPollDelay();

            updatedSectionsTally = new Dictionary<string, int>(0);
        }
コード例 #35
0
        public void RegisteredObjectForNonRequestedSectionIsNotNotified()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data,  false);
            implementation.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged));

            implementation.ConfigSourceChanged(externalSectionSource);

            Assert.IsFalse(updatedSectionsTally.ContainsKey(localSection));
        }
コード例 #36
0
        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]);
        }
コード例 #37
0
        public void WatchedSectionIsUpdatedIfNotificationIsFired()
        {
            SqlConfigurationSourceImplementation implementation = new SqlConfigurationSourceImplementation(this.data,  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;
            implementation.SaveSection(localSection, rwSection);

            implementation.ConfigSourceChanged(externalSectionSource);

            section1 = implementation.GetSection(localSection);
            Assert.IsNotNull(section1);
            dummySection1 = section1 as DummySection;
            Assert.AreEqual(localSection, dummySection1.Name);
            Assert.AreEqual(15, dummySection1.Value);
        }