public void JsonFileConfigurationSource_GetSectionByKeyThrowsInvalidOperationException() { var config = JsonFileConfigurationSource.FromFile("configuration.sample.json"); Assert.Throws <InvalidOperationException>(() => config.GetSection <UnconfiguredConfigSection>()); }
/// <summary> /// Runs the transpiler for the given configuration file. /// </summary> /// <param name="configurationFile"> /// Configuration file for the transpilation. If omitted, will be searched /// by looking in parent directories from the current working directory. /// </param> /// <param name="configurationReplaceTokens">Replacements for user-defined tokens in the configuration file.</param> private static void Execute(string configurationFile, IDictionary <string, string> configurationReplaceTokens) { // Configuration. var configuration = !string.IsNullOrWhiteSpace(configurationFile) ? JsonFileConfigurationSource.FromFile(configurationFile, configurationReplaceTokens) : JsonFileConfigurationSource.FromDirectory(Environment.CurrentDirectory, configurationReplaceTokens); // Change the current working directory based on the configuration file to allow relative paths. Environment.CurrentDirectory = configuration.ConfigurationFile.DirectoryName; // Logging. var logger = LoggerFactory.FromConfiguration(configuration); var stopwatch = Stopwatch.StartNew(); // Catch exceptions from the actual transpilation as // we can write them to the created logger. try { ExecuteTranspilation(configuration, logger); logger.WriteInformation($"Executed successfully, took {stopwatch.ElapsedMilliseconds}ms."); } catch (Exception exception) { logger.WriteError($"{exception}"); logger.WriteInformation($"Encountered an error after {stopwatch.ElapsedMilliseconds}ms."); throw; } }
public void JsonFileConfigurationSource_ThrowsConfigurationException_WhenReadingFails() { var exception = Assert.Throws <ConfigurationException>( () => JsonFileConfigurationSource.FromFile("configuration.missing.json")); // Underlying exception should indicate the missing file. Assert.IsType <FileNotFoundException>(exception.InnerException); }
public void JsonFileConfigurationSource_GetSectionByKeyThrowsConfigurationException() { var config = JsonFileConfigurationSource.FromFile("configuration.sample.json"); var exception = Assert.Throws <ConfigurationException>(() => config.GetSection <UnreadableConfigSection>()); Assert.NotNull(exception.InnerException); }
public void JsonFileConfigurationSource_ReplacesTokensInConfigurationFile() { var testvalue = "TestValue"; var config = JsonFileConfigurationSource.FromFile("configuration.sample.json", new Dictionary <string, string> { { "$TOKEN$", testvalue } }); var testConfig = config.GetSection <TestConfiguration>(); Assert.Equal(testvalue, testConfig.Value); }
public void JsonFileConfigurationSource_GetSectionByKeyReturnsDefaultValue() { var config = JsonFileConfigurationSource.FromFile("configuration.sample.json"); Assert.Null(config.GetSection <MissingConfigSection>()); }
public void JsonFileConfigurationSource_ReadsConfigurationFromJsonFile() { var config = JsonFileConfigurationSource.FromFile("configuration.sample.json"); Assert.Single(config.GetSection <InputConfiguration>().AssemblyFiles); }