public void TestDeleteObjectFromGraph() { IDataObjectContext context = MakeDataObjectContext(); var storeName = "TestDeleteObjectFromGraph_" + DateTime.Now.Ticks; var prefixes = new Dictionary <string, string> { { "foaf", "http://xmlns.com/foaf/0.1/" }, { "resource", "http://example.org/resource/" } }; // Create an object with some properties in the default graph var store1 = context.CreateStore(storeName, prefixes); var baseDataObject = store1.MakeDataObject("resource:Alice"); baseDataObject.SetProperty("foaf:name", "Alice Test"); baseDataObject.SetProperty("foaf:mbox", "*****@*****.**"); store1.SaveChanges(); // Add a new property in a separate graph var graph1 = "http://example.org/graphs/graph1"; var store2 = context.OpenStore(storeName, prefixes, updateGraph: graph1); var updateDataObject = store2.GetDataObject("resource:Alice"); Assert.IsNotNull(updateDataObject); updateDataObject.SetProperty("foaf:mbox_sha1", "ABCD1234"); store2.SaveChanges(); // Check access to properties in both graphs var store3 = context.OpenStore(storeName, prefixes, updateGraph: graph1, defaultDataSet: new [] { graph1, Constants.DefaultGraphUri }); updateDataObject = store3.GetDataObject("resource:Alice"); Assert.IsNotNull(updateDataObject); Assert.IsNotNull(updateDataObject.GetPropertyValue("foaf:mbox_sha1")); Assert.IsNotNull(updateDataObject.GetPropertyValue("foaf:name")); Assert.IsNotNull(updateDataObject.GetPropertyValue("foaf:mbox")); Assert.AreEqual("ABCD1234", updateDataObject.GetPropertyValue("foaf:mbox_sha1").ToString()); Assert.AreEqual("Alice Test", updateDataObject.GetPropertyValue("foaf:name").ToString()); Assert.AreEqual("*****@*****.**", updateDataObject.GetPropertyValue("foaf:mbox").ToString()); var store4 = context.OpenStore(storeName, prefixes, updateGraph: graph1, defaultDataSet: new string[] { graph1 }); updateDataObject = store4.GetDataObject("resource:Alice"); Assert.IsNotNull(updateDataObject); updateDataObject.Delete(); store4.SaveChanges(); // Check that the object and properties are still accessible through the default graph var store5 = context.OpenStore(storeName, prefixes, updateGraph: graph1, defaultDataSet: new[] { graph1, Constants.DefaultGraphUri }); updateDataObject = store5.GetDataObject("resource:Alice"); Assert.IsNotNull(updateDataObject); Assert.IsNotNull(updateDataObject.GetPropertyValue("foaf:mbox")); Assert.IsNotNull(updateDataObject.GetPropertyValue("foaf:name")); Assert.AreEqual("Alice Test", updateDataObject.GetPropertyValue("foaf:name").ToString()); Assert.AreEqual("*****@*****.**", updateDataObject.GetPropertyValue("foaf:mbox").ToString()); }
public void SetUp() { var storeName = "BasicDataObjectTests_" + DateTime.Now.Ticks; if (_isPersistent) { var client = BrightstarService.GetClient(_connectionString); if (client.DoesStoreExist(storeName)) { client.DeleteStore(storeName); Thread.Sleep(500); } client.CreateStore(storeName); } _context = BrightstarService.GetDataObjectContext(_connectionString); _store = _context.OpenStore(storeName, NamespaceMappings); }
public void SetUp() { var storeName = "BasicDataObjectTests_" + DateTime.Now.Ticks; var connectionString = new ConnectionString(String.Format(_connectionString, Path.GetFullPath(Configuration.DataLocation), Path.GetFullPath(Configuration.StoreLocation), storeName)); if (_isPersistent) { var client = BrightstarService.GetClient(connectionString); if (client.DoesStoreExist(connectionString.StoreName)) { client.DeleteStore(connectionString.StoreName); Thread.Sleep(500); } client.CreateStore(connectionString.StoreName); } _context = BrightstarService.GetDataObjectContext(connectionString); _store = _context.OpenStore(connectionString.StoreName, NamespaceMappings); }
public SimpleContextTests() { var connectionString = new ConnectionString("type=embedded;storesDirectory=" + TestConfiguration.StoreLocation); _dataObjectContext = new EmbeddedDataObjectContext(connectionString); }
private static void ExecuteSmallUnitOfWork(IDataObjectContext context, string storeId) { var contextName = Guid.NewGuid(); var rnd = new Random(); try { for (int i = 0; i < 100; i++) { var DataObjectStore = context.OpenStore(storeId); // create 50 themes var themes = new IDataObject[50]; for (int t = 0; t < 50; t++) { var theme = DataObjectStore.MakeDataObject("http://www.np.com/" + contextName + "/themes/" + t); theme.SetProperty("http://www.np.com/types/label", contextName + "_" + t); theme.SetProperty("http://www.np.com/types/description", contextName + "_desc_" + t); themes[t] = theme; } // 200 documents var docs = new IDataObject[250]; for (int t = 0; t < 250; t++) { var doc = DataObjectStore.MakeDataObject("http://www.np.com/" + contextName + "/docs/" + t); doc.SetProperty("http://www.np.com/types/label", contextName + "_" + t); doc.SetProperty("http://www.np.com/types/description", contextName + "_desc_" + t); doc.SetProperty("http://www.np.com/types/created", DateTime.UtcNow); doc.SetProperty("http://www.np.com/types/published", DateTime.UtcNow); doc.SetProperty("http://www.np.com/types/author", "Graham " + contextName + t); doc.AddProperty("http://www.np.com/types/classification", themes[rnd.Next(49)]); doc.AddProperty("http://www.np.com/types/classification", themes[rnd.Next(49)]); doc.AddProperty("http://www.np.com/types/classification", themes[rnd.Next(49)]); docs[t] = doc; } // 200 emails var emails = new IDataObject[200]; for (int t = 0; t < 200; t++) { var email = DataObjectStore.MakeDataObject("http://www.np.com/" + contextName + "/emails/" + t); email.SetProperty("http://www.np.com/types/label", contextName + "_" + t); email.SetProperty("http://www.np.com/types/description", contextName + "_desc_" + t); email.SetProperty("http://www.np.com/types/written", DateTime.UtcNow); email.SetProperty("http://www.np.com/types/received", DateTime.UtcNow); email.SetProperty("http://www.np.com/types/responded", DateTime.UtcNow); email.AddProperty("http://www.np.com/types/classification", themes[rnd.Next(49)]); email.AddProperty("http://www.np.com/types/classification", themes[rnd.Next(49)]); email.AddProperty("http://www.np.com/types/classification", themes[rnd.Next(49)]); emails[t] = email; } var st = DateTime.UtcNow; DataObjectStore.SaveChanges(); var et = DateTime.UtcNow; var duration = et.Subtract(st).TotalMilliseconds; Console.WriteLine(duration); } } catch (Exception ex) { Console.WriteLine("Exception " + ex); } Console.WriteLine("Finished " + contextName); }
private void SetUpData(IDataObjectContext context, string storeName, out Dictionary<string,string> namespaceMappings) { namespaceMappings = new Dictionary<string, string> { {"people", "http://example.org/people/"}, {"skills", "http://example.org/skills/"}, {"schema", "http://example.org/schema/"} }; var store = context.OpenStore(storeName, namespaceMappings); var personType = store.MakeDataObject("schema:person"); var salary = store.MakeDataObject("schema:salary"); //add 10 people // salaries = 10000, 20000, ... 100000 for(var i = 0; i<10; i++) { var p = store.MakeDataObject("people:personname" + i); p.SetType(personType); var pay = (i + 1)*10000; p.SetProperty(salary, pay); } store.SaveChanges(); store = context.OpenStore(storeName, namespaceMappings); const string getpeopleQuery = "SELECT ?p WHERE { ?p a <http://example.org/schema/person> }"; var people = store.BindDataObjectsWithSparql(getpeopleQuery); Assert.AreEqual(10, people.Count()); }
public void SetUp() { var connectionString = new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation); _dataObjectContext = new EmbeddedDataObjectContext(connectionString); }
/// <summary> /// Creates a new context with a specific IDataObjectContext /// </summary> /// <param name="context">The underlying context that this dynamic context will use.</param> public BrightstarDynamicContext(IDataObjectContext context) { _context = context; }
public DataObjectStoreTestsBase() { var connectionString = new ConnectionString("type=embedded;storesDirectory=" + TestConfiguration.StoreLocation); _dataObjectContext = new EmbeddedDataObjectContext(connectionString); }
public void TestUpdateGraphTargetting() { IDataObjectContext context = MakeDataObjectContext(); var storeName = "TestUpdateGraphTargetting_" + DateTime.Now.Ticks; var prefixes = new Dictionary <string, string> { { "foaf", "http://xmlns.com/foaf/0.1/" }, { "resource", "http://example.org/resource/" } }; // Create a resource with some initial properties in the default graph var store1 = context.CreateStore(storeName, prefixes); var personType = store1.MakeDataObject("foaf:Person"); var firstName = store1.MakeDataObject("foaf:givenName"); var surname = store1.MakeDataObject("foaf:surname"); var fullname = store1.MakeDataObject("foaf:name"); const string inferredGraphUri = "http://example.org/graphs/inferred"; var johnSmith = store1.MakeDataObject("resource:John_Smith"); johnSmith.SetType(personType); johnSmith.SetProperty(firstName, "John"); johnSmith.SetProperty(surname, "Smith"); store1.SaveChanges(); // Create a context that updates a new "inferred" graph and add a property var store2 = context.OpenStore(storeName, prefixes, updateGraph: inferredGraphUri, defaultDataSet: new[] { Constants.DefaultGraphUri }); johnSmith = store2.GetDataObject("resource:John_Smith"); fullname = store2.GetDataObject("foaf:name"); Assert.IsNotNull(johnSmith, "Could not find base data object in store2"); var gn = johnSmith.GetPropertyValue("foaf:givenName") as string; Assert.IsNotNull(gn, "Could not find foaf:givenName property of base data object in store2"); var sn = johnSmith.GetPropertyValue("foaf:surname") as string; Assert.IsNotNull(sn, "Could not find foaf:surname property of base data object in store2"); johnSmith.SetProperty(fullname, gn + " " + sn); store2.SaveChanges(); // Create a context that reads from both the default and inferred graphs var store3 = context.OpenStore(storeName, prefixes, updateGraph: Constants.DefaultGraphUri, defaultDataSet: new string[] { Constants.DefaultGraphUri, inferredGraphUri }); johnSmith = store3.GetDataObject("resource:John_Smith"); Assert.IsNotNull(johnSmith, "Could not find base data object in store3"); var fn = johnSmith.GetPropertyValue("foaf:name"); Assert.IsNotNull(fn, "Could not find name property on base data object in store3"); Assert.AreEqual("John Smith", fn); // Create a context that reads only from the inferred graph var store4 = context.OpenStore(storeName, prefixes, updateGraph: inferredGraphUri, defaultDataSet: new string[] { inferredGraphUri }); johnSmith = store4.GetDataObject("resource:John_Smith"); Assert.IsNotNull(johnSmith); fn = johnSmith.GetPropertyValue("foaf:name"); Assert.IsNotNull(fn); // foaf:givenName and foaf:surname should not be found gn = johnSmith.GetPropertyValue("foaf:givenName") as string; Assert.IsNull(gn); sn = johnSmith.GetPropertyValue("foaf:surname") as string; Assert.IsNull(sn); // Verify the quads are as expected. var client = MakeRdfClient(); var query = @"SELECT ?p ?o ?g FROM NAMED <" + Constants.DefaultGraphUri + "> " + " FROM NAMED <" + inferredGraphUri + "> WHERE {" + " GRAPH ?g { <http://example.org/resource/John_Smith> ?p ?o } }"; var resultStream = client.ExecuteQuery(storeName, query); var results = XDocument.Load(resultStream); foreach (var row in results.SparqlResultRows()) { var p = row.GetColumnValue("p").ToString(); var g = row.GetColumnValue("g").ToString(); if (p.Equals("http://xmlns.com/foaf/0.1/givenName") || p.Equals("http://xmlns.com/foaf/0.1/surname") || p.Equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")) { Assert.AreEqual(Constants.DefaultGraphUri, g, "Triple with predicate {0} is not in the expected graph", p); } else if (p.Equals("http://xmlns.com/foaf/0.1/name")) { Assert.AreEqual(inferredGraphUri, g, "Triple with predicate {0} is not in the expected graph", p); } else { Assert.Fail("Found a statement with an unexpected predicate: {0}", p); } } }