public void AddGetAndRemoveASection() { IConfigurationSource source = ConfigurationSourceFactory.Create("sqlSource"); Assert.AreEqual(typeof(SqlConfigurationSource), source.GetType()); DummySection dummySection1 = new DummySection(); dummySection1.Value = 10; source.Add(CreateParameter(), localSection, dummySection1); ConfigurationSection newSection = source.GetSection(localSection); Assert.AreEqual(typeof(DummySection), newSection.GetType()); DummySection dummySection2 = newSection as DummySection; Assert.AreEqual(dummySection1, dummySection2); source.Remove(CreateParameter(), localSection); newSection = source.GetSection(localSection); Assert.AreEqual(null, newSection); }
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); }
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); }
public void SaveTestConfiguration() { DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationManager.SaveSection("TestSection", configSection, data); //Assert that the database now has one record Assert.IsTrue(GetNumberofConfigSections() == 1); }
public void SaveAndGetTestConfiguration() { DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationManager.SaveSection("TestSection", configSection, data); DummySection configSection2 = SqlConfigurationManager.GetSection("TestSection", data) as DummySection; Assert.AreEqual(configSection2.Value, configSection.Value); }
public void SaveAndGetTestConfiguration() { DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationSystem configSystem = new SqlConfigurationSystem(data); configSystem.SaveSection("TestSection", configSection); DummySection configSection2 = configSystem.GetSection("TestSection") as DummySection; Assert.AreEqual(configSection2.Value, configSection.Value); }
public void GetsNotificationWhenUpdatingAndRemovingSections() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); IConfigurationSource source = ConfigurationSourceFactory.Create("sqlSource"); Assert.AreEqual(typeof(SqlConfigurationSource), source.GetType()); DummySection dummySection1 = new DummySection(); dummySection1.Value = 10; source.Add(CreateParameter(), localSection, dummySection1); bool sourceChanged = false; SqlConfigurationSource sqlSource = source as SqlConfigurationSource; sqlSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { sourceChanged = true; }); ConfigurationSection newSection = source.GetSection(localSection); Assert.AreEqual(typeof(DummySection), newSection.GetType()); DummySection dummySection2 = newSection as DummySection; Assert.AreEqual(dummySection1, dummySection2); //update the section dummySection2.Value = 15; sqlSource.Add(CreateParameter(), localSection, dummySection2); Thread.Sleep(500); Assert.IsTrue(sourceChanged); sourceChanged = false; //remove the section sqlSource.Remove(CreateParameter(), localSection); Thread.Sleep(500); Assert.IsTrue(sourceChanged); sourceChanged = false; newSection = sqlSource.GetSection(localSection); Assert.AreEqual(null, newSection); }
public void RefreshConfiguration() { string sectionName = "TestSection"; DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationSystem configSystem = new SqlConfigurationSystem(data); configSystem.SaveSection(sectionName, configSection); DateTime lastModDate1 = GetLastModDate(sectionName); System.Threading.Thread.Sleep(1000); configSystem.RefreshConfig(sectionName); DateTime lastModDate2 = GetLastModDate(sectionName); Assert.IsFalse(lastModDate2.Equals(lastModDate1)); }
public void AddAndGetASection() { IConfigurationSource source = ConfigurationSourceFactory.Create("sqlSource"); Assert.AreEqual(typeof(SqlConfigurationSource), source.GetType()); DummySection dummySection1 = new DummySection(); dummySection1.Value = 10; source.Add(CreateParameter(), localSection, dummySection1); ConfigurationSection newSection = source.GetSection(localSection); Assert.AreEqual(typeof(DummySection), newSection.GetType()); DummySection dummySection2 = newSection as DummySection; Assert.AreEqual(dummySection1, dummySection2); }
public void RefreshConfiguration() { string sectionName = "TestSection"; DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationManager.SaveSection("TestSection", configSection, data); DateTime lastModDate1 = GetLastModDate(sectionName); System.Threading.Thread.Sleep(1000); SqlConfigurationManager.RefreshSection(sectionName, data); DateTime lastModDate2 = GetLastModDate(sectionName); Assert.IsFalse(lastModDate2.Equals(lastModDate1)); }
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); }
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 DifferentSqlConfigurationSourcesDoNotShareEvents() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); SqlConfigurationSource.ResetImplementation(data1, true); SystemConfigurationSource.ResetImplementation(true); bool sysSourceChanged = false; bool otherSourceChanged = false; SystemConfigurationSource systemSource = new SystemConfigurationSource(); DummySection sysDummySerializableSection = systemSource.GetSection(localSection) as DummySection; SqlConfigurationSource otherSource = new SqlConfigurationSource( data1.ConnectionString, data1.GetStoredProcedure, data1.SetStoredProcedure, data1.RefreshStoredProcedure, data1.RemoveStoredProcedure); SqlConfigurationParameter parameter = new SqlConfigurationParameter( data1.ConnectionString, data1.GetStoredProcedure, data1.SetStoredProcedure, data1.RefreshStoredProcedure, data1.RemoveStoredProcedure); otherSource.Add(parameter,localSection, sysDummySerializableSection); DummySection otherDummySerializableSection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(sysDummySerializableSection != null); Assert.IsTrue(otherDummySerializableSection != null); systemSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { sysSourceChanged = true; }); otherSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.AreEqual(12, ((DummySection)otherSource.GetSection(localSection)).Value); otherSourceChanged = true; }); DummySection rwSection = new DummySection(); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenMachineConfiguration(); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = data1.ConnectionString; SqlConfigurationManager.SaveSection(rwSection.Name, rwSection, data1); Thread.Sleep(200); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); }
public void InvalidSectionNameReturnsNull() { DummySection configSection2 = SqlConfigurationManager.GetSection("BadSection", data) as DummySection; Assert.IsNull(configSection2); }
public void SaveAndGetTestConfiguration() { DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationManager.SaveSection("TestSection", configSection, data); DummySection configSection2 = SqlConfigurationManager.GetSection("TestSection", data) as DummySection; Assert.AreEqual(configSection2.Value, configSection.Value); }
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); }
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 SaveAndGetTestConfiguration() { DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationSystem configSystem = new SqlConfigurationSystem(data); configSystem.SaveSection("TestSection", configSection); DummySection configSection2 = configSystem.GetSection("TestSection") as DummySection; Assert.AreEqual(configSection2.Value, configSection.Value); }
public void SaveTestConfiguration() { DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationSystem configSystem = new SqlConfigurationSystem(data); configSystem.SaveSection("TestSection",configSection); //Assert that the database now has one record Assert.IsTrue(GetNumberofConfigSections() == 1); }
public void GetsNotificationWhenUpdatingAndRemovingSections() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); IConfigurationSource source = ConfigurationSourceFactory.Create("sqlSource"); Assert.AreEqual(typeof(SqlConfigurationSource), source.GetType()); DummySection dummySection1 = new DummySection(); dummySection1.Value = 10; source.Add(CreateParameter(), localSection, dummySection1); bool sourceChanged = false; SqlConfigurationSource sqlSource = source as SqlConfigurationSource; sqlSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { sourceChanged = true; }); ConfigurationSection newSection = source.GetSection(localSection); Assert.AreEqual(typeof(DummySection), newSection.GetType()); DummySection dummySection2 = newSection as DummySection; Assert.AreEqual(dummySection1, dummySection2); //update the section dummySection2.Value = 15; sqlSource.Add(CreateParameter(), localSection, dummySection2); Thread.Sleep(500); Assert.IsTrue(sourceChanged); sourceChanged = false; //remove the section sqlSource.Remove(CreateParameter(), localSection); Thread.Sleep(500); Assert.IsTrue(sourceChanged); sourceChanged = false; newSection = sqlSource.GetSection(localSection); Assert.AreEqual(null, newSection); }
public void DifferentSqlConfigurationSourcesDoNotShareEvents() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); SqlConfigurationSource.ResetImplementation(data1, true); SystemConfigurationSource.ResetImplementation(true); bool sysSourceChanged = false; bool otherSourceChanged = false; SystemConfigurationSource systemSource = new SystemConfigurationSource(); DummySection sysDummySerializableSection = systemSource.GetSection(localSection) as DummySection; SqlConfigurationSource otherSource = new SqlConfigurationSource( data1.ConnectionString, data1.GetStoredProcedure, data1.SetStoredProcedure, data1.RefreshStoredProcedure, data1.RemoveStoredProcedure); SqlConfigurationParameter parameter = new SqlConfigurationParameter( data1.ConnectionString, data1.GetStoredProcedure, data1.SetStoredProcedure, data1.RefreshStoredProcedure, data1.RemoveStoredProcedure); otherSource.Add(parameter, localSection, sysDummySerializableSection); DummySection otherDummySerializableSection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(sysDummySerializableSection != null); Assert.IsTrue(otherDummySerializableSection != null); systemSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { sysSourceChanged = true; }); otherSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.AreEqual(12, ((DummySection)otherSource.GetSection(localSection)).Value); otherSourceChanged = true; }); DummySection rwSection = new DummySection(); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenMachineConfiguration(); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = data1.ConnectionString; SqlConfigurationManager.SaveSection(rwSection.Name, rwSection, data1); Thread.Sleep(200); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); }