コード例 #1
0
        public void IgnoreMatchingNone()
        {
            var xml =
                @"<RecursiveCleaner>
    <Ignore>
        <MatchingNone>            
            <OlderThan seconds='1' />
            <Regex>.*</Regex>
            <Wildcards>*.*</Wildcards>
        </MatchingNone>       
    </Ignore>
</RecursiveCleaner>";

            using (var file = new TemporaryFile {
                Contents = xml
            })
            {
                var rules = ConfigFileReader.Read(file.Path).ToArray();
                Assert.AreEqual(1, rules.Length);
                Assert.IsInstanceOf <IgnoreRule>(rules[0]);
                Assert.IsInstanceOf <MatchingNoneFilter>(rules[0].Filter);
                var filter   = rules[0].Filter as ParentFilter;
                var children = filter.Children.ToArray();
                Assert.AreEqual(3, children.Length);
                Assert.IsInstanceOf <OlderThanFilter>(children[0]);
                Assert.IsInstanceOf <RegexFilter>(children[1]);
                Assert.IsInstanceOf <WildcardsFilter>(children[2]);
            }
        }
コード例 #2
0
 public void EmptyFile()
 {
     using (var file = new TemporaryFile())
     {
         ConfigFileReader.Read(file.Path);
     }
 }
コード例 #3
0
        public void InvalidRoot()
        {
            var xml = @"<Recursive></Recursive>";

            using (var file = new TemporaryFile {
                Contents = xml
            })
            {
                ConfigFileReader.Read(file.Path);
            }
        }
コード例 #4
0
        public void should_read_file_from_disk()
        {
            // Arrange
            string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test-config.yml");

            // Act
            string actualContent = _configFileReader.Read(new Uri(configPath));

            // Assert
            Assert.That(actualContent, Does.Contain("name: \"Text example\""));
        }
コード例 #5
0
        IEnumerable <IRule> ReadFolderLocalRules(DirectoryInfo folder)
        {
            var configPath = Path.Combine(folder.FullName, ConfigFileReader.Filename);

            if (!File.Exists(configPath))
            {
                return(Enumerable.Empty <IRule>());
            }

            Log.Info("Found {0}", configPath);
            try
            {
                return(ConfigFileReader.Read(configPath));
            }
            catch (Exception e)
            {
                Log.Error("Failed to read {0} : {1}", configPath, e.Message);
                return(Enumerable.Empty <IRule>());
            }
        }
コード例 #6
0
        public void DeleteFoldersWildcards()
        {
            var xml =
                @"<RecursiveCleaner>
    <Delete Target='Folders'>
        <Wildcards>\.\w+~</Wildcards>
  </Delete>
</RecursiveCleaner>";

            using (var file = new TemporaryFile {
                Contents = xml
            })
            {
                var rules = ConfigFileReader.Read(file.Path).ToArray();
                Assert.AreEqual(1, rules.Length);
                Assert.IsInstanceOf <DeleteRule>(rules[0]);
                Assert.AreEqual(RuleTarget.Folders, rules[0].Target);
                Assert.IsInstanceOf <WildcardsFilter>(rules[0].Filter);
            }
        }
コード例 #7
0
        public void RecycleFilesRegex()
        {
            var xml =
                @"<RecursiveCleaner>
    <Recycle Target='Files'>
        <Regex>\.\w+~</Regex>
  </Recycle>
</RecursiveCleaner>";

            using (var file = new TemporaryFile {
                Contents = xml
            })
            {
                var rules = ConfigFileReader.Read(file.Path).ToArray();
                Assert.AreEqual(1, rules.Length);
                Assert.IsInstanceOf <RecycleRule>(rules[0]);
                Assert.AreEqual(RuleTarget.Files, rules[0].Target);
                Assert.IsInstanceOf <RegexFilter>(rules[0].Filter);
            }
        }
コード例 #8
0
        public void ReadFileTest()
        {
            string           input_file = @"..\..\..\..\Docs\sample_input.txt";
            ConfigFileReader reader     = new ConfigFileReader(input_file);
            int entryCount = 0;

            reader.EntryFoundEvent += new EventHandler <ConfigEntry>((sender, entry) =>
            {
                entryCount++;

                Assert.IsNotNull(entry.Path);
                Assert.IsNotNull(entry.AllowedHeaders);
                Assert.IsNotNull(entry.AllowedMethods);
                Assert.IsNotNull(entry.AllowedOrigins);

                if (entry.Path == "/roles")
                {
                    Assert.AreEqual(entry.AllowedHeaders, "Content-Type,x-requested-with,Access-Control-Allow-Headers,Access-Control-Allow-Origin,Access-Control-Allow-Methods");
                    Assert.AreEqual(entry.AllowedMethods, "get,options");
                    Assert.AreEqual(entry.AllowedOrigins, "*");
                }
                else if (entry.Path == "/categories")
                {
                    Assert.AreEqual(entry.AllowedHeaders, "Content-Type,x-requested-with,Access-Control-Allow-Headers,Access-Control-Allow-Origin,Access-Control-Allow-Methods");
                    Assert.AreEqual(entry.AllowedMethods, "*");
                    Assert.AreEqual(entry.AllowedOrigins, "mydomain.com,myhost.com");
                }
                else if (entry.Path == "/posts")
                {
                    Assert.AreEqual(entry.AllowedHeaders, "Content-Type,x-requested-with,Access-Control-Allow-Headers,Access-Control-Allow-Origin,Access-Control-Allow-Methods");
                    Assert.AreEqual(entry.AllowedMethods, "get,options");
                    Assert.AreEqual(entry.AllowedOrigins, "*");
                }
                else
                {
                    Assert.Fail("Invalid path has been read");
                }
            });
            reader.Read();
            Assert.AreEqual(entryCount, 2);
        }
コード例 #9
0
        public void FourLevel()
        {
            var xml =
                @"<RecursiveCleaner>
    <Ignore>
        <MatchingNone>      
            <MatchingAll>
                <MatchingAny>
                    <Wildcards>*.*</Wildcards>
                </MatchingAny>
            </MatchingAll>      
        </MatchingNone>       
    </Ignore>
</RecursiveCleaner>";

            using (var file = new TemporaryFile {
                Contents = xml
            })
            {
                var rules = ConfigFileReader.Read(file.Path).ToArray();
                Assert.AreEqual(1, rules.Length);

                Assert.IsInstanceOf <MatchingNoneFilter>(rules[0].Filter);
                var filter1   = rules[0].Filter as ParentFilter;
                var children1 = filter1.Children.ToArray();
                Assert.AreEqual(1, children1.Length);

                Assert.IsInstanceOf <MatchingAllFilter>(children1[0]);
                var filter2   = children1[0] as ParentFilter;
                var children2 = filter2.Children.ToArray();
                Assert.AreEqual(1, children2.Length);

                Assert.IsInstanceOf <MatchingAnyFilter>(children2[0]);
                var filter3   = children2[0] as ParentFilter;
                var children3 = filter3.Children.ToArray();
                Assert.AreEqual(1, children3.Length);

                Assert.IsInstanceOf <WildcardsFilter>(children3[0]);
            }
        }
コード例 #10
0
        public void IgnoreFilerAndFoldersOlderThan()
        {
            var xml =
                @"<RecursiveCleaner>
    <Ignore Target='FilesAndFolders'>
        <OlderThan years='1' months='2' days='3' hours='4' minutes='5' seconds='6' />
    </Ignore>
</RecursiveCleaner>";

            using (var file = new TemporaryFile {
                Contents = xml
            })
            {
                var rules = ConfigFileReader.Read(file.Path).ToArray();
                Assert.AreEqual(1, rules.Length);
                Assert.IsInstanceOf <IgnoreRule>(rules[0]);
                Assert.AreEqual(RuleTarget.FilesAndFolders, rules[0].Target);
                Assert.IsInstanceOf <OlderThanFilter>(rules[0].Filter);
                var filter = rules[0].Filter as OlderThanFilter;
                Assert.AreEqual(4, (int)filter.TimeSpan.Hours);
                Assert.AreEqual(5, (int)filter.TimeSpan.Minutes);
                Assert.AreEqual(6, (int)filter.TimeSpan.Seconds);
            }
        }