public void Setup() { SystemConfigurationSource.ResetImplementation(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; rwSection.SectionInformation.ConfigSource = localSectionSource; rwConfiguration.Sections.Remove(externalSection); rwConfiguration.Sections.Add(externalSection, rwSection = new DummySection()); rwSection.Name = externalSection; rwSection.Value = 20; rwSection.SectionInformation.ConfigSource = externalSectionSource; rwConfiguration.Sections.Remove(localSection2); rwConfiguration.Sections.Add(localSection2, rwSection = new DummySection()); rwSection.Name = localSection2; rwSection.Value = 30; rwSection.SectionInformation.ConfigSource = localSectionSource; rwConfiguration.Save(); ConfigurationManager.RefreshSection(localSection); ConfigurationManager.RefreshSection(localSection2); ConfigurationManager.RefreshSection(externalSection); ConfigurationChangeFileWatcher.ResetDefaultPollDelay(); updatedSectionsTally = new Dictionary <string, int>(0); }
public void RemovingAndAddingSection() { SystemConfigurationSource.ResetImplementation(true); SystemConfigurationSource sysSource = new SystemConfigurationSource(); DummySection dummySection = sysSource.GetSection(localSection) as DummySection; Assert.IsTrue(dummySection != null); Thread.Sleep(300); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string fileName = rwConfiguration.FilePath; int numSections = rwConfiguration.Sections.Count; FileConfigurationParameter parameter = new FileConfigurationParameter(fileName); sysSource.Remove(parameter, localSection); Thread.Sleep(300); rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); Assert.AreEqual(rwConfiguration.Sections.Count, numSections - 1); sysSource.Add(parameter, localSection, new DummySection()); Thread.Sleep(300); rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); Assert.AreEqual(rwConfiguration.Sections.Count, numSections); }
public void DifferentFileConfigurationSourcesDoNotShareEvents() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); FileConfigurationSource.ResetImplementation(otherConfigurationFile, true); SystemConfigurationSource.ResetImplementation(true); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { bool sysSourceChanged = false; bool otherSourceChanged = false; SystemConfigurationSource systemSource = new SystemConfigurationSource(); FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile); DummySection sysDummySection = systemSource.GetSection(localSection) as DummySection; DummySection otherDummySection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(sysDummySection != null); Assert.IsTrue(otherDummySection != 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.OpenExeConfiguration(otherConfigurationFile); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = localSectionSource; rwConfiguration.SaveAs(otherConfigurationFile); Thread.Sleep(200); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void SystemConfigurationSourceReturnsReadOnlySections() { SystemConfigurationSource.ResetImplementation(false); SystemConfigurationSource source = new SystemConfigurationSource(); ConfigurationSection dummySection = source.GetSection(localSection); Assert.IsTrue(dummySection.IsReadOnly()); }
public void CanReceiveNotificationsFromImplementation() { SystemConfigurationSource.ResetImplementation(false); SystemConfigurationSource source = new SystemConfigurationSource(); source.GetSection(localSection); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); SystemConfigurationSource.Implementation.ConfigSourceChanged(localSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); }
public void Setup() { SystemConfigurationSource.ResetImplementation(false); ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); 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; rwSection.SectionInformation.ConfigSource = localSectionSource; updatedSectionsTally = new Dictionary <string, int>(0); }
private void SetTracingFlag(bool tracingEnabled) { ConfigurationChangeFileWatcher.SetDefaultPollDelayInMilliseconds(100); SystemConfigurationSource.ResetImplementation(true); Logger.Reset(); SysConfig.Configuration config = SysConfig.ConfigurationManager.OpenExeConfiguration(SysConfig.ConfigurationUserLevel.None); Logging.Configuration.LoggingSettings loggingSettings = config.GetSection(Logging.Configuration.LoggingSettings.SectionName) as Logging.Configuration.LoggingSettings; loggingSettings.TracingEnabled = tracingEnabled; config.Save(); SysConfig.ConfigurationManager.RefreshSection(Logging.Configuration.LoggingSettings.SectionName); SystemConfigurationSource.Implementation.ConfigSourceChanged(string.Empty); Thread.Sleep(200); }
public void ConfigurationChangeNotificationRefreshesLogger() { SystemConfigurationSource.ResetImplementation(false); Logger.Reset(); MockTraceListener.Reset(); Logger.Write("test", "MockCategoryOne"); Assert.AreEqual(1, MockTraceListener.Entries.Count); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); LoggingSettings rwSettings = rwConfiguration.GetSection(LoggingSettings.SectionName) as LoggingSettings; ((CategoryFilterData)rwSettings.LogFilters.Get("Category")).CategoryFilters.Add(new CategoryFilterEntry("MockCategoryOne")); rwConfiguration.Save(); SystemConfigurationSource.Implementation.ConfigSourceChanged(string.Empty); MockTraceListener.Reset(); Logger.Write("test", "MockCategoryOne"); Assert.AreEqual(0, MockTraceListener.Entries.Count, "should have been filtered out by the new category filter"); }
public void ConfigurationChangeNotificationRefreshesLoggerAutomatically() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(100); SystemConfigurationSource.ResetImplementation(true); Logger.Reset(); MockTraceListener.Reset(); Logger.Write("test", "MockCategoryOne"); Assert.AreEqual(1, MockTraceListener.Entries.Count); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); LoggingSettings rwSettings = rwConfiguration.GetSection(LoggingSettings.SectionName) as LoggingSettings; ((CategoryFilterData)rwSettings.LogFilters.Get("Category")).CategoryFilters.Add(new CategoryFilterEntry("MockCategoryOne")); rwConfiguration.Save(); Thread.Sleep(400); MockTraceListener.Reset(); Logger.Write("test", "MockCategoryOne"); Assert.AreEqual(0, MockTraceListener.Entries.Count); }
public void UsingTracerDoesNotWriteWhenDisabled() { SystemConfigurationSource.ResetImplementation(false); //turn tracing off SetTracingFlag(false); MockTraceListener.Reset(); Guid currentActivityId = Guid.Empty; using (new Tracer(operation)) { currentActivityId = Trace.CorrelationManager.ActivityId; Assert.AreEqual(0, MockTraceListener.Entries.Count); } Assert.AreEqual(0, MockTraceListener.Entries.Count); //turn tracing back on SetTracingFlag(true); }
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); }