Ejemplo n.º 1
0
        public void Test_FileInheritsDirectoryConfiguration()
        {
            var directoryConfig = CreateConfigFile("config1.json",
                                                   new JObject(
                                                       new JProperty("SomeKey", "SomeValue")));

            var directory = new Directory(null, "Irrelevant");

            var directoryConfigMock = MockFile("MusicFileCop.json", directoryConfig, directory);
            var fileMock            = MockFile("file1.ext", "", directory);

            directory.AddFile(directoryConfigMock.Object);
            directory.AddFile(fileMock.Object);


            var mapper = new ConfigurationMapper();

            var configurationLoader = new ConfigurationLoader(mapper, MockDefaultConfigurationNode().Object);

            configurationLoader.LoadConfiguration(MockConfigurationNode().Object, directory);

            var fileConfig = mapper.GetConfiguration(fileMock.Object);

            Assert.NotNull(fileConfig);
            Assert.Equal("SomeValue", fileConfig.GetValue("SomeKey"));
        }
Ejemplo n.º 2
0
        public void Test_LoadConfigurationForFile()
        {
            var filePath = CreateConfigFile("config.json",
                                            new JObject(
                                                new JProperty("SomeKey", "SomeValue")));

            var directory = new Directory(null, "dir");

            var fileMock = MockFile("file.ext", "", directory);

            directory.AddFile(fileMock.Object);

            var configFileMock = MockFile("file.ext.MusicFileCop.json", filePath, directory);

            directory.AddFile(configFileMock.Object);

            var mapper = new ConfigurationMapper();

            var configurationLoader = new ConfigurationLoader(mapper, MockDefaultConfigurationNode().Object);

            configurationLoader.LoadConfiguration(MockConfigurationNode().Object, fileMock.Object);

            var config = mapper.GetConfiguration(fileMock.Object);

            Assert.NotNull(config);

            Assert.Equal("SomeValue", config.GetValue("SomeKey"));
        }
Ejemplo n.º 3
0
        public void Test_LoadConfigurationForFile()
        {
            var filePath = CreateConfigFile("config.json",
              new JObject(
                  new JProperty("SomeKey", "SomeValue")));

            var directory = new Directory(null, "dir");

            var fileMock = MockFile("file.ext", "", directory);
            directory.AddFile(fileMock.Object);

            var configFileMock = MockFile("file.ext.MusicFileCop.json", filePath, directory);            
            directory.AddFile(configFileMock.Object);
                      
            var mapper = new ConfigurationMapper();

            var configurationLoader = new ConfigurationLoader(mapper, MockDefaultConfigurationNode().Object);
            configurationLoader.LoadConfiguration(MockConfigurationNode().Object, fileMock.Object);

            var config = mapper.GetConfiguration(fileMock.Object);
            Assert.NotNull(config);

            Assert.Equal("SomeValue", config.GetValue("SomeKey"));
            

        }
Ejemplo n.º 4
0
        IDirectory LoadDirectory(string path, IDirectory parent)
        {
            m_Logger.Info($"Loading directory '{path}'");

            // throw exception if directory does not exist
            if (!IO.Directory.Exists(path))
            {
                throw new DirectoryNotFoundException($"Could not find directory '{path}'");
            }

            // create directory object
            var currentDirectory = new Directory(parent, path);

            // load files
            foreach (var filePath in IO.Directory.GetFiles(path))
            {
                var file = new File(currentDirectory, filePath);
                currentDirectory.AddFile(file);
            }

            // load sub-directories
            foreach (var directoryPath in IO.Directory.GetDirectories(path))
            {
                var directory = LoadDirectory(directoryPath, currentDirectory);
                currentDirectory.AddDirectory(directory);
            }

            return(currentDirectory);
        }
Ejemplo n.º 5
0
        IDirectory LoadDirectory(string path, IDirectory parent)
        {
            m_Logger.Info($"Loading directory '{path}'");

            // throw exception if directory does not exist
            if (!IO.Directory.Exists(path))
            {
                throw new DirectoryNotFoundException($"Could not find directory '{path}'");
            }
            
            // create directory object
            var currentDirectory = new Directory(parent, path);

            // load files 
            foreach (var filePath in IO.Directory.GetFiles(path))
            {
                var file = new File(currentDirectory, filePath);
                currentDirectory.AddFile(file);
            }

            // load sub-directories
            foreach (var directoryPath in IO.Directory.GetDirectories(path))
            {
                var directory = LoadDirectory(directoryPath, currentDirectory);
                currentDirectory.AddDirectory(directory);
            }

            return currentDirectory;
        }
Ejemplo n.º 6
0
        public void Test_FileInheritsDirectoryConfiguration()
        {
            var directoryConfig = CreateConfigFile("config1.json",
             new JObject(
                 new JProperty("SomeKey", "SomeValue")));
            
            var directory = new Directory(null, "Irrelevant");

            var directoryConfigMock = MockFile("MusicFileCop.json", directoryConfig, directory);
            var fileMock = MockFile("file1.ext", "", directory);

            directory.AddFile(directoryConfigMock.Object);
            directory.AddFile(fileMock.Object);

            
            var mapper = new ConfigurationMapper();
                       
            var configurationLoader = new ConfigurationLoader(mapper, MockDefaultConfigurationNode().Object);
            configurationLoader.LoadConfiguration(MockConfigurationNode().Object, directory);

            var fileConfig = mapper.GetConfiguration(fileMock.Object);

            Assert.NotNull(fileConfig);
            Assert.Equal("SomeValue", fileConfig.GetValue("SomeKey"));            
        }