示例#1
0
        public void DeleteMultipleNodeProperties2()
        {
            var now = DateTime.Now;

            var p = new Properties();
            p.SetProperty("name", "jack");
            p.SetProperty("age", 12);
            p.SetProperty("date", now);

            var node1 = Node.CreateNode(p);

            var cypher = new Cypher();

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

            var results = cypher.Execute();

            var n1 = Node.GetNode(node1.Id);

            Assert.IsTrue(n1 == results.Rows[0].Field<Node>("node1"));

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

            Assert.IsTrue(n1.GetProperty<DateTime>("date") == now);
        }
示例#2
0
        public void SetNodeProperty2()
        {
            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 cypher = new Cypher();

            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Set(s => s.Node("node1", p));
            cypher.Return(r => r.Node("node1"));

            var results = cypher.Execute();

            var n1 = results.Rows[0].Field<Node>("node1");

            Assert.IsTrue(n1.GetProperty<string>("name") == "jack");
            Assert.IsTrue(n1.GetProperty<int>("age") == 12);
            Assert.IsTrue(n1.GetProperty<DateTime>("date") == now);
        }
示例#3
0
        public void OperatorHasTest2()
        {
            var p1 = new Properties();
            p1.SetProperty("name", "jack");

            var p2 = new Properties();
            p2.SetProperty("name", "jill");
            p2.SetProperty("count", 3);

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

            var rel1 = node1.CreateRelationshipTo(node2, "like", p1);
            var rel2 = node1.CreateRelationshipTo(node3, "like", p2);

            var cypher = new Cypher();
            cypher.Start(s => s.Relationship("rel", rel1.Id	, rel2.Id));
            cypher.Where(w => w.RelationshipHas("rel", "count"));
            cypher.Return(r => r.Relationship("rel"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.First().Field<Relationship>("rel") == rel2);
        }
示例#4
0
        public void ReturnAllElements()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();
            var rel1 = node1.CreateRelationshipTo(node2, "like");

            var cypher = new Cypher();

            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Match(m => m.Node("node1").To("rel1", "like").Node("node2"));
            cypher.Return(r => r.AllElements());

            var row = cypher.Execute().AsEnumerable().FirstOrDefault();

            Assert.IsNotNull(row);

            var objNode1 = row.Field<object>("node1");
            var objNode2 = row.Field<object>("node2");
            var objRel1 = row.Field<object>("rel1");

            var rowNode1 = RestNodeStore.CreateNodeFromJson((JObject)objNode1);
            var rowNode2 = RestNodeStore.CreateNodeFromJson((JObject)objNode2);
            var rowRel1 = RestRelationshipStore.CreateRelationshipFromJson((JObject)objRel1);

            Assert.IsTrue(node1.Id == rowNode1.Id);
            Assert.IsTrue(node2.Id == rowNode2.Id);
            Assert.IsTrue(rel1.Id == rowRel1.Id);
        }
示例#5
0
        public void GetNodeById()
        {
            var node = Node.CreateNode();

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node", node.Id));
            cypher.Return(r => r.Node("node"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);

            Assert.IsTrue(node == result.AsEnumerable().First().Field<Node>("node"));
        }
示例#6
0
        public void CreateNodeIfMissing()
        {
            var node1 = Node.CreateNode();

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Relate(l => l.Node("node1").To("likes").Node("node2"));

            cypher.Return(r => r.Node("node2"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Rows.Count == 1);
            Assert.IsTrue(result.Rows[0].Field<Node>("node2") != null);
        }
示例#7
0
        public void GetNodeByIndexLookup()
        {
            var node1 = Node.CreateNode();

            var value1 = UniqueValue();

            node1.AddToIndex("nodes", "name", value1);

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node", "nodes", "name", value1));
            cypher.Return(r => r.Node("node"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);

            Assert.IsTrue(node1 == result.First().Field<Node>("node"));
        }
示例#8
0
        public void GetMultipleNodesById()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();
            var node3 = Node.CreateNode();

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node", node1.Id, node2.Id, node3.Id));
            cypher.Return(r => r.Node("node"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 3);

            Assert.IsTrue(node1 == result.First().Field<Node>("node"));
            Assert.IsTrue(node2 == result.ElementAt(1).Field<Node>("node"));
            Assert.IsTrue(node3 == result.ElementAt(2).Field<Node>("node"));
        }
示例#9
0
        public void IncomingRelationships()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();
            var node3 = Node.CreateNode();

            var rel1 = node1.CreateRelationshipTo(node2, "like");
            var rel2 = node3.CreateRelationshipTo(node1, "like");

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Match(m => m.Node("node1").From().Node("matchedNode"));
            cypher.Return(r => r.Node("matchedNode"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.First().Field<Node>("matchedNode") == node3);
        }
示例#10
0
        public void SetNodeProperty1()
        {
            var p = new Properties();
            p.SetProperty("name", "jack");

            var node1 = Node.CreateNode();

            var cypher = new Cypher();

            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Set(s => s.Node("node1", p));
            cypher.Return(r => r.Node("node1"));

            var results = cypher.Execute();

            var n1 = results.First().Field<Node>("node1");

            Assert.IsTrue(n1.GetProperty<string>("name") == "jack");
        }
示例#11
0
        public void MatchByMultipleRelationshipType1()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();
            var node3 = Node.CreateNode();

            var rel1 = node1.CreateRelationshipTo(node2, "knows");
            var rel2 = node1.CreateRelationshipTo(node3, "blocks");

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Match(m => m.Node("node1").Any(new List<string> { "knows", "blocks" }).Node("matchedNode"));
            cypher.Return(r => r.Node("matchedNode"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 2);
            Assert.IsTrue(result.First().Field<Node>("matchedNode") == node2);
            Assert.IsTrue(result.ElementAt(1).Field<Node>("matchedNode") == node3);
        }
示例#12
0
        public void CreateRelationship()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

            var cypher = new Cypher();
            cypher.Start(s => s.Node("n1", node1.Id).Node("n2", node2.Id));

            cypher.Create(c => c.Node("n1").To("r", "like").Node("n2"));

            cypher.Return(r => r.Relationship("r"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.First().Field<Relationship>("r") != null);
            var rel = result.First().Field<Relationship>("r");
            Assert.IsTrue(rel.StartNode == node1);
            Assert.IsTrue(rel.EndNode == node2);
        }
示例#13
0
        public void DirectedRelationshipsAndIdentifier()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();
            var node3 = Node.CreateNode();

            var rel1 = node1.CreateRelationshipTo(node2, "knows");
            var rel2 = node1.CreateRelationshipTo(node3, "blocks");

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Match(m => m.Node("node1").To("r", string.Empty).Node());
            cypher.Return(r => r.Relationship("r"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 2);
            Assert.IsTrue(result.First().Field<Relationship>("r") == rel1);
            Assert.IsTrue(result.ElementAt(1).Field<Relationship>("r") == rel2);
        }
示例#14
0
        public void SetRelationshipProperty1()
        {
            var p = new Properties();
            p.SetProperty("name", "jack");

            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.Rows[0].Field<Relationship>("rel1");

            Assert.IsTrue(r1.GetProperty<string>("name") == "jack");
        }
示例#15
0
        public void CreateNodesWithProperties()
        {
            var p = new Properties();
            p.SetProperty("name", "jack");
            p.SetProperty("age", 12);

            var node1 = Node.CreateNode();

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Relate(l => l.Node("node1").To("likes").Node("node2", p));

            cypher.Return(r => r.Node("node2"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Rows.Count == 1);
            Assert.IsTrue(result.Rows[0].Field<Node>("node2") != null);
            var n2 = result.Rows[0].Field<Node>("node2");
            Assert.IsTrue(n2.GetProperty<string>("name") == "jack");
            Assert.IsTrue(n2.GetProperty<int>("age") == 12);
        }
示例#16
0
        public void OperatorHasTest1()
        {
            var p1 = new Properties();
            p1.SetProperty("name", "jack");

            var p2 = new Properties();
            p2.SetProperty("name", "jill");
            p2.SetProperty("count", 3);

            var node1 = Node.CreateNode(p1);
            var node2 = Node.CreateNode(p1);
            var node3 = Node.CreateNode(p2);

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node", node1.Id, node2.Id, node3.Id));
            cypher.Where(w => w.NodeHas("node", "count"));
            cypher.Return(r => r.Node("node"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.First().Field<Node>("node") == node3);
        }
示例#17
0
        public void CreateRelationshipIfMissing()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();
            var node3 = Node.CreateNode();

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node1", node1.Id).Node("node2", node2.Id, node3.Id));
            cypher.Relate(l => l.Node("node1").To("r", "likes").Node("node2"));

            cypher.Return(r => r.Relationship("r"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Rows.Count == 2);
            var r1 = result.Rows[0].Field<Relationship>("r");
            var r2 = result.Rows[1].Field<Relationship>("r");

            Assert.IsTrue(r1.StartNode == node1);
            Assert.IsTrue(r1.EndNode == node2);
            Assert.IsTrue(r2.StartNode == node1);
            Assert.IsTrue(r2.EndNode == node3);
        }
示例#18
0
        public void MultipleRelationshipStartingPoints2()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();
            var node3 = Node.CreateNode();

            var rel1 = node1.CreateRelationshipTo(node3, "like");
            var rel2 = node2.CreateRelationshipTo(node3, "like");

            var cypher = new Cypher();
            cypher.Start(s => s.Relationship("r1", rel1.Id));
            cypher.Start(s => s.Relationship("r2", rel2.Id));

            cypher.Return(r => r.Relationship("r1"));
            cypher.Return(r => r.Relationship("r2"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(rel1 == result.First().Field<Relationship>("r1"));
            Assert.IsTrue(rel2 == result.First().Field<Relationship>("r2"));
        }
示例#19
0
        public void MultipleNodeStartingPoints2()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

            var cypher = new Cypher();
            cypher.Start(s => s.Node("n1", node1.Id));
            cypher.Start(s => s.Node("n2", node2.Id));

            cypher.Return(r => r.Node("n1"));
            cypher.Return(r => r.Node("n2"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(node1 == result.First().Field<Node>("n1"));
            Assert.IsTrue(node2 == result.First().Field<Node>("n2"));
        }
示例#20
0
        public void DeleteNodeAndRelationship()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

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

            var cypher = new Cypher();

            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Match(m => m.Node("node1").To("r", "like").Node("node2"));
            cypher.Delete(d => d.Node("node2").Relationship("r"));

            cypher.Execute();

            try
            {
                Node.GetNode(node2.Id);

                Assert.Fail();
            }
            catch (NodeNotFoundException e)
            {

            }

            try
            {
                Relationship.GetRelationship(rel.Id);

                Assert.Fail();
            }
            catch(RelationshipNotFoundException e)
            {

            }
        }
示例#21
0
        public void GetRelationshipByIndexQuery()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

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

            var value1 = DateTime.Now.Millisecond;

            rel.AddToIndex("relationships", "name", value1);

            var cypher = new Cypher();
            cypher.Start(s => s.Relationship("rel", "relationships", string.Format("name:{0}", value1)));
            cypher.Return(r => r.Relationship("rel"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);

            Assert.IsTrue(rel == result.First().Field<Relationship>("rel"));
        }
示例#22
0
        public void GetRelationshipByIndexLookup()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

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

            var value1 = UniqueValue();

            rel.AddToIndex("relationships", "name", value1);

            var cypher = new Cypher();
            cypher.Start(s => s.Relationship("rel", "relationships", "name", value1));
            cypher.Return(r => r.Relationship("rel"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);

            Assert.IsTrue(rel == result.First().Field<Relationship>("rel"));
        }
示例#23
0
        public void GetRelationshipById()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

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

            var cypher = new Cypher();
            cypher.Start(s => s.Relationship("relationship", rel.Id));
            cypher.Return(r => r.Relationship("relationship"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);

            Assert.IsTrue(rel == result.AsEnumerable().First().Field<Relationship>("relationship"));
        }
示例#24
0
        public void DeleteSingleNode()
        {
            var node1 = Node.CreateNode();

            var cypher = new Cypher();

            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Delete(d => d.Node("node1"));

            cypher.Execute();

            Node.GetNode(node1.Id);
        }
示例#25
0
        public void DeleteSingleNodeProperty()
        {
            var now = DateTime.Now;

            var p = new Properties();
            p.SetProperty("name", "jack");
            p.SetProperty("age", 12);
            p.SetProperty("date", now);

            var node1 = Node.CreateNode(p);

            var cypher = new Cypher();

            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Delete(d => d.Node("node1", "age"));

            cypher.Execute();

            var n1 = Node.GetNode(node1.Id);

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

            Assert.IsTrue(n1.GetProperty<string>("name") == "jack");
            Assert.IsTrue(n1.GetProperty<DateTime>("date") == now);
        }
示例#26
0
        public void DeleteSingleRelationship()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

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

            var cypher = new Cypher();

            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Match(m => m.Node("node1").To("r", "like").Node("node2"));
            cypher.Delete(d => d.Relationship("r"));

            cypher.Execute();

            Relationship.GetRelationship(rel.Id);
        }
示例#27
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);
        }
示例#28
0
        public void DeleteMultipleRelationshipProperties1()
        {
            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").Node("rel1", "name"));
            cypher.Return(r => r.Relationship("rel1"));

            var results = cypher.Execute();

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

            Assert.IsTrue(r1 == results.Rows[0].Field<Relationship>("rel1"));

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

            Assert.IsTrue(r1.GetProperty<DateTime>("date") == now);
        }
示例#29
0
        public void GetNodeByIndexQuery()
        {
            var node1 = Node.CreateNode();

            var value1 = DateTime.Now.Millisecond;

            node1.AddToIndex("nodes", "name", value1);

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node", "nodes", string.Format("name:{0}", value1)));
            cypher.Return(r => r.Node("node"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);

            Assert.IsTrue(node1 == result.First().Field<Node>("node"));
        }
示例#30
0
        public void CreateRelationshipWithProperties()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();

            var p = new Properties();
            p.SetProperty("name", "jack");
            p.SetProperty("age", 12);

            var cypher = new Cypher();
            cypher.Start(s => s.Node("n1", node1.Id).Node("n2", node2.Id));

            cypher.Create(c => c.Node("n1").To("r", "like", p).Node("n2"));

            cypher.Return(r => r.Relationship("r"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.First().Field<Relationship>("r") != null);
            var rel = result.First().Field<Relationship>("r");
            Assert.IsTrue(rel.StartNode == node1);
            Assert.IsTrue(rel.EndNode == node2);
            Assert.IsTrue(rel.GetProperty<string>("name") == "jack");
            Assert.IsTrue(rel.GetProperty<int>("age") == 12);
        }