public void CanGetExistingSectionInAppConfig() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section = source.GetSection(localSection); Assert.IsNotNull(section); }
public void SystemConfigurationSourceReturnsReadOnlySections() { SystemConfigurationSource source = new SystemConfigurationSource(false); ConfigurationSection dummySection = source.GetSection(localSection); Assert.IsTrue(dummySection.IsReadOnly()); }
public static void CheckSource() { var source = new SystemConfigurationSource(false); object section = source.GetSection(localSection); if (section == null) { throw new Exception("could not get section"); } }
public void RemovingSectionIsReflectedInMemoryAndOnDisk_Bug2931() { SystemConfigurationSource sysSource = new SystemConfigurationSource(false); var originalSection = (DummySection)(sysSource.GetSection(removeSectionName)); Assert.IsNotNull(originalSection); sysSource.Remove(removeSectionName); var returnedSection = (DummySection)(sysSource.GetSection(removeSectionName)); Assert.IsNull(returnedSection); }
public void FirstRequestForSectionInExternalFileCreatesWatchersForExternalFileAndAppConfig() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section = source.GetSection(externalSection); Assert.IsNotNull(section); Assert.AreEqual(2, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.IsTrue(source.WatchedConfigSources.Contains(externalSectionSource)); Assert.AreEqual(2, source.WatchedSections.Count); //watches ConfigurationSourceSection + externalSection Assert.IsTrue(source.WatchedSections.Contains(externalSection)); }
public void CanBuildCustomAuthorizationProviderFromSystemConfiguration() { using (var configurationSource = new SystemConfigurationSource(false)) { IAuthorizationProvider custom = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource) .GetInstance <IAuthorizationProvider>("custom"); Assert.IsNotNull(custom); Assert.AreSame(typeof(MockCustomAuthorizationProvider), custom.GetType()); Assert.AreEqual("value1", ((MockCustomAuthorizationProvider)custom).customValue); } }
public void AllRegisteredObjectsAreNotifiedOfSectionChangesForExternalFile() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(externalSection); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[externalSection]); }
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); }
public static void Main(string[] args) { var configSource = new SystemConfigurationSource(); var bootstrapperConfig = new UnityBootstrapperConfiguration(configSource); var bootstrapper = new UnityBootstrapper(bootstrapperConfig); bootstrapper.Startup(); EventfulRestClient(); Console.ReadLine(); Console.WriteLine("Press a key to exit.."); Console.ReadLine(); }
public void SecondRequestForSameSectionInAppConfigDoesNotCreateSecondWatcherForAppConfig() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section1 = source.GetSection(localSection); object section2 = source.GetSection(localSection); Assert.IsNotNull(section1); Assert.IsNotNull(section2); Assert.AreEqual(1, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.AreEqual(2, source.WatchedSections.Count); //watches ConfigurationSourceSection + localSection Assert.IsTrue(source.WatchedSections.Contains(localSection)); }
public void AllRegisteredObjectsAreNotifiedOfDifferentSectionsChangesForAppConfig() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(localSection); source.GetSection(localSection2); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(localSection2, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); Assert.AreEqual(1, updatedSectionsTally[localSection2]); }
public void BootstrapperStartupTest() { var configSource = new SystemConfigurationSource(); var bootstrapperConfig = new UnityBootstrapperConfiguration(configSource); var bootstrapper = new UnityBootstrapper(bootstrapperConfig); bootstrapper.AddBootstrapperTasks(new BootstrapperTask()); bootstrapper.Startup(); var expected = typeof(TraceLoggerFactory); var actual = ServiceLocator.Current.GetInstance <ILoggerFactory>().GetType(); Assert.AreEqual(expected, actual); }
public void SameImplementationSurvivesAcrossInstances() { SystemConfigurationSource source1 = new SystemConfigurationSource(); object section = source1.GetSection(localSection); Assert.IsNotNull(section); Assert.AreEqual(1, SystemConfigurationSource.Implementation.WatchedSections.Count); Assert.IsTrue(SystemConfigurationSource.Implementation.WatchedSections.Contains(localSection)); source1 = null; GC.Collect(3); Assert.AreEqual(1, SystemConfigurationSource.Implementation.WatchedSections.Count); Assert.IsTrue(SystemConfigurationSource.Implementation.WatchedSections.Contains("dummy.local")); }
public void RequestsForAppConfigAndExternalFileCreatesWatchersForBoth() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section1 = source.GetSection(localSection); object section2 = source.GetSection(externalSection); Assert.IsNotNull(section1); Assert.IsNotNull(section2); Assert.AreEqual(2, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.IsTrue(source.WatchedConfigSources.Contains(externalSectionSource)); Assert.AreEqual(3, source.WatchedSections.Count); //watches ConfigurationSourceSection + externalSection + localSection Assert.IsTrue(source.WatchedSections.Contains(localSection)); Assert.IsTrue(source.WatchedSections.Contains(externalSection)); }
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 CanStopReceivingNotificationsFromImplementation() { 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]); source.RemoveSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); SystemConfigurationSource.Implementation.ConfigSourceChanged(localSectionSource); Assert.AreEqual(1, updatedSectionsTally[localSection]); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); SystemConfigurationSource.Implementation.ConfigSourceChanged(localSectionSource); Assert.AreEqual(2, updatedSectionsTally[localSection]); }
public void Save() { UserSettings data = this.UserSettings.Clone(); if (this.Source is FileConfigurationSource) { FileConfigurationSource fs = this.Source as FileConfigurationSource; fs.Save(UserSettings.SectionName, data); } if (this.Source is SystemConfigurationSource) { SystemConfigurationSource fs = this.Source as SystemConfigurationSource; fs.Save(UserSettings.SectionName, data); } }
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 FirstRequestForSectionInAppConfigCreatesWatcherForAppConfig() { IConfigurationSourceTest source = new SystemConfigurationSource(true); object section = source.GetSection(localSection); Assert.IsNotNull(section); Assert.AreEqual(1, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.AreEqual(2, source.WatchedSections.Count); //watches ConfigurationSourceSection + localSection Assert.IsTrue(source.WatchedSections.Contains(localSection)); Assert.IsNotNull(source.ConfigSourceWatcherMappings[localSectionSource].Watcher); Assert.AreEqual(source.ConfigSourceWatcherMappings[localSectionSource].Watcher.GetType(), typeof(ConfigurationChangeFileWatcher)); ((IDisposable)source).Dispose(); }
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); }
private static void Main(string[] args) { var configSource = new SystemConfigurationSource(); var bootstrapperConfig = new UnityBootstrapperConfiguration(configSource); var bootstrapper = new UnityBootstrapper(bootstrapperConfig); bootstrapper.Startup(); WriteContainerInfo(); //LoggerSample(); //SettingSample(); CachedSettingBehaviorSample(); //FindTypes(); WriteContainerInfo(); Console.ReadLine(); }
public void EmptyCategoriesRevertToDefaultCategory() { MockTraceListener.Reset(); using (var configurationSource = new SystemConfigurationSource(false)) { LoggingSettings settings = LoggingSettings.GetLoggingSettings(configurationSource); LogEntry log = new LogEntry(); log.EventId = 1; log.Message = "test"; log.Categories = new string[0]; log.Severity = TraceEventType.Error; Logger.Write(log); Assert.IsNotNull(MockTraceListener.LastEntry); Assert.AreEqual("test", MockTraceListener.LastEntry.Message); Assert.AreEqual(1, MockTraceListener.LastEntry.Categories.Count); Assert.IsTrue(MockTraceListener.LastEntry.Categories.Contains(settings.DefaultCategory)); } }
public void CanAddAndRemoveHandlers() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section = source.GetSection(externalSection); Assert.IsNotNull(section); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(2, updatedSectionsTally[externalSection]); source.RemoveSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[externalSection]); source.RemoveSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ExternalConfigSourceChanged(externalSectionSource); Assert.AreEqual(3, updatedSectionsTally[externalSection]); }
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 RemovedSectionGetsNotificationOnRemovalAndDoesNotGetFurtherNotifications() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section1 = source.GetSection(localSection); Assert.IsNotNull(section1); object section2 = source.GetSection(localSection2); Assert.IsNotNull(section2); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(localSection2, new ConfigurationChangedEventHandler(OnConfigurationChanged)); // a change in system config notifies both sections System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Save(); source.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(); source.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(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(3, updatedSectionsTally[localSection]); Assert.AreEqual(2, updatedSectionsTally[localSection2]); }
public void RemovingAndAddingSection() { SystemConfigurationSource sysSource = new SystemConfigurationSource(false); DummySection dummySection = sysSource.GetSection(localSection) as DummySection; Assert.IsTrue(dummySection != null); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string fileName = rwConfiguration.FilePath; int numSections = rwConfiguration.Sections.Count; sysSource.Remove(localSection); rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); Assert.AreEqual(rwConfiguration.Sections.Count, numSections - 1); sysSource.Add(localSection, new DummySection()); // can't be the same instance rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); Assert.AreEqual(rwConfiguration.Sections.Count, numSections); }
public void NewInstanceHasNoWatchers() { IConfigurationSourceTest source = new SystemConfigurationSource(false); Assert.AreEqual(0, source.WatchedConfigSources.Count); Assert.AreEqual(0, source.WatchedSections.Count); }
public void SecondRequestForSameSectionInExternalFileDoesNotCreateWatcherForExternalFile() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section1 = source.GetSection(externalSection); object section2 = source.GetSection(externalSection); Assert.IsNotNull(section1); Assert.IsNotNull(section2); Assert.AreEqual(2, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.IsTrue(source.WatchedConfigSources.Contains(externalSectionSource)); Assert.AreEqual(2, source.WatchedSections.Count); //watches ConfigurationSourceSection + externalSection Assert.IsTrue(source.WatchedSections.Contains(externalSection)); }
public void Initialize() { this.configurationSource = new SystemConfigurationSource(); }
public void RequestForNonexistentSectionCreatesNoWatcher() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section = source.GetSection(nonExistingSection); Assert.IsNull(section); Assert.AreEqual(1, source.WatchedConfigSources.Count); //watches only ConfigurationSourceSection. Assert.AreEqual(1, source.WatchedSections.Count); }
public void SecondRequestForDifferentSectionInAppConfigDoesNotCreateSecondWatcherForAppConfig() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section1 = source.GetSection(localSection); object section2 = source.GetSection(localSection2); Assert.IsNotNull(section1); Assert.IsNotNull(section2); Assert.AreEqual(1, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.AreEqual(3, source.WatchedSections.Count); //watches ConfigurationSourceSection. + localSection + localSection2 Assert.IsTrue(source.WatchedSections.Contains(localSection)); Assert.IsTrue(source.WatchedSections.Contains(localSection2)); }
public void DifferentFileConfigurationSourcesDoNotShareEvents() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { bool sysSourceChanged = false; bool otherSourceChanged = false; using (SystemConfigurationSource systemSource = new SystemConfigurationSource(true, 50)) using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, true, 50)) { 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(500); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void SaveConfigurationSectionWithNoConfigurationFileThrows() { SystemConfigurationSource source = new SystemConfigurationSource(); source.Save("foo.exe.cofig", InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection()); }
public void RegisteredObjectForNonRequestedSectionIsNotNotified() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ConfigSourceChanged(localSectionSource); Assert.IsFalse(updatedSectionsTally.ContainsKey(localSection)); }
public void WatchedSectionInExternalFileValuesAreUpdatedIfExternalFileChangesAndNotificationIsFired() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section1 = source.GetSection(externalSection); Assert.IsNotNull(section1); DummySection dummySection1 = section1 as DummySection; Assert.AreEqual(externalSection, dummySection1.Name); Assert.AreEqual(20, dummySection1.Value); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); DummySection rwSection = rwConfiguration.GetSection(externalSection) as DummySection; rwSection.Value = 25; rwConfiguration.Save(); source.ExternalConfigSourceChanged(externalSectionSource); section1 = source.GetSection(externalSection); Assert.IsNotNull(section1); dummySection1 = section1 as DummySection; Assert.AreEqual(externalSection, dummySection1.Name); Assert.AreEqual(25, dummySection1.Value); }
public void WatchedExistingSectionInExternalFileIsNoLongerWatchedIfRemovedFromConfigurationAndExternalFileWatcherIsRemoved() { IConfigurationSourceTest source = new SystemConfigurationSource(false); DummySection dummySection1 = source.GetSection(localSection) as DummySection; DummySection dummySection2 = source.GetSection(externalSection) as DummySection; Assert.IsNotNull(dummySection1); Assert.IsNotNull(dummySection2); Assert.AreEqual(2, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.IsTrue(source.WatchedConfigSources.Contains(externalSectionSource)); Assert.AreEqual(3, source.WatchedSections.Count); //watches ConfigurationSourceSection + externalSection + localSection Assert.IsTrue(source.WatchedSections.Contains(localSection)); Assert.IsTrue(source.WatchedSections.Contains(externalSection)); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Sections.Remove(externalSection); rwConfiguration.Save(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(2, source.WatchedConfigSources.Count); Assert.IsTrue(source.WatchedConfigSources.Contains(localSectionSource)); Assert.IsTrue(source.WatchedConfigSources.Contains(SystemConfigurationSource.NullConfigSource)); Assert.AreEqual(3, source.WatchedSections.Count); Assert.IsTrue(source.WatchedSections.Contains(localSection)); Assert.IsTrue(source.WatchedSections.Contains(externalSection)); Assert.AreEqual(2, source.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Count); Assert.IsTrue(source.ConfigSourceWatcherMappings[string.Empty].WatchedSections.Contains(localSection)); Assert.AreEqual(1, source.ConfigSourceWatcherMappings[SystemConfigurationSource.NullConfigSource].WatchedSections.Count); Assert.IsTrue(source.ConfigSourceWatcherMappings[SystemConfigurationSource.NullConfigSource].WatchedSections.Contains(externalSection)); }
public void GetsNullIfSectionDoesNotExist() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section = source.GetSection(nonExistingSection); Assert.IsNull(section); }
public void TryToSaveWithNullOrEmptySectionNameThrows() { SystemConfigurationSource source = new SystemConfigurationSource(); source.Save(file, null, CreateInstrumentationSection()); }
public void TryToSaveWithTheWrongConfigurationSaveParameterTypeThrows() { SystemConfigurationSource source = new SystemConfigurationSource(); source.Add(new WrongConfigurationSaveParameter(), InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection()); }
public void RegisteredObjectForExternalFileIsNotifiedOfSectionChangesForAppConfigIfConfigSourceForExternalSectionNotChanged() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(externalSection); source.AddSectionChangeHandler(externalSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.ConfigSourceChanged(localSectionSource); Assert.IsFalse(updatedSectionsTally.ContainsKey(externalSection)); }
public void TryToSaveWithNullSectionThrows() { SystemConfigurationSource source = new SystemConfigurationSource(); source.Save(file, InstrumentationConfigurationSection.SectionName, null); }
public void TryToSaveWithNullOrEmptyFileNameThrows() { SystemConfigurationSource source = new SystemConfigurationSource(); source.Save((string)null, InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection()); }
public void RestoredSectionGetsNotificationOnRestoreAndGetsFurtherNotifications() { IConfigurationSourceTest source = new SystemConfigurationSource(false); object section1 = source.GetSection(localSection); Assert.IsNotNull(section1); object section2 = source.GetSection(localSection2); Assert.IsNotNull(section2); source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged)); source.AddSectionChangeHandler(localSection2, new ConfigurationChangedEventHandler(OnConfigurationChanged)); // a change in system config notifies both sections System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Save(); source.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(); source.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(); source.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(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(4, updatedSectionsTally[localSection]); Assert.AreEqual(3, updatedSectionsTally[localSection2]); // further updates notify both sections rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); rwConfiguration.Save(); source.ConfigSourceChanged(localSectionSource); Assert.AreEqual(5, updatedSectionsTally[localSection]); Assert.AreEqual(4, updatedSectionsTally[localSection2]); }
public void Initialize() { this.configurationSource = new SystemConfigurationSource(); this.retryPolicySettings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(this.configurationSource); this.retryManager = retryPolicySettings.BuildRetryManager(); }
public void GetsNotifiedOfMultipleRetrievedSection() { IConfigurationSourceTest source = new SystemConfigurationSource(false); source.GetSection(localSection); source.GetSection(localSection2); source.SourceChanged += this.OnConfigurationSourceChanged; source.ConfigSourceChanged(localSectionSource); CollectionAssert.AreEquivalent(new[] { ConfigurationSourceSection.SectionName, localSection, localSection2 }, new List<string>(updatedSections)); }