Esempio n. 1
0
        public void TestGetProperties()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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);

            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());
        }
Esempio n. 2
0
        public void TestAddAndRemovePropertyPersisted()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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.AreEqual(1, ((DataObject)p2).Triples.Count());

            p2.RemovePropertiesOfType(ageType);

            Assert.AreEqual(0, ((DataObject)p2).Triples.Count());
            Assert.AreEqual(0, ((RemoteDataObjectStore)store).AddTriples.Count());
        }
Esempio n. 3
0
        public void TestGetRelatedProxiesWithSafeCurie()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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);
        }
Esempio n. 4
0
        public void TestPreconditionsFailedException()
        {
            IDataObjectContext context =
                new HttpDataObjectContext(
                    new ConnectionString("type=http;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());
            }
        }
Esempio n. 5
0
        public void TestSavedDataObjectPropertyIsSameAfterSave()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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);
        }
Esempio n. 6
0
        public void TestDataObjectFluids()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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();
        }
Esempio n. 7
0
        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 HttpDataObjectContext(new ConnectionString("type=http;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);
        }
Esempio n. 8
0
        public void TestCreateDataObjectStore()
        {
            IDataObjectContext context = new HttpDataObjectContext(_connectionString);

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

            Assert.IsNotNull(store);
        }
Esempio n. 9
0
        public void TestCreateDataObjectWithString()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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);
        }
Esempio n. 10
0
        public void TestOpenDataObjectStoreWithNamespaceMappings()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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);
        }
Esempio n. 11
0
        public void TestLocalStateAfterSetProperty()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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");
        }
Esempio n. 12
0
        public void TestCreateDataObjectWithCurie()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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());
        }
Esempio n. 13
0
        public void TestSetSamePropertyResultsInOnlyOneProperty()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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");
            p1.SetProperty(ageType, "kal");

            var propValue = p1.GetPropertyValue(ageType);

            Assert.AreEqual(propValue, "kal");

            Assert.AreEqual(1, ((DataObject)p1).Triples.Count());
            Assert.AreEqual(1, ((RemoteDataObjectStore)store).AddTriples.Count());
        }
Esempio n. 14
0
        public void TestSetPropertyDataObject()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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);

            Assert.AreEqual(1, ((DataObject)p3).Triples.Count());
        }
Esempio n. 15
0
        public void TestSaveAndFetchDataObject()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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);
        }
        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));
        }
Esempio n. 17
0
        public void TestSetSamePropertyResultsInOnlyOnePropertyAfterSave()
        {
            IDataObjectContext context = new HttpDataObjectContext(_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);

            Assert.AreEqual(1, ((DataObject)p2).Triples.Count());
        }
Esempio n. 18
0
        public void TestCreateDataObjectContext()
        {
            IDataObjectContext context = new HttpDataObjectContext(_connectionString);

            Assert.IsNotNull(context);
        }