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); }
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); }