public void BulkSetGetTest() { var provider = new FileConfigurationProvider(CONFIG_FILE_NAME); CommonTestRunner commonTests = new CommonTestRunner(provider); commonTests.RunBulkSetGetTest(); }
public void ReadUnsetOptionsWithDefaultValueTest() { var provider = new FileConfigurationProvider(CONFIG_FILE_NAME); CommonTestRunner commonTests = new CommonTestRunner(provider); commonTests.RunReadUnsetOptionsWithDefaultValueTest(); }
public void OnLoadErrorWillBeCalledOnXmlParseError() { _fileSystem.WriteFile("error.xml", @"gobblygook"); FileConfigurationProvider provider = null; Exception error = null; Action <FileLoadExceptionContext> loadError = c => { error = c.Exception; provider = c.Provider; }; try { CreateBuilder().AddJsonFile("error.xml") .SetFileLoadExceptionHandler(loadError) .Build(); } catch (Exception e) { Assert.Equal(e, error); } Assert.NotNull(provider); }
public void OnLoadErrorWillBeCalledOnJsonParseError() { _fileSystem.WriteFile(Path.Combine(_basePath, "error.json"), @"{""JsonKey1"": ", absolute: true); FileConfigurationProvider provider = null; Exception jsonError = null; Action <FileLoadExceptionContext> jsonLoadError = c => { jsonError = c.Exception; provider = c.Provider; }; try { new ConfigurationBuilder() .AddJsonFile("error.json") .SetFileLoadExceptionHandler(jsonLoadError) .Build(); } catch (Exception e) { Assert.Equal(e, jsonError); } Assert.NotNull(provider); }
public void OnLoadErrorWillBeCalledOnIniLoadError() { _fileSystem.WriteFile("error.ini", @"IniKey1=IniValue1 IniKey1=IniValue2"); FileConfigurationProvider provider = null; Exception error = null; Action <FileLoadExceptionContext> loadError = c => { error = c.Exception; provider = c.Provider; }; try { CreateBuilder().AddIniFile("error.ini") .SetFileLoadExceptionHandler(loadError) .Build(); } catch (FormatException e) { Assert.Equal(e, error); } Assert.NotNull(provider); }
public EmbeddedConfigurationProvider(Stream fileStream) { var source = new TSource(); _provider = source.Build(new ConfigurationBuilder()) as FileConfigurationProvider; _provider.Load(fileStream); }
public void Should_load_an_existing_int_value() { IConfigurationProvider configurationProvider = new FileConfigurationProvider(); int intValue = configurationProvider.GetSetting("SimpleValue", 0); Assert.AreEqual(42, intValue); }
public void SaveOptionsToFileTest() { var provider = new FileConfigurationProvider(CONFIG_FILE_NAME); // Fill it with random information TestUtils.FillProviderWithTestData(provider, 50); // Save provider.SaveConfiguration(); }
public void Should_load_an_existing_string_value() { IConfigurationProvider configurationProvider = new FileConfigurationProvider(); string stringValue; bool present = configurationProvider.TryGetSetting("SimpleString", out stringValue); Assert.IsTrue(present); Assert.AreEqual("Hello, World.", stringValue); }
/// <summary> /// Initializes a new instance of the <see cref="ProcessIncludesConfigurationProvider"/> class. /// </summary> /// <param name="configurationProvider">configurationProvider</param> /// <param name="rootPath">rootPath</param> /// <param name="valueEvaluators">Evaluator that can be used in include.</param> public ProcessIncludesConfigurationProvider( FileConfigurationProvider configurationProvider, string rootPath, IReadOnlyCollection <IValueEvaluator> valueEvaluators = null) : base(configurationProvider.Source) { _configurationProvider = configurationProvider; _rootPath = rootPath; _valueEvaluators = valueEvaluators; }
public void Should_get_the_default_with_server() { IConfigurationProvider configurationProvider = new FileConfigurationProvider(); IConnectionStringProvider connectionStringProvider = new ConnectionStringProvider(configurationProvider); string providerName; string connectionString; Assert.IsTrue(connectionStringProvider.TryGetConnectionString("default", out connectionString, out providerName, "remote")); Assert.AreEqual("Server=remote;Database=test", connectionString); Assert.AreEqual("easyProvider", providerName); }
public void Should_map_the_settings_from_the_configuration_provider() { IConfigurationProvider configurationProvider = new FileConfigurationProvider(); var converterCache = new DynamicObjectConverterCache(new DynamicImplementationBuilder()); var settingsProvider = new ConfigurationSettingsProvider(configurationProvider, converterCache); RabbitMqSettings settings; Assert.IsTrue(settingsProvider.TryGetSettings("RabbitMQ", out settings)); Assert.IsNotNull(settings); Assert.AreEqual("localhost", settings.Host); Assert.AreEqual("vortex", settings.VirtualHost); Assert.AreEqual("joe", settings.Username); Assert.AreEqual("guess", settings.Password); Assert.AreEqual(5672, settings.Port); Assert.AreEqual(0, settings.Heartbeat); Assert.IsNull(settings.Options); }
public void OnLoadErrorCanIgnoreErrors() { _fileSystem.WriteFile("error.json", @"{""JsonKey1"": "); FileConfigurationProvider provider = null; Action <FileLoadExceptionContext> jsonLoadError = c => { provider = c.Provider; c.Ignore = true; }; CreateBuilder() .AddJsonFile(s => { s.Path = "error.json"; s.OnLoadException = jsonLoadError; }) .Build(); Assert.NotNull(provider); }
public void SaveOptionsToFileThenLoadTest() { var writeProvider = new FileConfigurationProvider(CONFIG_FILE_NAME); // Fill it with random information var testData = TestUtils.FillProviderWithTestData(writeProvider, 50); // Save writeProvider.SaveConfiguration(); // Read and validate var readProvider = new FileConfigurationProvider(CONFIG_FILE_NAME); readProvider.LoadConfiguration(); foreach (var td in testData) { var expectedValue = td.Value; var actualValue = readProvider.GetOption(td.Key); Assert.AreEqual(expectedValue, actualValue); } }
public EmbeddedConfigurationProvider(string filePath) { var fileInfo = new FileInfo(filePath); var file = fileInfo.FullName; var source = new TSource(); if (source is JsonConfigurationSource jsonConfigurationSource) { jsonConfigurationSource.Optional = true; jsonConfigurationSource.FileProvider = new PhysicalFileProvider(Path.GetDirectoryName(file)); jsonConfigurationSource.Path = Path.GetFileName(file); jsonConfigurationSource.ReloadOnChange = true; } else if (source is XmlConfigurationSource xmlConfigurationSource) { xmlConfigurationSource.Optional = true; xmlConfigurationSource.FileProvider = new PhysicalFileProvider(Path.GetDirectoryName(file)); xmlConfigurationSource.Path = Path.GetFileName(file); xmlConfigurationSource.ReloadOnChange = true; } this._provider = (FileConfigurationProvider)source.Build(new ConfigurationBuilder()); this._provider.Load(); }
/// <summary>Attempts to bind the given object instance to configuration section value by FileConfigurationProvider.</summary> /// <param name="options">The object to bind.</param> /// <param name="value">The value to bind.</param> /// <param name="provider">The <see cref="T:FileConfigurationProvider" /> to load the value.</param> public static void Bind <TOptions>([NotNull] TOptions options, string value, [NotNull] FileConfigurationProvider provider) where TOptions : class { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (string.IsNullOrWhiteSpace(value)) { return; } if (provider == null) { throw new ArgumentNullException(nameof(provider)); } var root = new ConfigurationRoot(new List <IConfigurationProvider> { provider }); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(value))) provider.Load(stream); root.Bind(options); }
/// <inheritdoc /> public IConfigurationProvider Build(IConfigurationBuilder builder) { FileConfigurationProvider fileConfigurationProvider = (FileConfigurationProvider)_jsonConfigurationSource.Build(builder); return(new ProcessIncludesConfigurationProvider(fileConfigurationProvider, _rootPath, _valueEvaluators)); }
/// <summary> /// Initializes a new instance of the <see cref="PreprocessConfigurationProvider"/> class. /// </summary> /// <param name="configurationProvider">configurationProvider</param> /// <param name="rootPath">rootPath</param> public PreprocessConfigurationProvider(FileConfigurationProvider configurationProvider, string rootPath) : base(configurationProvider.Source) { _configurationProvider = configurationProvider; _rootPath = rootPath; }
static ScheduleMessageService CreateService(HostSettings arg) { var configurationProvider = new FileConfigurationProvider(); return(new ScheduleMessageService(configurationProvider)); }
void initializeView() { if (!ArcGISOnlineEnvironment.ArcGISOnline.IsInitialized) // Wait for AGOL environment initialization { EventHandler <EventArgs> onInitialized = null; onInitialized = (o, e) => { ArcGISOnlineEnvironment.ArcGISOnline.Initialized -= onInitialized; initializeView(); }; ArcGISOnlineEnvironment.ArcGISOnline.Initialized += onInitialized; } else { WindowManager manager = View != null && View.WindowManager != null ? View.WindowManager : null; string portalUrl = BaseUri.Scheme == "http" ? ViewerApplication.ArcGISOnlineSharing : ViewerApplication.ArcGISOnlineSecure; // TODO: Investigate difference between ViewerApplication.ArcGISOnlineProxy and ViewerApplication.Proxy ArcGISPortal portal = new ArcGISPortal() { Url = portalUrl, Token = ArcGISOnlineEnvironment.ArcGISOnline.User != null ? ArcGISOnlineEnvironment.ArcGISOnline.User.Token : null, ProxyUrl = ViewerApplication.ArcGISOnlineProxy }; View = new View(ApplicationServices, manager) { IsEditMode = IsEditMode, BaseUrl = BaseUri.ToString(), ApplicationColorSet = ApplicationColorSet, LayoutProvider = new LayoutFileProvider() { LayoutFileContents = layoutFileContents, }, Portal = portal }; if (!string.IsNullOrWhiteSpace(ConfigurationStoreFilePath)) { View.ConfigurationStoreProvider = new ViewerConfigurationStoreProvider(ViewerApplication.GeometryService, ViewerApplication.BingMapsAppId, ViewerApplication.PortalAppId); } View.ProxyUrl = View.DefaultProxyUrl = ViewerApplication.Proxy; layoutResourceDictionaries = new List <ResourceDictionary>(); foreach (string layoutResourceDictionaryFileContent in layoutResourceDictionaryFileContents) { if (!string.IsNullOrWhiteSpace(layoutResourceDictionaryFileContent)) { ResourceDictionary resourceDict = XamlReader.Load(layoutResourceDictionaryFileContent) as ResourceDictionary; if (resourceDict != null) { Application.Current.Resources.MergedDictionaries.Add(resourceDict); layoutResourceDictionaries.Add(resourceDict); } } } View.LayoutResourceDictionaries = layoutResourceDictionaries; if (!string.IsNullOrWhiteSpace(ThemeFilePath)) { View.ThemeProvider = new ThemeProvider() { ThemeFileUrl = ThemeFilePath, }; } if (!string.IsNullOrWhiteSpace(ConnectionsFileFilePath)) { View.ConnectionsProvider = new FileConnectionsProvider() { ConfigurationFile = new DataFile() { IsUrl = true, Path = ConnectionsFileFilePath } }; } if (!string.IsNullOrWhiteSpace(MapConfigurationFilePath)) { FileConfigurationProvider fileConfigurationProvider = ConfigurationProvider ?? new FileConfigurationProvider(); fileConfigurationProvider.ConfigurationFile = new DataFile() { IsUrl = true, Path = MapConfigurationFilePath }; View.ConfigurationProvider = fileConfigurationProvider; } if (!string.IsNullOrWhiteSpace(SymbolConfigurationFilePath)) { View.SymbolConfigProvider = new FileSymbolConfigProvider() { ConfigFileUrl = SymbolConfigurationFilePath, ClassBreaksColorGradientsConfigFileUrl = ClassBreaksColorGradientsConfigFileUrl, HeatMapColorGradientsConfigFileUrl = HeatMapColorGradientsConfigFileUrl, SymbolFolderParentUrl = SymbolFolderParentUrl, UniqueValueColorGradientsConfigFileUrl = UniqueValueColorGradientsConfigFileUrl, }; } View.ExtensionsDataManager = new ExtensionsDataManager() { ExtensionsConfigData = new ExtensionsConfigData(controlsXmlFileContents) }; View.ExtensionBehaviors = getBehaviors(behaviorsXmlFileContents); View.ExtensionLoadFailed += new EventHandler <ExceptionEventArgs>(View_ExtensionLoadFailed); View.ConfigurationLoaded += new EventHandler(View_ConfigurationLoaded); this.Content = View; OnViewInitialized(new ViewEventArgs() { View = View }); } }
static ScheduleMessageService CreateService(HostSettings arg) { var configurationProvider = new FileConfigurationProvider(); return new ScheduleMessageService(configurationProvider); }
public MateralJsonConfigurationProvider(FileConfigurationProvider jsonConfigurationProvider) : base((JsonConfigurationSource)jsonConfigurationProvider.Source) { }