示例#1
0
        public void BuildReturnsSparqlResultsFormatXml()
        {
            TripleStore store = new MemoryTripleStore();

            store.Add(new Statement(new UriRef("http://example.com/subj"), new UriRef("http://example.com/property"), new UriRef("http://example.com/obj")));

            SparqlQuery query = new SparqlQuery("SELECT ?var WHERE { <http://example.com/subj> <http://example.com/property> ?var }");

            SparqlResultsFormatBuilder builder = new SparqlResultsFormatBuilder();

            XmlDocument resultsRaw       = builder.Build(query.ExecuteEnumerator(store), query);
            XmlDocument resultsCanonical = new XmlDocument();

            resultsCanonical.LoadXml(resultsRaw.InnerXml);

            XmlDocument expected = new XmlDocument();

            expected.LoadXml(@"<sparql xmlns=""http://www.w3.org/2005/sparql-results#"">
  <head>
    <variable name=""var""/>
  </head>
  <results ordered=""false"" distinct=""false"">
    <result>
      <binding name=""var""><uri>http://example.com/obj</uri></binding>
    </result>
  </results>
</sparql>");



            Assert.AreEqual(expected.InnerXml, resultsCanonical.InnerXml, "Result of query should equal expected XML");
        }
示例#2
0
        public void ExecuteEnumeratorPassesSelfToTripleStore()
        {
            SparqlQuery      query = new SparqlQuery("SELECT ?var WHERE { <http://example.com/subject> <http://example.com/predicate> ?var }");
            TripleStoreStore store = new TripleStoreStore();

            IEnumerator results = query.ExecuteEnumerator(store);

            Assert.IsTrue(store.WasSolveCalledWith(query), "Query should invoke triple store's solve method");
        }
示例#3
0
        private void AssertXPath(string xPath, SparqlQuery query, TripleStore store)
        {
            SparqlResultsFormatBuilder builder = new SparqlResultsFormatBuilder();

            XmlDocument results = builder.Build(query.ExecuteEnumerator(store), query);

            XPathNavigator  nav  = results.CreateNavigator();
            XPathExpression expr = nav.Compile(xPath);

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);

            nsmgr.AddNamespace("s", "http://www.w3.org/2005/sparql-results#");
            expr.SetContext(nsmgr);


            Assert.IsTrue(nav.Select(expr).MoveNext(), "Result of query should match XPath " + xPath + " result was " + results.InnerXml);
        }