public void Parse_ValidString()
        {
            var ruleString = @"^(x+) / $1x";
            var rule       = RenameRule.Parse(ruleString);

            Assert.IsTrue(rule.IsMatch("xx_"));
            Assert.AreEqual("xxx_", rule.Apply("xx_"));
        }
Esempio n. 2
0
        public void FileNoCollision()
        {
            using (TemporaryFolder folder = new TemporaryFolder())
            {
                var file = folder.CreateFile();

                var          originalName = file.Name;
                const string newName      = "test";

                var rule = new RenameRule
                {
                    Name = newName
                };

                rule.Apply(file.FileInfo, environment);

                Assert.IsFalse(folder.Files.Any(x => x.Name == originalName));
                Assert.IsTrue(folder.Files.Any(x => x.Name == newName));
                Assert.AreEqual(1, folder.Files.Count());
            }
        }
Esempio n. 3
0
        public void FileIfExistsCancel()
        {
            using (TemporaryFolder folder = new TemporaryFolder())
            {
                var file1 = folder.CreateFile();
                var file2 = folder.CreateFile();

                var originalName = file1.Name;
                var newName = file2.Name;

                var rule = new RenameRule
                {
                    Name = newName,
                    IfExists = RenameRule.IfExistsMode.Cancel
                };

                rule.Apply(file1.FileInfo, environment);

                Assert.IsTrue(folder.Files.Any(x => x.Name == originalName));
                Assert.IsTrue(folder.Files.Any(x => x.Name == newName));
                Assert.AreEqual(2, folder.Files.Count());
            }
        }
Esempio n. 4
0
        public void FileIfExistsDelete()
        {
            using (TemporaryFolder folder = new TemporaryFolder())
            {
                var file1 = folder.CreateFile();
                var file2 = folder.CreateFile();

                var originalName = file1.Name;
                var newName      = file2.Name;

                var rule = new RenameRule
                {
                    Name     = newName,
                    IfExists = RenameRule.IfExistsMode.Delete
                };

                rule.Apply(file1.FileInfo, environment);

                Assert.IsFalse(folder.Files.Any(x => x.Name == originalName));
                Assert.IsTrue(folder.Files.Any(x => x.Name == newName));
                Assert.AreEqual(1, folder.Files.Count());
            }
        }
		public ManualBranchResolverTest()
		{
			m_log = MockRepository.GenerateStub<ILogger>();
			m_tagResolver = MockRepository.GenerateStub<ITagResolver>();
			m_rule = new RenameRule(@"^(.*)", "$1-branchpoint");
		}
 public ManualBranchResolverTest()
 {
     m_log         = MockRepository.GenerateStub <ILogger>();
     m_tagResolver = MockRepository.GenerateStub <ITagResolver>();
     m_rule        = new RenameRule(@"^(.*)", "$1-branchpoint");
 }
 public void Parse_InvalidRegex()
 {
     var ruleString = @"(.**) / $1x";
     var rule       = RenameRule.Parse(ruleString);
 }
 public void Parse_InvalidString()
 {
     var ruleString = @"(.+) | $1x";
     var rule       = RenameRule.Parse(ruleString);
 }
Esempio n. 9
0
        public void FileNoCollision()
        {
            using( TemporaryFolder folder = new TemporaryFolder() )
            {
                var file = folder.CreateFile();

                var originalName = file.Name;
                const string newName = "test";

                var rule = new RenameRule
                {
                    Name = newName
                };

                rule.Apply(file.FileInfo, environment);

                Assert.IsFalse(folder.Files.Any(x => x.Name == originalName));
                Assert.IsTrue(folder.Files.Any(x => x.Name == newName));
                Assert.AreEqual(1, folder.Files.Count());
            }
        }
Esempio n. 10
0
        internal static IRule ReadRule(XmlReader xml, bool includeFilter=true)
        {
            IRule rule;

            var elementName = xml.Name;

            switch (elementName.ToLower())
            {
                case "recycle":
                    rule = new RecycleRule();
                    break;
                case "delete":
                    rule = new DeleteRule();
                    break;
                case "ignore":
                    rule = new IgnoreRule();
                    break;
                case "move":
                    rule = new MoveRule();
                    break;
                case "rename":
                    rule = new RenameRule();
                    break;
                default:
                    xml.Skip();
                    throw new IgnoredElementException(elementName);
            }

            var attributes = new AttributeParser(xml);

            rule.Target              = attributes.GetOptional("Target").AsEnum(RuleTarget.FilesAndFolders);
            rule.AppliesToSubfolders = attributes.GetOptional("ApplyToSubfolders").AsBool(true);

            if (rule is MoveRuleBase)
            {
                ((MoveRuleBase)rule).IfExists =
                    attributes.GetOptional("ifexists").AsEnum(MoveRuleBase.IfExistsMode.Cancel);
            }

            if( rule is MoveRule)
            {
                ((MoveRule)rule).Destination = attributes.GetMandatory("destination").AsString();
                ((MoveRule)rule).CreateFolder = attributes.GetOptional("createfolder").AsBool(true);
            }

            if (rule is RenameRule)
            {
                ((RenameRule)rule).Name = attributes.GetMandatory("name").AsString();
            }

            attributes.AssertNoUnused();

            if (includeFilter)
            {
                var filters = ReadFilters(xml).ToArray();

                if (filters.Length == 0)
                    throw new Exception("You must specificy a filter for this rule");

                if (filters.Length > 1)
                    throw new Exception("You can only specify one filter at rule's root. Please use <MatchingAll>, <MatchingAny> or <MatchingNone>.");

                rule.Filter = filters.First();
            }

            return rule;
        }
Esempio n. 11
0
        internal static IRule ReadRule(XmlReader xml, bool includeFilter = true)
        {
            IRule rule;

            var elementName = xml.Name;

            switch (elementName.ToLower())
            {
            case "recycle":
                rule = new RecycleRule();
                break;

            case "delete":
                rule = new DeleteRule();
                break;

            case "ignore":
                rule = new IgnoreRule();
                break;

            case "move":
                rule = new MoveRule();
                break;

            case "rename":
                rule = new RenameRule();
                break;

            default:
                xml.Skip();
                throw new IgnoredElementException(elementName);
            }

            var attributes = new AttributeParser(xml);

            rule.Target = attributes.GetOptional("Target").AsEnum(RuleTarget.FilesAndFolders);
            rule.AppliesToSubfolders = attributes.GetOptional("ApplyToSubfolders").AsBool(true);

            if (rule is MoveRuleBase)
            {
                ((MoveRuleBase)rule).IfExists =
                    attributes.GetOptional("ifexists").AsEnum(MoveRuleBase.IfExistsMode.Cancel);
            }

            if (rule is MoveRule)
            {
                ((MoveRule)rule).Destination  = attributes.GetMandatory("destination").AsString();
                ((MoveRule)rule).CreateFolder = attributes.GetOptional("createfolder").AsBool(true);
            }

            if (rule is RenameRule)
            {
                ((RenameRule)rule).Name = attributes.GetMandatory("name").AsString();
            }

            attributes.AssertNoUnused();

            if (includeFilter)
            {
                var filters = ReadFilters(xml).ToArray();

                if (filters.Length == 0)
                {
                    throw new Exception("You must specificy a filter for this rule");
                }

                if (filters.Length > 1)
                {
                    throw new Exception("You can only specify one filter at rule's root. Please use <MatchingAll>, <MatchingAny> or <MatchingNone>.");
                }

                rule.Filter = filters.First();
            }

            return(rule);
        }