Ejemplo n.º 1
0
        public void JsonFileConfigurationSource_SearchesFileInParentDirectories()
        {
            var config = JsonFileConfigurationSource.FromDirectory("Configuration/Files/SampleDirectoryWithSubDirectory/SampleSubDirectoryWithConfigFile");

            Assert.Equal("testcase-sample-subdirectory-with-configfile",
                         config.GetSection <InputConfiguration>().AssemblyFiles.Single());
        }
Ejemplo n.º 2
0
        /// <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;
            }
        }
Ejemplo n.º 3
0
 public void JsonFileConfigurationSource_NoSearchMatchThrowsConfigurationException()
 {
     Assert.Throws <ConfigurationException>(
         () => JsonFileConfigurationSource.FromDirectory("Configuration/Files/SampleDirectoryWithoutConfigFile"));
 }