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);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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)
            {

            }
        }
        public void MultipleRelatinship3()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();
            var node3 = Node.CreateNode();

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

            var cypher = new Cypher();
            cypher.Start(s => s.Node("node1", node1.Id));
            cypher.Match(m => m.Node("node1").To("knows").Node("node2").Any("blocks").Node("node3"));
            cypher.Return(r => r.Node("node1").Node("node2").Node("node3"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.First().Field<Node>("node1") == node1);
            Assert.IsTrue(result.First().Field<Node>("node2") == node2);
            Assert.IsTrue(result.First().Field<Node>("node3") == node3);
        }
        public void MatchByRelationshipTypeUseIdentifer3()
        {
            var node1 = Node.CreateNode();
            var node2 = Node.CreateNode();
            var node3 = Node.CreateNode();

            var rel1 = node2.CreateRelationshipTo(node1, "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").From("r1", "knows").Node("matchedNode"));
            cypher.Return(r => r.Relationship("r1"));

            var result = cypher.Execute();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.First().Field<Relationship>("r1") == rel1);
        }