private IStalkNode NewRegexLeafNode(XmlElement fragment) { RegexLeafNode node; switch (fragment.Name) { case "user": node = new UserStalkNode(); break; case "targetuser": node = new TargetUserStalkNode(); break; case "actinguser": node = new ActingUserStalkNode(); break; case "page": node = new PageStalkNode(); break; case "summary": node = new SummaryStalkNode(); break; case "flag": node = new FlagStalkNode(); break; case "log": node = new LogStalkNode(); break; case "additionaldata": node = new AdditionalDataNode(); break; default: throw new XmlException("Unknown element " + fragment.Name); } if (fragment.Attributes["caseinsensitive"] != null) { node.CaseInsensitive = XmlConvert.ToBoolean(fragment.Attributes["caseinsensitive"].Value); } node.SetMatchExpression(fragment.Attributes["value"].Value); return(node); }
protected IStalkNode CreateNode(string type, string stalkTarget) { IStalkNode newNode; var escapedTarget = Regex.Escape(stalkTarget); switch (type) { case "user": var usn = new UserStalkNode(); usn.SetMatchExpression(escapedTarget); newNode = usn; break; case "page": var psn = new PageStalkNode(); psn.SetMatchExpression(escapedTarget); newNode = psn; break; case "summary": var ssn = new SummaryStalkNode(); ssn.SetMatchExpression(escapedTarget); newNode = ssn; break; case "xml": try { var xml = this.xmlCacheService.RetrieveXml(this.User); if (xml == null) { throw new CommandErrorException("No cached XML. Please use the xml command first."); } newNode = this.stalkNodeFactory.NewFromXmlFragment(xml); } catch (XmlException ex) { throw new CommandErrorException(ex.Message, ex); } break; default: throw new CommandErrorException("Unknown stalk type!"); } return(newNode); }
public void ShouldSerialiseUserCorrectly() { // arrange var node = new UserStalkNode(); node.SetMatchExpression("abc"); var doc = new XmlDocument(); var snf = new StalkNodeFactory(this.phabExternalMock.Object); // act var result = snf.ToXml(doc, node); // assert Assert.AreEqual("<user value=\"abc\" />", result.OuterXml); }