public void StorageVirtuosoNativeUpdate() { VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); Object result = null; Console.WriteLine("Now we'll delete a Triple"); //Try a DELETE DATA manager.Update("DELETE DATA FROM <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}"); Console.WriteLine("Triple with subject <http://example.org/seven> should be missing - ASKing for it..."); //Try a SELECT query result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("Now we'll add the Triple back again"); //Try a INSERT DATA manager.Update("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}"); Console.WriteLine("Triple with subject <http://example.org/seven> should be restored - ASKing for it again..."); //Try a SELECT query result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}"); CheckQueryResult(result, true); } finally { if (manager != null) { manager.Dispose(); } } }
public void StorageVirtuosoBadUpdate() { VirtuosoManager virtuoso = VirtuosoTest.GetConnection(); try { virtuoso.Update("Bad update"); Assert.Fail("Expected an error"); } catch { //Expected so can be ignored Assert.IsFalse(virtuoso.HasOpenConnection, "Connection should be closed"); Assert.IsFalse(virtuoso.HasActiveTransaction, "Should be no active transaction"); } finally { virtuoso.Dispose(); } }
public void StorageVirtuosoNativeQueryAndUpdate() { NTriplesFormatter formatter = new NTriplesFormatter(); VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Console.WriteLine("Got the Virtuoso Manager OK"); Object result = null; Console.WriteLine("ASKing if there's any Triples"); //Try an ASK query result = manager.Query("ASK {?s ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("CONSTRUCTing a Graph"); //Try a CONSTRUCT result = manager.Query("CONSTRUCT {?s ?p ?o} FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, false); Console.WriteLine("DESCRIBEing a resource"); //Try a DESCRIBE result = manager.Query("DESCRIBE <http://example.org/one>"); CheckQueryResult(result, false); //Try another DESCRIBE result = manager.Query("DESCRIBE <http://example.org/noSuchThing>"); CheckQueryResult(result, false); Console.WriteLine("SELECTing the same Graph"); //Try a SELECT query result = manager.Query("SELECT * FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("SELECTing the same Graph using Project Expressions"); //Try a SELECT query result = manager.Query("SELECT (?s AS ?Subject) (?P as ?Predicate) (?o AS ?Object) FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("Now we'll delete a Triple"); //Try a DELETE DATA manager.Update("DELETE DATA { GRAPH <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".} }"); Console.WriteLine("Triple with subject <http://example.org/seven> should be missing - ASKing for it..."); //Try a SELECT query result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("Now we'll add the Triple back again"); //Try a INSERT DATA manager.Update("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}"); Console.WriteLine("Triple with subject <http://example.org/seven> should be restored - ASKing for it again..."); //Try a SELECT query result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("DESCRIBE things which are classes"); //Try a DESCRIBE result = manager.Query("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> DESCRIBE ?s WHERE {?s a rdfs:Class} LIMIT 1"); CheckQueryResult(result, false); Console.WriteLine("Another CONSTRUCT"); //Try a CONSTRUCT result = manager.Query("CONSTRUCT {?s ?p ?o} FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, false); Console.WriteLine("COUNT subjects"); //Try a SELECT using an aggregate function result = manager.Query("SELECT COUNT(?s) FROM <http://example.org/> WHERE {?s ?p ?o}"); CheckQueryResult(result, true); Console.WriteLine("AVG integer objects"); //Try another SELECT using an aggregate function result = manager.Query("SELECT AVG(?o) FROM <http://example.org/> WHERE {?s ?p ?o. FILTER(DATATYPE(?o) = <http://www.w3.org/2001/XMLSchema#integer>)}"); CheckQueryResult(result, true); Console.WriteLine("AVG decimal objects"); //Try yet another SELECT using an aggregate function result = manager.Query("SELECT AVG(?o) FROM <http://example.org/> WHERE {?s ?p ?o. FILTER(DATATYPE(?o) = <http://www.w3c.org/2001/XMLSchema#decimal>)}"); CheckQueryResult(result, true); } finally { if (manager != null) { manager.Dispose(); } } }