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 TestRepeatedSmallUnitsOfWork()
        {
            // ServicePointManager.DefaultConnectionLimit = 1000;
            var sp = ServicePointManager.FindServicePoint(new Uri("http://localhost:8090/brightstar"));

            sp.ConnectionLimit = 64;

            var st = DateTime.UtcNow;
            IDataObjectContext context = new RestDataObjectContext(new ConnectionString("type=rest;endpoint=http://localhost:8090/brightstar"));

            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 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 TestAddAndRemovePropertyPersisted()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);
            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, "kal");

            var propValue = p1.GetPropertyValue(ageType);

            Assert.AreEqual(propValue, "kal");

            store.SaveChanges();

            var p2 = store.GetDataObject(p1.Identity);

            Assert.That(p2.GetPropertyValue(ageType), Is.EqualTo("kal"));

            p2.RemovePropertiesOfType(ageType);

            Assert.That(p2.GetPropertyValue(ageType), Is.Null);
        }
        public void TestSavedDataObjectPropertyIsSameAfterSave()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);

            Assert.IsNotNull(context);
            var store = context.CreateStore(Guid.NewGuid().ToString());

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

            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 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);
        }
Beispiel #8
0
        private static IDataObjectStore OpenStore(ConnectionString connectionString, bool?enableOptimisticLocking = null,
                                                  string updateGraphUri = null, IEnumerable <string> datasetGraphUris = null, string versionGraphUri = null)
        {
            IDataObjectContext context;

            switch (connectionString.Type)
            {
            case ConnectionType.Embedded:
                context = new EmbeddedDataObjectContext(connectionString);
                break;

#if !SILVERLIGHT && !__MonoCS__
            case ConnectionType.Rest:
                context = new RestDataObjectContext(connectionString);
                break;
#endif
            case ConnectionType.DotNetRdf:
                context = new DotNetRdfDataObjectContext(connectionString);
                break;

            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,
                                     updateGraph: updateGraphUri,
                                     defaultDataSet: datasetGraphUris,
                                     versionTrackingGraph: versionGraphUri));
        }
        public void TestCreateDataObjectStore()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);

            Assert.IsNotNull(context);
            var store = context.CreateStore(Guid.NewGuid().ToString());

            Assert.IsNotNull(store);
        }
        public void TestCreateDataObjectWithString()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);

            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 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 TestLocalStateAfterSetProperty()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);
            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 TestRemoveProperty()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);
            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, "kal");

            var propValue = p1.GetPropertyValue(ageType);

            Assert.AreEqual(propValue, "kal");

            p1.RemovePropertiesOfType(ageType);

            Assert.That(p1.GetPropertyValue(ageType), Is.Null);
        }
        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());
        }
        public void TestSaveAndFetchDataObject()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);

            Assert.IsNotNull(context);
            var store = context.CreateStore(Guid.NewGuid().ToString());

            Assert.IsNotNull(store);
            var p1 = store.MakeDataObject();

            Assert.IsNotNull(p1);

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

            store.SaveChanges();

            var p2 = store.GetDataObject(p1.Identity);

            Assert.IsNotNull(p2);
            Assert.AreEqual(p1.Identity, p2.Identity);
        }
        public void TestGetProperty()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);
            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);
            var values = p2.GetPropertyValues(ageType).ToList();

            Assert.That(values.Count, Is.EqualTo(2));
            Assert.That(values, Contains.Item("graham"));
            Assert.That(values, Contains.Item("kal"));
        }
        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 TestSetPropertyDataObject()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);
            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);
            var v  = p3.GetPropertyValue(classificationType) as IDataObject;

            Assert.That(v, Is.Not.Null);
            Assert.That(v.Identity, Is.EqualTo(p2.Identity));
        }
        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"));
        }
        public void TestCreateDataObjectContext()
        {
            IDataObjectContext context = new RestDataObjectContext(_connectionString);

            Assert.IsNotNull(context);
        }