Example #1
0
 public void TestCreateDataObjectStore()
 {
     IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
     Assert.IsNotNull(context);
     var store = context.CreateStore(Guid.NewGuid().ToString());
     Assert.IsNotNull(store);
 }
 private static IDataObjectStore GetDataObjectStore(string storeName)
 {
     var context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
     if (!context.DoesStoreExist(storeName))
     {
         return context.CreateStore(storeName);
     }
     return context.OpenStore(storeName);
 }
        public void TestDataObjectFluentApi()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            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")
                                     );
            Assert.IsNotNull(gra);

            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", store.MakeListDataObject(new List<string> { "*****@*****.**"}));
            Assert.IsNotNull(kal);

            store.SaveChanges();
        }
        public void TestDataObjectDeleteObjectsUsedInProperties()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var storeId = Guid.NewGuid().ToString();
            var store = context.CreateStore(storeId);

            //Categories
            var categoryType = store.MakeDataObject("http://www.networkedplanet.com/schemas/category");

            var nosql = store.MakeDataObject("http://www.networkedplanet.com/categories/nosql");
            nosql.SetType(categoryType);
            var dotnet = store.MakeDataObject("http://www.networkedplanet.com/categories/.net");
            dotnet.SetType(categoryType);
            var rdf = store.MakeDataObject("http://www.networkedplanet.com/categories/rdf");
            rdf.SetType(categoryType);
            var topicmaps = store.MakeDataObject("http://www.networkedplanet.com/categories/topicmaps");
            topicmaps.SetType(categoryType);
            
            store.SaveChanges();
            store = context.OpenStore(storeId);

            
            var allCategories = store.BindDataObjectsWithSparql("SELECT ?cat WHERE {?cat a <http://www.networkedplanet.com/schemas/category>}").ToList();
            Assert.IsNotNull(allCategories);
            Assert.AreEqual(4, allCategories.Count);
            foreach (var c in allCategories)
            {
                c.Delete();
            }
            store.SaveChanges();
            store = context.OpenStore(storeId);

            allCategories = store.BindDataObjectsWithSparql("SELECT ?cat WHERE {?cat a <http://www.networkedplanet.com/schemas/category>}").ToList();
            Assert.IsNotNull(allCategories);
            Assert.AreEqual(0, allCategories.Count);  // all categories have been deleted


            nosql = store.GetDataObject("http://www.networkedplanet.com/categories/nosql");

            Assert.AreEqual(0, ((DataObject)nosql).Triples.Count());
            

        }
        public void TestDataObjectProperties()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var storeId = Guid.NewGuid().ToString();
            var store = context.CreateStore(storeId);
            
            //products
            var productType = store.MakeDataObject("http://www.networkedplanet.com/schemas/product");

            var brightstarDb = store.MakeDataObject("http://www.networkedplanet.com/products/brightstar");
            brightstarDb.SetType(productType);

            //properties
            var name = store.MakeDataObject("http://www.networkedplanet.com/schemas/product/name");
            brightstarDb.SetProperty(name, "Brightstar DB");

            store.SaveChanges();
            store = context.OpenStore(storeId);

            brightstarDb = store.GetDataObject("http://www.networkedplanet.com/products/brightstar");
            Assert.IsNotNull(brightstarDb);
            Assert.IsNotNull(brightstarDb.GetPropertyValue(name));

        }
        public void TestGetRelatedProxiesWithSafeCurie()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            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>().ToList();
            Assert.AreEqual(1, related.Count());

            var np = related.FirstOrDefault();
            Assert.IsNotNull(np);
            Assert.AreEqual(p1.Identity, np.Identity);
        }
        public void TestSetPropertyDataObject()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var store = context.CreateStore(Guid.NewGuid().ToString());

            var p1 = store.MakeDataObject();
            var p2 = store.MakeDataObject();
            Assert.IsNotNull(p1);
            var classificationType = store.MakeDataObject("http://www.np.com/classification");
            p1.SetProperty(classificationType, p1);
            p1.SetProperty(classificationType, p2);

            store.SaveChanges();

            var p3 = store.GetDataObject(p1.Identity);
            Assert.AreEqual(1, ((DataObject)p3).Triples.Count());                        
        }
        public void TestCurieObjectGetProperty()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var storeId = Guid.NewGuid().ToString();
            context.CreateStore(storeId);
            var store = context.OpenStore(storeId,
                                      new Dictionary<string, string> { { "np", "http://www.np.com/" } });

            var p1 = store.MakeDataObject();
            Assert.IsNotNull(p1);
            var labelType = store.MakeDataObject("np:label");
            p1.AddProperty(labelType, "graham");
            store.SaveChanges();

            var p2 = store.GetDataObject(p1.Identity);
            Assert.AreEqual(1, ((DataObject)p2).Triples.Count());
            var label = p2.GetPropertyValue(labelType);
            Assert.IsNotNull(label);
            Assert.AreEqual("graham", label);
        }
 public void TestCreateDataObject()
 {
     IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
     Assert.IsNotNull(context);
     var store = context.CreateStore(Guid.NewGuid().ToString());
     Assert.IsNotNull(store);
     var p1 = store.MakeDataObject();
     Assert.IsNotNull(p1);
     Assert.AreEqual(0, ((DataObject)p1).Triples.Count());
 }
 public void TestCreateDataObjectWithString()
 {
     IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
     Assert.IsNotNull(context);
     var store = context.CreateStore(Guid.NewGuid().ToString());
     Assert.IsNotNull(store);
     var p1 = store.MakeDataObject("http://www.networkedplanet.com/people/gra");
     Assert.IsNotNull(p1);
 }
 public void TestOpenDataObjectStoreWithNamespaceMappings()
 {
     IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
     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 TestRefreshSingleStoreWins()
        {
            IDataObjectContext context =
                new EmbeddedDataObjectContext(
                    new ConnectionString("type=embedded;optimisticLocking=true;storesDirectory=" +
                                         Configuration.StoreLocation + "\\"));
            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("http://example.org/alice");
            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)
            {
                // Expected
                store1.Refresh(RefreshMode.StoreWins, store1Alice);
                Assert.AreEqual(22, store1Alice.GetPropertyValue("http://example.org/age"));
                store1.SaveChanges();

                // Should have forced the update through
                var store3 = context.OpenStore(storeName);
                var store3Alice = store3.GetDataObject(store1Alice.Identity);
                Assert.AreEqual(22, store3Alice.GetPropertyValue("http://example.org/age"));
            }
        }
        public void TestPreconditionsFailedException()
        {
            IDataObjectContext context =
                new EmbeddedDataObjectContext(
                    new ConnectionString("type=embedded;optimisticLocking=true;storesDirectory=" +
                                         Configuration.StoreLocation + "\\"));
            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("http://example.org/alice");
            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 TestQueryGreaterThan()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var storeName = Guid.NewGuid().ToString();
            context.CreateStore(storeName);

            Dictionary<string, string> namespaceMappings;
            SetUpData(context, storeName, out namespaceMappings);

            var store = context.OpenStore(storeName, namespaceMappings);
            const string highPay = "SELECT ?p ?s WHERE { ?p a <http://example.org/schema/person> . ?p <http://example.org/schema/salary> ?s . FILTER (?s>50000)  }";

            var sparqlResult = store.ExecuteSparql(highPay);

            Assert.IsNotNull(sparqlResult);
            var result = sparqlResult.ResultDocument;
            Assert.AreEqual(5, result.SparqlResultRows().Count());
        }
        public void TestRemoveLiteralProperty()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var storeId = Guid.NewGuid().ToString();
            var store = context.CreateStore(storeId);

            var p1 = store.MakeDataObject();
            var p2 = store.MakeDataObject();

            var o1 = store.MakeDataObject();
            o1.AddProperty(p1, "graham");
            o1.AddProperty(p2, 23);

            var o2 = store.MakeDataObject();
            o2.AddProperty(p1, "bob");
            o2.AddProperty(p2, 24);

            o2.RemoveProperty(p1, "bob");

            store.SaveChanges();
            store = context.OpenStore(storeId);

            var o3 = store.GetDataObject(o1.Identity);
            var o4 = store.GetDataObject(o2.Identity);

            Assert.AreEqual("graham", o3.GetPropertyValue(p1));
            Assert.AreEqual(23, o3.GetPropertyValue(p2));
            Assert.AreEqual(24, o4.GetPropertyValue(p2));
            Assert.IsNull(o4.GetPropertyValue(p1));
        }
        public void TestDataObjectList()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            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 list = store.MakeListDataObject(new[] {"bob", "gra"});

            Assert.AreEqual("bob", list.GetPropertyValue("rdf:first"));
            Assert.IsInstanceOf(typeof(IDataObject), list.GetPropertyValue("rdf:rest"));
            var dataobj = list.GetPropertyValue("rdf:rest") as IDataObject;
            Assert.IsNotNull(dataobj);
            Assert.AreEqual("gra", dataobj.GetPropertyValue("rdf:first"));

            store.SaveChanges();
        }
        public void TestGetProperty()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var store = context.CreateStore(Guid.NewGuid().ToString());

            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();

            var p2 = store.GetDataObject(p1.Identity);
            Assert.AreEqual(2, ((DataObject)p2).Triples.Count());            
        }
 public void TestCreateDataObjectWithIdentity()
 {
     IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
     Assert.IsNotNull(context);
     var store = context.CreateStore(Guid.NewGuid().ToString());
     Assert.IsNotNull(store);
     var p1 = store.MakeDataObject("http://www.networkedplanet.com/staff/jen");
     Assert.IsNotNull(p1);
     Assert.AreEqual(0, ((DataObject)p1).Triples.Count());
     Assert.IsNotNull(p1.Identity);
     Assert.AreEqual("http://www.networkedplanet.com/staff/jen", p1.Identity);
 }
        public void TestCurieObjectGetPropertyPersisted()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var storeId = Guid.NewGuid().ToString();
            context.CreateStore(storeId);
            var store = context.OpenStore(storeId,
                                      new Dictionary<string, string> { { "np", "http://www.np.com/" } });

            var p1 = store.MakeDataObject();
            Assert.IsNotNull(p1);
            
            //object type
            var productType = store.MakeDataObject("http://www.networkedplanet.com/schemas/product");
            p1.SetType(productType);

            var labelType = store.MakeDataObject("np:label");
            p1.AddProperty(labelType, "graham");
            store.SaveChanges();

            store = context.OpenStore(storeId,
                                      new Dictionary<string, string> { { "np", "http://www.np.com/" } });

            var p2 = store.GetDataObject(p1.Identity);
            var label = p2.GetPropertyValue(labelType);
            Assert.IsNotNull(label);
            Assert.AreEqual("graham", label);

            var label2 = p2.GetPropertyValue("np:label");
            Assert.IsNotNull(label2);
            Assert.AreEqual("graham", label2);
        }
        public void TestCreateDataObjectWithCurie()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            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);
        }
        public void TestRemoveSpecificValueProperty()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            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);
            Assert.AreEqual(2, ((DataObject)p2).Triples.Count());

            var propValues = p2.GetPropertyValues("http://www.np.com/label").Cast<string>();
            Assert.IsNotNull(propValues);
            Assert.AreEqual(2, propValues.Count());

            // remove it
            p2.RemoveProperty(ageType, "kal");
            store.SaveChanges();

            Assert.AreEqual(1, ((DataObject)p2).Triples.Count());
            store = context.OpenStore(storeId);

            var p3 = store.GetDataObject(p1.Identity);
            Assert.AreEqual(1, ((DataObject)p3).Triples.Count());

            var label = p3.GetPropertyValue(ageType);
            Assert.IsNotNull(label);
            Assert.AreEqual("graham", label);
        }
        public void TestSavedDataObjectPropertyIsSameAfterSave()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            Assert.IsNotNull(context);
            var storeName = Guid.NewGuid().ToString();
            var store = context.CreateStore(storeName);
            Assert.IsNotNull(store);
            var p1 = store.MakeDataObject();
            Assert.IsNotNull(p1);

            var labelType = store.MakeDataObject("http://www.np.com/label"); 
            p1.SetProperty(labelType, "graham");

            store.SaveChanges();

            store = context.OpenStore(storeName);
            var p2 = store.GetDataObject(p1.Identity);
            Assert.IsNotNull(p2);
            Assert.AreEqual(p1.Identity, p2.Identity);

            var label = p2.GetPropertyValue(labelType);
            Assert.AreEqual("graham", label);
        }
        public void TestOptimisticLocking()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var storeId = Guid.NewGuid().ToString();
            var store = context.CreateStore(storeId, optimisticLockingEnabled: true);

            var p1 = store.MakeDataObject();
            var p2 = store.MakeDataObject();
            Assert.IsNotNull(p1);
            var classificationType = store.MakeDataObject("http://www.np.com/classification");
            p1.SetProperty(classificationType, p1);
            p1.SetProperty(classificationType, p2);

            store.SaveChanges();

            var p3 = store.GetDataObject(p1.Identity);
            Assert.AreEqual(2, ((DataObject)p3).Triples.Count());

            var store1 = context.OpenStore(storeId, optimisticLockingEnabled: true);
            var e1 = store1.GetDataObject(p1.Identity);

            var store2 = context.OpenStore(storeId, optimisticLockingEnabled: true);
            var e2 = store2.GetDataObject(p1.Identity);

            e1.SetProperty("http://www.np.com/types/label", "gra");

            store1.SaveChanges();

            e2.SetProperty("http://www.np.com/types/label", "gra");
            store2.SaveChanges();
        }
        public void TestLocalStateAfterSetProperty()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var store = context.CreateStore(Guid.NewGuid().ToString());

            var p1 = store.MakeDataObject();
            Assert.IsNotNull(p1);
            var ageType = store.MakeDataObject("http://www.np.com/label");
            p1.SetProperty(ageType, "graham");

            var propValue = p1.GetPropertyValue(ageType);

            Assert.AreEqual(propValue, "graham");
        }
        public void TestDataObjectPropertiesUsingMappings()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var storeId = Guid.NewGuid().ToString();
            context.CreateStore(storeId);
            var store = context.OpenStore(storeId, new Dictionary<string, string> { { "products", "http://www.networkedplanet.com/products/" } });

            //products
            var productType = store.MakeDataObject("http://www.networkedplanet.com/schemas/product");

            var brightstarDb = store.MakeDataObject("products:brightstar");
            brightstarDb.SetType(productType);

            //properties
            var name = store.MakeDataObject("http://www.networkedplanet.com/schemas/product/name");
            brightstarDb.SetProperty(name, "Brightstar DB");

            store.SaveChanges();
            store = context.OpenStore(storeId, new Dictionary<string, string> { { "products", "http://www.networkedplanet.com/products/" }});

            var getObjectByFullIdentity = store.GetDataObject("http://www.networkedplanet.com/products/brightstar");
            Assert.AreEqual(2, ((DataObject)getObjectByFullIdentity).Triples.Count());
            Assert.IsNotNull(getObjectByFullIdentity.GetPropertyValue(name), "Name property is null");
            Assert.AreEqual("Brightstar DB", getObjectByFullIdentity.GetPropertyValue(name));

            var getObjectByCurie = store.GetDataObject("products:brightstar");
            Assert.AreEqual(2, ((DataObject)getObjectByCurie).Triples.Count());
            Assert.IsNotNull(getObjectByCurie.GetPropertyValue(name), "Name property is null");
            Assert.AreEqual("Brightstar DB", getObjectByCurie.GetPropertyValue(name));
            

        }
        public void TestSetSamePropertyResultsInOnlyOneProperty()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var store = context.CreateStore(Guid.NewGuid().ToString());

            var p1 = store.MakeDataObject();
            Assert.IsNotNull(p1);
            var labelType = store.MakeDataObject("http://www.np.com/label");
            p1.SetProperty(labelType, "graham");
            p1.SetProperty(labelType, "kal");

            var propValue = p1.GetPropertyValue(labelType);

            Assert.AreEqual(propValue, "kal");

            Assert.AreEqual(1, ((DataObject)p1).Triples.Count());
            Assert.AreEqual(1, ((EmbeddedDataObjectStore)store).AddTriples.Count());
        }
Example #27
0
        public void TestRepeatedSmallUnitsOfWork()
        {
            var st = DateTime.UtcNow;
            // for the embedded stores the context needs to be common.
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + BrightstarDB.Configuration.StoreLocation + "\\"));
            Assert.IsNotNull(context);

            var storeId = Guid.NewGuid().ToString();
            context.CreateStore(storeId);

            var tasks = new List<Task>();

            for (var i=0;i < 10;i++)
            {
                var t = new Task(() => ExecuteSmallUnitOfWork(context, storeId));                
                tasks.Add(t);
                t.Start();
            }

            Task.WaitAll(tasks.ToArray());
            var et = DateTime.UtcNow;
            var duration = et.Subtract(st).TotalMilliseconds;
            Console.WriteLine(duration);                
        }
        public void TestAddAndRemovePropertyPersisted()
        {
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var storeName = Guid.NewGuid().ToString();
            var store = context.CreateStore(storeName);

            var p1 = store.MakeDataObject();
            Assert.IsNotNull(p1);
            var ageType = store.MakeDataObject("http://www.np.com/label");
            p1.SetProperty(ageType, "kal");

            var propValue = p1.GetPropertyValue(ageType);
            Assert.AreEqual(propValue, "kal");

            store.SaveChanges();
            store = context.OpenStore(storeName);

            var p2 = store.GetDataObject(p1.Identity);
            Assert.AreEqual(1, ((DataObject)p2).Triples.Count());

            p2.RemovePropertiesOfType(ageType);

            Assert.AreEqual(0, ((DataObject)p2).Triples.Count());
            Assert.AreEqual(0, ((EmbeddedDataObjectStore)store).AddTriples.Count());           
        }