public void TestGetRelatedProxiesWithSafeCurie() { IDataObjectContext context = new RestDataObjectContext(_connectionString); var storeId = Guid.NewGuid().ToString(); var store = context.CreateStore(storeId, new Dictionary <string, string> { { "ont", "http://www.networkedplanet.com/types/" }, { "rdfs", "http://www.w3.org/2000/01/rdf-schema#" }, { "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" } }); var p1 = store.MakeDataObject().AddProperty("rdfs:label", "networkedplanet"); var p2 = store.MakeDataObject().AddProperty("rdfs:label", "gra").AddProperty("ont:worksfor", p1); store.SaveChanges(); store = context.OpenStore(storeId, new Dictionary <string, string> { { "ont", "http://www.networkedplanet.com/types/" }, { "rdfs", "http://www.w3.org/2000/01/rdf-schema#" }, { "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" } }); var p3 = store.GetDataObject(p2.Identity); Assert.IsNotNull(p3); var related = p3.GetPropertyValues("[ont:worksfor]").OfType <IDataObject>(); Assert.AreEqual(1, related.Count()); var np = related.FirstOrDefault(); Assert.IsNotNull(np); Assert.AreEqual(p1.Identity, np.Identity); }
public void TestPreconditionsFailedException() { IDataObjectContext context = new RestDataObjectContext( new ConnectionString("type=rest;optimisticLocking=true;endpoint=http://localhost:8090/brightstar")); var storeName = Guid.NewGuid().ToString(); var store1 = context.CreateStore(storeName); var store1Alice = store1.MakeDataObject("http://example.org/alice"); store1Alice.SetProperty("http://example.org/age", 21); store1.SaveChanges(); var store2 = context.OpenStore(storeName); var store2Alice = store2.GetDataObject(store1Alice.Identity); Assert.AreEqual(21, store2Alice.GetPropertyValue("http://example.org/age")); store2Alice.SetProperty("http://example.org/age", 22); store2.SaveChanges(); store1Alice.SetProperty("http://example.org/age", 20); try { store1.SaveChanges(); Assert.Fail("Expected a TransactionPreconditionsFailed exception"); } catch (TransactionPreconditionsFailedException ex) { // Expected Assert.AreEqual(1, ex.InvalidSubjects.Count()); Assert.AreEqual("http://example.org/alice", ex.InvalidSubjects.First()); } }
public void TestGetProperties() { IDataObjectContext context = new RestDataObjectContext(_connectionString); var storeId = Guid.NewGuid().ToString(); var store = context.CreateStore(storeId); var p1 = store.MakeDataObject(); Assert.IsNotNull(p1); var ageType = store.MakeDataObject("http://www.np.com/label"); p1.AddProperty(ageType, "graham"); p1.AddProperty(ageType, "kal"); store.SaveChanges(); store = context.OpenStore(storeId); var p2 = store.GetDataObject(p1.Identity); var propValues = p2.GetPropertyValues("http://www.np.com/label").Cast <string>(); Assert.IsNotNull(propValues); Assert.AreEqual(2, propValues.Count()); }
public void TestDataObjectFluids() { IDataObjectContext context = new RestDataObjectContext(_connectionString); var storeId = Guid.NewGuid().ToString(); context.CreateStore(storeId); var store = context.OpenStore(storeId, new Dictionary <string, string>() { { "ont", "http://www.networkedplanet.com/types/" }, { "rdfs", "http://www.w3.org/2000/01/rdf-schema#" }, { "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" } }); var gra = store.MakeDataObject() .SetType(store.MakeDataObject("http://www.networkedplanet.com/types/person")) .SetProperty(store.MakeDataObject("http://www.networkedplanet.com/types/age"), 23) .SetProperty(store.MakeDataObject("http://www.networkedplanet.com/types/worksfor"), store.MakeDataObject("http://www.networkedplanet.com/companies/np") ); var kal = store.MakeDataObject() .SetType(store.MakeDataObject("http://www.networkedplanet.com/types/person")) .SetProperty("ont:age", 23) .SetProperty("rdfs:label", "Kal") .SetProperty("ont:worksfor", store.MakeDataObject("http://www.networkedplanet.com/companies/np") .SetProperty("rdfs:label", "Networked Planet") ) .SetProperty("ont:email", new List <string> { "*****@*****.**" }); store.SaveChanges(); }
public void TestOpenDataObjectStore() { IDataObjectContext context = new RestDataObjectContext(_connectionString); Assert.IsNotNull(context); var storeName = Guid.NewGuid().ToString(); var store = context.CreateStore(storeName); Assert.IsNotNull(store); store = context.OpenStore(storeName); Assert.IsNotNull(store); }
public void TestOpenDataObjectStoreWithNamespaceMappings() { IDataObjectContext context = new RestDataObjectContext(_connectionString); Assert.IsNotNull(context); var storeName = Guid.NewGuid().ToString(); var store = context.CreateStore(storeName); Assert.IsNotNull(store); store = context.OpenStore(storeName, new Dictionary <string, string>() { { "people", "http://www.networkedplanet.com/people/" } }); Assert.IsNotNull(store); }
public void TestCreateDataObjectWithCurie() { IDataObjectContext context = new RestDataObjectContext(_connectionString); Assert.IsNotNull(context); var storeName = Guid.NewGuid().ToString(); var store = context.CreateStore(storeName); Assert.IsNotNull(store); store = context.OpenStore(storeName, new Dictionary <string, string>() { { "people", "http://www.networkedplanet.com/people/" } }); Assert.IsNotNull(store); var p1 = store.MakeDataObject("people:gra"); Assert.IsNotNull(p1); Assert.AreEqual("http://www.networkedplanet.com/people/gra", p1.Identity.ToString()); }
private static IDataObjectStore OpenStore(ConnectionString connectionString, bool?enableOptimisticLocking = null) { IDataObjectContext context; switch (connectionString.Type) { #if !REST_CLIENT case ConnectionType.Embedded: context = new EmbeddedDataObjectContext(connectionString); break; #endif #if !SILVERLIGHT #if !REST_CLIENT case ConnectionType.Http: context = new HttpDataObjectContext(connectionString); break; case ConnectionType.Tcp: context = new NetTcpDataObjectContext(connectionString); break; case ConnectionType.NamedPipe: context = new NamedPipeDataObjectContext(connectionString); break; #endif case ConnectionType.Rest: context = new RestDataObjectContext(connectionString); break; #endif default: throw new BrightstarClientException("Unable to create valid context with connection string " + connectionString.Value); } return(context.OpenStore(connectionString.StoreName, optimisticLockingEnabled: enableOptimisticLocking.HasValue ? enableOptimisticLocking.Value : connectionString.OptimisticLocking)); }
public void TestSetSamePropertyResultsInOnlyOnePropertyAfterSave() { IDataObjectContext context = new RestDataObjectContext(_connectionString); var storeId = Guid.NewGuid().ToString(); var store = context.CreateStore(storeId); var p1 = store.MakeDataObject(); Assert.IsNotNull(p1); var ageType = store.MakeDataObject("http://www.np.com/label"); p1.SetProperty(ageType, "graham"); p1.SetProperty(ageType, "kal"); store.SaveChanges(); store = context.OpenStore(storeId); var p2 = store.GetDataObject(p1.Identity); var values = p2.GetPropertyValues(ageType); Assert.That(values.Count(), Is.EqualTo(1)); Assert.That(values.First(), Is.EqualTo("kal")); }