コード例 #1
0
        public void SetRelationshipProperty2()
        {
            var now = DateTime.Now;

            var p = new Properties();

            p.SetProperty("name", "jack");
            p.SetProperty("age", 12);
            p.SetProperty("date", now);


            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

            var rel = Relationship.CreateRelationship(node1, node2, "like");

            var cypher = new Cypher();

            cypher.Start(s => s.Relationship("rel1", rel.Id));
            cypher.Set(s => s.Relationship("rel1", p));
            cypher.Return(r => r.Relationship("rel1"));

            var results = cypher.Execute();

            var r1 = results.First().Field <Relationship>("rel1");

            Assert.IsTrue(r1.GetProperty <string>("name") == "jack");
            Assert.IsTrue(r1.GetProperty <int>("age") == 12);
            Assert.IsTrue(r1.GetProperty <DateTime>("date") == now);
        }
コード例 #2
0
        public void DeleteSingleRelationshipProperty()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();


            var now = DateTime.Now;

            var p = new Properties();

            p.SetProperty("name", "jack");
            p.SetProperty("age", 12);
            p.SetProperty("date", now);

            var rel1 = Relationship.CreateRelationship(node1, node2, "like", p);

            var cypher = new Cypher();

            cypher.Start(s => s.Relationship("rel1", rel1.Id));
            cypher.Delete(d => d.Relationship("rel1", "age"));

            cypher.Execute();

            var r1 = Relationship.GetRelationship(rel1.Id);

            Assert.IsTrue(r1.GetPropertyOrOther("age", -1) == -1);

            Assert.IsTrue(r1.GetProperty <string>("name") == "jack");
            Assert.IsTrue(r1.GetProperty <DateTime>("date") == now);
        }
コード例 #3
0
        public void DeleteMultipleRelationshipProperties2()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

            var now = DateTime.Now;

            var p = new Properties();

            p.SetProperty("name", "jack");
            p.SetProperty("age", 12);
            p.SetProperty("date", now);

            var rel1 = Relationship.CreateRelationship(node1, node2, "like", p);

            var cypher = new Cypher();

            cypher.Start(s => s.Relationship("rel1", rel1.Id));
            cypher.Delete(d => d.Relationship("rel1", new List <string> {
                "age", "name"
            }));
            cypher.Return(r => r.Relationship("rel1"));

            var results = cypher.Execute();

            var r1 = Relationship.GetRelationship(rel1.Id);

            Assert.IsTrue(r1 == results.First().Field <Relationship>("rel1"));

            Assert.IsTrue(r1.GetPropertyOrOther("age", -1) == -1);
            Assert.IsTrue(r1.GetPropertyOrOther("name", "deleted") == "deleted");

            Assert.IsTrue(r1.GetProperty <DateTime>("date") == now);
        }
コード例 #4
0
        public void RemoveRelationshipProperties()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

            var batch = new BatchStore();

            var batchRelationship = Relationship.CreateRelationship(node1, node2, "likes", null, batch);

            batchRelationship.Properties.SetProperty("name", "joe");
            batchRelationship.Properties.SetProperty("age", 12);

            batchRelationship.SaveProperties();

            batchRelationship.Properties.RemoveProperty("age");

            batchRelationship.SaveProperties();

            Assert.IsTrue(batch.Execute());

            var restRelationship = batch.GetGraphObject(batchRelationship);

            Assert.IsTrue(restRelationship.Properties.GetProperty <string>("name") == "joe");
            Assert.IsTrue(restRelationship.Properties.GetPropertyOrDefault <int>("age") == 0);
        }
コード例 #5
0
        public void CreateRelationshipWithProperties2()
        {
            var batch      = new BatchStore();
            var batchNode1 = Node.CreateNode(batch);
            var batchNode2 = Node.CreateNode(batch);

            var prop = new Properties();

            var since = DateTime.Now;

            prop.SetProperty("since", since);
            prop.SetProperty("approved", true);

            var batchRelationship = Relationship.CreateRelationship(batchNode1, batchNode2, "friend", prop, batch);

            Assert.IsTrue(batch.Execute());

            var restNode1        = batch.GetGraphObject(batchNode1);
            var restNode2        = batch.GetGraphObject(batchNode2);
            var restRelationship = batch.GetGraphObject(batchRelationship);

            Assert.IsTrue(restNode1.Id > 0);
            Assert.IsTrue(restNode2.Id > 0 && restNode1.Id != restNode2.Id);

            Assert.IsTrue(restRelationship.StartNode == restNode1);
            Assert.IsTrue(restRelationship.EndNode == restNode2);
            Assert.IsTrue(restRelationship.Type == "friend");

            Assert.IsTrue(restRelationship.Properties.GetProperty <DateTime>("since") == since);
            Assert.IsTrue(restRelationship.Properties.GetProperty <bool>("approved"));
        }
コード例 #6
0
        public void GetRelationships4()
        {
            var node1         = Node.CreateNode();
            var node2         = Node.CreateNode();
            var node3         = Node.CreateNode();
            var relationship1 = Relationship.CreateRelationship(node1, node2, "a");
            var relationship2 = Relationship.CreateRelationship(node1, node3, "b");

            var relationships1 = node1.GetRelationships("a");

            Assert.IsNotNull(relationships1);
            Assert.IsTrue(relationships1.Count() == 1);
            Assert.IsTrue(relationships1.First().Equals(relationship1));

            var relationships2 = node1.GetRelationships("b");

            Assert.IsNotNull(relationships2);
            Assert.IsTrue(relationships2.Count() == 1);
            Assert.IsTrue(relationships2.First().Equals(relationship2));

            var relationships3 = node3.GetRelationships("a");

            Assert.IsNotNull(relationships3);
            Assert.IsTrue(relationships3.Count() == 0);
        }
コード例 #7
0
        public void CreateRelationshipNoProperties2()
        {
            var batch      = new BatchStore();
            var batchNode1 = Node.CreateNode(batch);
            var batchNode2 = Node.CreateNode(batch);

            var batchRelationship = Relationship.CreateRelationship(batchNode1, batchNode2, "friend", null, batch);

            Assert.IsTrue(batch.Execute());

            var restNode1        = batch.GetGraphObject(batchNode1);
            var restNode2        = batch.GetGraphObject(batchNode2);
            var restRelationship = batch.GetGraphObject(batchRelationship);

            Assert.IsTrue(restNode1.Id > 0);
            Assert.IsTrue(restNode2.Id > 0 && restNode1.Id != restNode2.Id);

            Assert.IsTrue(restRelationship.StartNode == restNode1);
            Assert.IsTrue(restRelationship.EndNode == restNode2);
            Assert.IsTrue(restRelationship.Type == "friend");
        }
コード例 #8
0
        public void UpdateRelationshipProperties1()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

            var batch = new BatchStore();

            var batchRelationship = Relationship.CreateRelationship(node1, node2, "likes", null, batch);

            batchRelationship.Properties.SetProperty("name", "todd");
            batchRelationship.Properties.SetProperty("moved", true);
            batchRelationship.Properties.SetProperty("height", 13);

            batchRelationship.SaveProperties();

            Assert.IsTrue(batch.Execute());

            var restRelationship = batch.GetGraphObject(batchRelationship);

            Assert.IsTrue(restRelationship.Properties.GetProperty <string>("name") == "todd");
            Assert.IsTrue(restRelationship.Properties.GetProperty <bool>("moved"));
            Assert.IsTrue(restRelationship.Properties.GetProperty <int>("height") == 13);
        }