Example #1
0
        public void StorageVirtuosoBlankNodeDelete()
        {
            //First ensure data is present in the store
            VirtuosoManager manager = VirtuosoTest.GetConnection();

            try
            {
                manager.DeleteGraph("http://localhost/deleteBNodeTest");
                Graph  g = new Graph();
                Triple t = new Triple(g.CreateBlankNode(), g.CreateUriNode("rdf:type"), g.CreateUriNode(UriFactory.Create("http://example.org/object")));
                g.Assert(t);

                manager.UpdateGraph("http://localhost/deleteBNodeTest", t.AsEnumerable(), null);

                Object results = manager.Query("ASK WHERE { GRAPH <http://localhost/deleteBNodeTest> { ?s a <http://example.org/object> } }");
                if (results is SparqlResultSet)
                {
                    TestTools.ShowResults(results);
                    Assert.IsTrue(((SparqlResultSet)results).Result, "Expected a true result");

                    //Now we've ensured data is present we can first load the graph and then try to delete the given triple
                    Graph h = new Graph();
                    manager.LoadGraph(h, "http://localhost/deleteBNodeTest");
                    Assert.AreEqual(g, h, "Graphs should be equal");

                    //Then we can go ahead and delete the triples from this graph
                    manager.UpdateGraph("http://localhost/deleteBNodeTest", null, h.Triples);
                    Graph i = new Graph();
                    manager.LoadGraph(i, "http://localhost/deleteBNodeTest");
                    Assert.IsTrue(i.IsEmpty, "Graph should be empty");
                    Assert.AreNotEqual(h, i);
                    Assert.AreNotEqual(g, i);
                }
                else
                {
                    Assert.Fail("Didn't get a SPARQL Result Set as expected");
                }
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }
Example #2
0
        public void StorageVirtuosoDeleteGraph()
        {
            VirtuosoManager manager = VirtuosoTest.GetConnection();

            try
            {
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                //Load in our Test Graph
                TurtleParser ttlparser = new TurtleParser();
                Graph        g         = new Graph();
                ttlparser.Load(g, "resources\\Turtle.ttl");
                g.BaseUri = new Uri("http://example.org/deleteMe");

                Console.WriteLine();
                Console.WriteLine("Loaded Test Graph OK");
                Console.WriteLine("Test Graph contains:");

                Assert.IsFalse(g.IsEmpty, "Test Graph should be non-empty");

                foreach (Triple t in g.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                //Try to save to Virtuoso
                manager.SaveGraph(g);
                Console.WriteLine("Saved OK");
                Console.WriteLine();

                //Try to retrieve
                Graph h = new Graph();
                manager.LoadGraph(h, "http://example.org/deleteMe");

                Assert.IsFalse(h.IsEmpty, "Retrieved Graph should be non-empty");

                Console.WriteLine("Retrieved the Graph from Virtuoso OK");
                Console.WriteLine("Retrieved Graph contains:");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                //Try to delete
                manager.DeleteGraph("http://example.org/deleteMe");
                Graph i = new Graph();
                manager.LoadGraph(i, "http://example.org/deleteMe");

                Assert.IsTrue(i.IsEmpty, "Retrieved Graph should be empty as it should have been deleted from the Store");
            }
            finally
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
            }
        }