public void JsonFileConfigurationSource_SearchesFileInParentDirectories() { var config = JsonFileConfigurationSource.FromDirectory("Configuration/Files/SampleDirectoryWithSubDirectory/SampleSubDirectoryWithConfigFile"); Assert.Equal("testcase-sample-subdirectory-with-configfile", config.GetSection <InputConfiguration>().AssemblyFiles.Single()); }
/// <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_NoSearchMatchThrowsConfigurationException() { Assert.Throws <ConfigurationException>( () => JsonFileConfigurationSource.FromDirectory("Configuration/Files/SampleDirectoryWithoutConfigFile")); }