Ejemplo n.º 1
0
 public void TestCreateDataObjectContext()
 {
     var connectionString =
         new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\");
     IDataObjectContext context = new EmbeddedDataObjectContext(connectionString);
     Assert.IsNotNull(context);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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());            
        }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
        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"));
            }
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        public void TestAnonymousDataObjects()
        {
            // a resource with an anon data object which links to two other objects
            const string data = @"<http://www.np.com/objects/1> <http://www.np.com/types/p1> _:anon1 . 
                         _:anon1 <http://www.np.com/types/p2> <http://www.np.com/objects/2> . 
                         _:anon1 <http://www.np.com/types/p2> <http://www.np.com/objects/3> . ";

            var storeId = Guid.NewGuid().ToString();
            InitializeStore(storeId, data);

            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var store = context.OpenStore(storeId);

            var obj = store.GetDataObject("http://www.np.com/objects/1");


            var bnode = obj.GetPropertyValue("http://www.np.com/types/p1") as IDataObject;

            Assert.IsNotNull(bnode);
            Assert.IsTrue(bnode.Identity.StartsWith("http://www.brightstardb.com/.well-known/genid/"));
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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");
        }
Ejemplo n.º 12
0
 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);
 }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
 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());
 }
Ejemplo n.º 15
0
 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);
 }
Ejemplo n.º 16
0
 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);
 }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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());
        }
Ejemplo n.º 19
0
        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());                        
        }
Ejemplo n.º 20
0
        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());           
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        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));
            

        }
Ejemplo n.º 23
0
        public void TestRemoveProperty2()
        {
            var storeId = Guid.NewGuid().ToString();
            const string data = @"<http://www.np.com/objects/1> <http://www.np.com/types/p1> <http://www.np.com/objects/2> .
                  <http://www.np.com/objects/3> <http://www.np.com/types/p1> <http://www.np.com/objects/4> .";
            InitializeStore(storeId, data);
            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var store = context.OpenStore(storeId);
            var obj1 = store.GetDataObject("http://www.np.com/objects/1");
            var obj1Related = obj1.GetPropertyValues("http://www.np.com/types/p1").OfType<IDataObject>().ToList();
            var obj3 = store.GetDataObject("http://www.np.com/objects/3");
            var obj3Related = obj3.GetPropertyValues("http://www.np.com/types/p1").OfType<IDataObject>().ToList();
            Assert.AreEqual(1, obj1Related.Count());
            Assert.IsTrue(obj1Related.Any(r=>r.Identity.Equals("http://www.np.com/objects/2")));
            Assert.AreEqual(1, obj3Related.Count());
            Assert.IsTrue(obj3Related.Any(r => r.Identity.Equals("http://www.np.com/objects/4")));


            obj3.AddProperty("http://www.np.com/types/p1", store.MakeDataObject("http://www.np.com/objects/5"));
            obj1.RemovePropertiesOfType("http://www.np.com/types/p1");
            obj1Related = obj1.GetPropertyValues("http://www.np.com/types/p1").OfType<IDataObject>().ToList();
            obj3Related = obj3.GetPropertyValues("http://www.np.com/types/p1").OfType<IDataObject>().ToList();
            Assert.AreEqual(0, obj1Related.Count());
            Assert.AreEqual(2, obj3Related.Count());
            Assert.IsTrue(obj3Related.Any(r => r.Identity.Equals("http://www.np.com/objects/4")));
            Assert.IsTrue(obj3Related.Any(r => r.Identity.Equals("http://www.np.com/objects/5")));

            store.SaveChanges();

            obj1 = store.GetDataObject("http://www.np.com/objects/1");
            obj1Related = obj1.GetPropertyValues("http://www.np.com/types/p1").OfType<IDataObject>().ToList();
            obj3 = store.GetDataObject("http://www.np.com/objects/3");
            obj3Related = obj3.GetPropertyValues("http://www.np.com/types/p1").OfType<IDataObject>().ToList();
            Assert.AreEqual(0, obj1Related.Count());
            Assert.AreEqual(2, obj3Related.Count());
            Assert.IsTrue(obj3Related.Any(r => r.Identity.Equals("http://www.np.com/objects/4")));
            Assert.IsTrue(obj3Related.Any(r => r.Identity.Equals("http://www.np.com/objects/5")));

        }
Ejemplo n.º 24
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);                
        }
Ejemplo n.º 25
0
        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));

        }
Ejemplo n.º 26
0
        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());
            }
        }
Ejemplo n.º 27
0
        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());
            

        }
Ejemplo n.º 28
0
        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();
        }
Ejemplo n.º 29
0
        public void TestSpecialCharsInIdentities()
        {
            var importDir = Path.Combine(Configuration.StoreLocation, "import");
            if (!Directory.Exists(importDir))
            {
                Directory.CreateDirectory(importDir);
            }
            var testTarget = new FileInfo(importDir + Path.DirectorySeparatorChar + "persondata_en_subset.nt");
            if (!testTarget.Exists)
            {
                var testSource = new FileInfo("persondata_en_subset.nt");
                if (!testSource.Exists)
                {
                    Assert.Inconclusive("Could not locate test source file {0}. Test will not run", testSource.FullName);
                    return;
                }
                testSource.CopyTo(importDir + Path.DirectorySeparatorChar + "persondata_en_subset.nt");
            }

            var bc = BrightstarService.GetClient("type=http;endpoint=http://localhost:8090/brightstar");
            var storeName = Guid.NewGuid().ToString();
            bc.CreateStore(storeName);
            var jobInfo = bc.StartImport(storeName, "persondata_en_subset.nt", null, label:"Import Persondata");
            Assert.That(jobInfo.Label, Is.EqualTo("Import Persondata"));
            while (!(jobInfo.JobCompletedOk || jobInfo.JobCompletedWithErrors))
            {
                Thread.Sleep(1000);
                jobInfo = bc.GetJobInfo(storeName, jobInfo.JobId);
            }
            Assert.IsTrue(jobInfo.JobCompletedOk, "Import job failed");
            Assert.That(jobInfo.Label, Is.EqualTo("Import Persondata"));

            IDataObjectContext context = new EmbeddedDataObjectContext(new ConnectionString("type=embedded;storesDirectory=" + Configuration.StoreLocation + "\\"));
            var store = context.OpenStore(storeName);

            var test = store.BindDataObjectsWithSparql("SELECT ?p WHERE {?p a <http://xmlns.com/foaf/0.1/Person>} LIMIT 30").ToList();
            Assert.IsNotNull(test);

            foreach (var testDo in test)
            {
                Assert.IsNotNull(testDo);

                var propValues = testDo.GetPropertyValues("http://xmlns.com/foaf/0.1/name").OfType<PlainLiteral>();
                Assert.IsNotNull(propValues);
                Assert.IsTrue(propValues.Any());
            }
        }
Ejemplo n.º 30
0
        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();
        }