예제 #1
0
        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));
        }
예제 #2
0
        /// <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);
        }
예제 #3
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));
        }
예제 #4
0
 /// <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();
 }
예제 #5
0
        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);
        }
예제 #6
0
 /// <inheritdoc/>
 public override bool Matches(object o)
 {
     this.actual = InputBuilder.From(o).Build();
     result      = validator.ValidateInstance(o as ISource);
     return(result.Valid);
 }