示例#1
0
        public void JsonFileConfigurationSource_GetSectionByKeyThrowsInvalidOperationException()
        {
            var config = JsonFileConfigurationSource.FromFile("configuration.sample.json");

            Assert.Throws <InvalidOperationException>(() =>
                                                      config.GetSection <UnconfiguredConfigSection>());
        }
示例#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;
            }
        }
示例#3
0
        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);
        }
示例#4
0
        public void JsonFileConfigurationSource_GetSectionByKeyThrowsConfigurationException()
        {
            var config = JsonFileConfigurationSource.FromFile("configuration.sample.json");

            var exception = Assert.Throws <ConfigurationException>(() =>
                                                                   config.GetSection <UnreadableConfigSection>());

            Assert.NotNull(exception.InnerException);
        }
示例#5
0
        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);
        }
示例#6
0
        public void JsonFileConfigurationSource_GetSectionByKeyReturnsDefaultValue()
        {
            var config = JsonFileConfigurationSource.FromFile("configuration.sample.json");

            Assert.Null(config.GetSection <MissingConfigSection>());
        }
示例#7
0
        public void JsonFileConfigurationSource_ReadsConfigurationFromJsonFile()
        {
            var config = JsonFileConfigurationSource.FromFile("configuration.sample.json");

            Assert.Single(config.GetSection <InputConfiguration>().AssemblyFiles);
        }