public void FileNoCollision() { using (TemporaryFolder folder1 = new TemporaryFolder(), folder2 = new TemporaryFolder()) { var file = folder1.CreateFile(); var rule = new MoveRule { Destination = folder2.Path }; rule.Apply(file.FileInfo, environment); Assert.IsFalse(folder1.Files.Any(x => x.Name == file.Name)); Assert.IsTrue(folder2.Files.Any(x => x.Name == file.Name)); } }
public void FileIfExistsCancel() { using (TemporaryFolder folder1 = new TemporaryFolder(), folder2 = new TemporaryFolder()) { var file1 = folder1.CreateFile(); var file2 = folder2.CreateFile(file1.Name); var rule = new MoveRule { Destination = folder2.Path, IfExists = MoveRule.IfExistsMode.Cancel }; rule.Apply(file1.FileInfo, environment); Assert.IsTrue(folder1.Files.Any(x => x.Name == file1.Name)); Assert.AreEqual(1, folder2.Files.Count()); } }
private static IEnumerable <Position> GetPositions( PlayerColor color, Board board, Position origin, MoveRule moveRule) { foreach (var delta in moveRule.Deltas) { var count = 0; var position = origin + delta; var pathFree = true; while (count++ < moveRule.MaxMultiplier && BasicLegality(color, position, board) && pathFree) { yield return(position); pathFree = board[position].Color == PlayerColor.None; position += delta; } } }
public void MoveRule() { string expected = File.ReadAllText(Path.Combine(_requestsTestDataPath, "MoveRule.xml")); var request = new MoveRule { SessionId = "sid", Who = "*****@*****.**", RuleID = 1, MoveType = TRuleMoveType.Down }; var xml = request.ToXml().InnerXmlFormatted(); Assert.AreEqual(expected, xml); XmlDocument doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(Path.Combine(_responsesTestDataPath, "MoveRule.xml"))); var response = request.FromHttpRequestResult(new HttpRequestResult { Response = doc.InnerXml }); Assert.AreEqual("result", response.Type); Assert.True(response.Success); }
public void FileNoCollision() { using( TemporaryFolder folder1 = new TemporaryFolder(), folder2 = new TemporaryFolder() ) { var file = folder1.CreateFile(); var rule = new MoveRule { Destination = folder2.Path }; rule.Apply(file.FileInfo, environment); Assert.IsFalse(folder1.Files.Any(x => x.Name == file.Name)); Assert.IsTrue(folder2.Files.Any(x=>x.Name==file.Name)); } }
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; }
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); }