[SetUp] public void ReadSource() { source = InputBuilder.FromFile(TestResources.BLAME_FILE).Build(); XmlDocument doc = new XmlDocument(); doc.Load(InputBuilder.FromFile(TestResources.BLAME_FILE).Build().Reader); sourceRootElement = doc.DocumentElement; }
private XmlDocument HandleWsSetup() { return(Convert.ToDocument(InputBuilder.FromString( "<root>\n" + "<!-- trim\tme -->\n" + "<child attr=' trim me ' attr2='not me'>\n" + " trim me \n" + "</child><![CDATA[ trim me ]]>\n" + "<?target trim me ?>\n" + "<![CDATA[ ]]>\n" + "</root>").Build())); }
// doesn't match public void SelectNodesWithDefaultNSNoPrefix() { IXPathEngine e = Engine; source = InputBuilder.FromString("<d xmlns='urn:test:1'><e/></d>") .Build(); Dictionary <string, string> m = new Dictionary <string, string>(); m[string.Empty] = "urn:test:1"; e.NamespaceContext = m; IEnumerable <XmlNode> it = e.SelectNodes("/d/e", source); Assert.IsTrue(it.GetEnumerator().MoveNext()); }
[Test] public void SelectNodesWithNS() { IXPathEngine e = Engine; source = InputBuilder.FromString("<n:d xmlns:n='urn:test:1'><n:e/></n:d>") .Build(); Dictionary <string, string> m = new Dictionary <string, string>(); m["x"] = "urn:test:1"; e.NamespaceContext = m; IEnumerable <XmlNode> it = e.SelectNodes("/x:d/x:e", source); Assert.IsTrue(it.GetEnumerator().MoveNext()); }
private string XPathEvaluate(object input) { XPathEngine engine = new XPathEngine(); if (prefix2Uri != null) { engine.NamespaceContext = prefix2Uri; } ISource s = InputBuilder.From(input).Build(); XmlNode n = Convert.ToNode(s); return(engine.Evaluate(xPath, n)); }
/// <inheritdoc/> public override bool Matches(object o) { XPathEngine engine = new XPathEngine(); if (prefix2Uri != null) { engine.NamespaceContext = prefix2Uri; } var s = InputBuilder.From(o).Build(); var n = Convert.ToNode(s); var nodes = engine.SelectNodes(xPath, n); return(nodes.Count() > 0); }
/// <inheritdoc/> public override ConstraintResult ApplyTo <TActual>(TActual actual) { XPathEngine engine = new XPathEngine(); if (prefix2Uri != null) { engine.NamespaceContext = prefix2Uri; } var s = InputBuilder.From(actual).Build(); var n = Convert.ToNode(s); var nodes = engine.SelectNodes(xPath, n); return(new HasXPathConstraintResult(this, actual, nodes)); }
/// <summary> /// Creates the constraint validating against the given schema(s). /// </summary> public SchemaValidConstraint(params object[] schema) : base(schema) { if (schema == null) { throw new ArgumentNullException("schema"); } if (schema.Any(s => s == null)) { throw new ArgumentException("must not contain null values", "schema"); } validator = Validator.ForLanguage(Languages.W3C_XML_SCHEMA_NS_URI); validator.SchemaSources = schema .Select(s => InputBuilder.From(s).Build()) .ToArray(); }
[Test] public void SelectNodesWithNS_NodeVersion() { IXPathEngine e = Engine; XmlDocument doc = new XmlDocument(); doc.Load(InputBuilder.FromString("<n:d xmlns:n='urn:test:1'><n:e/></n:d>").Build().Reader); sourceRootElement = doc.DocumentElement; Dictionary <string, string> m = new Dictionary <string, string>(); m["x"] = "urn:test:1"; e.NamespaceContext = m; IEnumerable <XmlNode> it = e.SelectNodes("/x:d/x:e", sourceRootElement); Assert.IsTrue(it.GetEnumerator().MoveNext()); }
private IList <Comparison> Compare(string controlXml, string testXml, bool ignoreDoctypeDeclarationAsWell) { ISource control = InputBuilder.From(controlXml).Build(); ISource test = InputBuilder.From(testXml).Build(); DOMDifferenceEngine e = new DOMDifferenceEngine(); if (ignoreDoctypeDeclarationAsWell) { e.DifferenceEvaluator = DifferenceEvaluators.IgnorePrologDifferences(); } else { e.DifferenceEvaluator = DifferenceEvaluators.IgnorePrologDifferencesExceptDoctype(); } var differences = new List <Comparison>(); e.DifferenceListener += (comparison, outcome) => differences.Add(comparison); e.Compare(control, test); return(differences); }
/// <inheritdoc/> public override bool Matches(object o) { this.actual = InputBuilder.From(o).Build(); result = validator.ValidateInstance(o as ISource); return(result.Valid); }
public void CreateTransformation() { t = new Transformation(InputBuilder.FromFile(TestResources.DOG_FILE) .Build()); t.Stylesheet = InputBuilder.FromFile(TestResources.ANIMAL_XSL).Build(); }