Exemplo n.º 1
0
        public void file_adapter_can_read_and_write_lines_to_file()
        {
            var temporaryFilePath = Path.GetTempFileName();
            var originalText      = "this is some temporary\n text to write\n to files\n";

            _fileAdapter.WriteAllText(temporaryFilePath, originalText);

            var writtenText = _fileAdapter.ReadAllText(temporaryFilePath);

            Assert.That(writtenText, Is.EqualTo(originalText));
        }
        private static T LoadJsonConfig <T>(string path, Func <T> emptyConfigurationFactory, Func <string, T> loaderMethod)
        {
            var fileAdapter = new FileAdapter();

            try
            {
                var configContents = fileAdapter.ReadAllText(path);

                return(loaderMethod(configContents));
            }
            catch (Exception ex)
            {
                Log.Warn($"Exception occurred loading JSON configuration file from '{path}' ('{ex.Message}'), assuming an empty configuration.");

                return(emptyConfigurationFactory());
            }
        }