Esempio n. 1
0
 public void TestRetrieveSingleFilm()
 {
     const string odataQuery = "http://example.org/odata/Films('Un_Chien_Andalou')";
     var parsedQuery = QueryDescriptorQueryNode.ParseUri(
         new Uri(odataQuery), new Uri(_odataBase), _dbpediaModel);
     var sparqlGenerator = new SparqlGenerator(_dbpediaMap);
     sparqlGenerator.ProcessQuery(parsedQuery);
     Console.WriteLine(sparqlGenerator.SparqlQueryModel.GetSparqlRepresentation());
     var mockRequest = new Mock<IODataRequestMessage>();
     mockRequest.Setup(m => m.Url).Returns(new Uri(odataQuery));
     var mockMessage = new Mock<IODataResponseMessage>();
     var outputStream = new MemoryStream();
     mockMessage.Setup(m => m.GetStream()).Returns(outputStream);
         var feedGenerator = new ODataFeedGenerator(mockRequest.Object, mockMessage.Object, _dbpediaMap, _odataBase, new ODataMessageWriterSettings{Indent = true});
     sparqlGenerator.SparqlQueryModel.Execute(_sparqlEndpoint, feedGenerator);
     outputStream.Seek(0, SeekOrigin.Begin);
     var validator = new XPathValidator(outputStream);
     validator.AddNamespace("atom", "http://www.w3.org/2005/Atom");
     validator.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
     validator.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     Console.WriteLine(validator.ToString());
     validator.AssertRoot("atom:entry");
     validator.AssertXPathValue("/atom:entry/atom:id", "http://example.org/odata/Films('Un_Chien_Andalou')");
     validator.AssertXPathValue("/atom:entry/atom:title", "");
     validator.AssertXPathValue("/atom:entry/atom:content/m:properties/d:Name", "Un Chien Andalou");
     validator.AssertXPathValue("/atom:entry/atom:content/m:properties/d:Runtime", "960.0");
     validator.AssertXPathValue("/atom:entry/atom:link[@rel='http://schemas.microsoft.com/ado/2007/08/dataservices/related/Director']/@href", "http://example.org/odata/Films('Un_Chien_Andalou')/Director");
 }
Esempio n. 2
0
        public void TestRetrieveSingleFilm()
        {
            const string odataQuery  = "http://example.org/odata/Films('Un_Chien_Andalou')";
            var          parsedQuery = QueryDescriptorQueryNode.ParseUri(
                new Uri(odataQuery), new Uri(_odataBase), _dbpediaModel);
            var sparqlGenerator = new SparqlGenerator(_dbpediaMap);

            sparqlGenerator.ProcessQuery(parsedQuery);
            Console.WriteLine(sparqlGenerator.SparqlQueryModel.GetSparqlRepresentation());
            var mockRequest = new Mock <IODataRequestMessage>();

            mockRequest.Setup(m => m.Url).Returns(new Uri(odataQuery));
            var mockMessage  = new Mock <IODataResponseMessage>();
            var outputStream = new MemoryStream();

            mockMessage.Setup(m => m.GetStream()).Returns(outputStream);
            var feedGenerator = new ODataFeedGenerator(mockRequest.Object, mockMessage.Object, _dbpediaMap, _odataBase, new ODataMessageWriterSettings {
                Indent = true
            });

            sparqlGenerator.SparqlQueryModel.Execute(_sparqlEndpoint, feedGenerator);
            outputStream.Seek(0, SeekOrigin.Begin);
            var validator = new XPathValidator(outputStream);

            validator.AddNamespace("atom", "http://www.w3.org/2005/Atom");
            validator.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
            validator.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
            Console.WriteLine(validator.ToString());
            validator.AssertRoot("atom:entry");
            validator.AssertXPathValue("/atom:entry/atom:id", "http://example.org/odata/Films('Un_Chien_Andalou')");
            validator.AssertXPathValue("/atom:entry/atom:title", "");
            validator.AssertXPathValue("/atom:entry/atom:content/m:properties/d:Name", "Un Chien Andalou");
            validator.AssertXPathValue("/atom:entry/atom:content/m:properties/d:Runtime", "960.0");
            validator.AssertXPathValue("/atom:entry/atom:link[@rel='http://schemas.microsoft.com/ado/2007/08/dataservices/related/Director']/@href", "http://example.org/odata/Films('Un_Chien_Andalou')/Director");
        }
Esempio n. 3
0
        private XPathValidator GenerateAndExecuteSparql(string odataQuery, SparqlMap sparqlMap, ODataVersion odataVersion = ODataVersion.V3)
        {
            var parsedQuery = QueryDescriptorQueryNode.ParseUri(
                new Uri(odataQuery),
                new Uri(_odataBase),
                _dbpediaModel);
            var sparqlGenerator = new SparqlGenerator(sparqlMap, "en");

            sparqlGenerator.ProcessQuery(parsedQuery);
            var mockRequest = new Mock <IODataRequestMessage>();

            mockRequest.Setup(m => m.Url).Returns(new Uri(odataQuery));
            var mockMessage  = new Mock <IODataResponseMessage>();
            var outputStream = new MemoryStream();

            mockMessage.Setup(m => m.GetStream()).Returns(outputStream);
            var feedGenerator = new ODataFeedGenerator(
                mockRequest.Object,
                mockMessage.Object, sparqlMap, _odataBase,
                new ODataMessageWriterSettings {
                Indent = true, Version = odataVersion
            });

            Console.WriteLine(sparqlGenerator.SparqlQueryModel.GetSparqlRepresentation());
            sparqlGenerator.SparqlQueryModel.Execute(_sparqlEndpoint, feedGenerator);
            outputStream.Seek(0, SeekOrigin.Begin);
            var validator = new XPathValidator(outputStream);

            validator.AddNamespace("atom", "http://www.w3.org/2005/Atom");
            validator.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
            validator.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
            return(validator);
        }
Esempio n. 4
0
 private XPathValidator GenerateAndExecuteSparql(string odataQuery, SparqlMap sparqlMap, ODataVersion odataVersion=ODataVersion.V3)
 {
     var parsedQuery = QueryDescriptorQueryNode.ParseUri(
         new Uri(odataQuery),
         new Uri(_odataBase),
         _dbpediaModel);
     var sparqlGenerator = new SparqlGenerator(sparqlMap, "en");
     sparqlGenerator.ProcessQuery(parsedQuery);
     var mockRequest = new Mock<IODataRequestMessage>();
     mockRequest.Setup(m => m.Url).Returns(new Uri(odataQuery));
     var mockMessage = new Mock<IODataResponseMessage>();
     var outputStream = new MemoryStream();
     mockMessage.Setup(m => m.GetStream()).Returns(outputStream);
     var feedGenerator = new ODataFeedGenerator(
         mockRequest.Object,
         mockMessage.Object, sparqlMap, _odataBase, 
         new ODataMessageWriterSettings{Indent = true, Version = odataVersion});
     Console.WriteLine(sparqlGenerator.SparqlQueryModel.GetSparqlRepresentation());
     sparqlGenerator.SparqlQueryModel.Execute(_sparqlEndpoint, feedGenerator);
     outputStream.Seek(0, SeekOrigin.Begin);
     var validator = new XPathValidator(outputStream);
     validator.AddNamespace("atom", "http://www.w3.org/2005/Atom");
     validator.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
     validator.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     return validator;
 }