Esempio n. 1
0
        public void RunCustomCypherQueryWithModelBinding()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user1 = new User {
                    Email = "*****@*****.**", FirstName = "FakeFirstName1", LastName = "FakeLastName2"
                };
                var user2 = new User {
                    Email = "*****@*****.**", FirstName = "FakeFirstName2", LastName = "FakeLastName2"
                };

                client.Add(user1);
                client.Add(user2);

                string cypherQuery = @"MATCH (n:User) RETURN n";

                IList <User> result = client.RunCustomQuery <User>(
                    query: cypherQuery
                    );

                result.Should().NotBeNullOrEmpty();
            }
        }
Esempio n. 2
0
        public void RunCustomCypherQuery()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                string cypherCreateQuery = @"CREATE (Neo:Crew {name:'Neo'}), 
                (Morpheus:Crew {name: 'Morpheus'}), 
                (Trinity:Crew {name: 'Trinity'}), 
                (Cypher:Crew:Matrix {name: 'Cypher'}), 
                (Smith:Matrix {name: 'Agent Smith'}), 
                (Architect:Matrix {name:'The Architect'}),
                (Neo)-[:KNOWS]->(Morpheus), 
                (Neo)-[:LOVES]->(Trinity), 
                (Morpheus)-[:KNOWS]->(Trinity),
                (Morpheus)-[:KNOWS]->(Cypher), 
                (Cypher)-[:KNOWS]->(Smith), 
                (Smith)-[:CODED_BY]->(Architect)";

                IStatementResult createResult = client.RunCustomQuery(
                    query: cypherCreateQuery
                    );

                createResult.Should().NotBeNull();
                createResult.Summary.Counters.LabelsAdded.Should().Be(7);
                createResult.Summary.Counters.NodesCreated.Should().Be(6);
                createResult.Summary.Counters.PropertiesSet.Should().Be(6);
                createResult.Summary.Counters.RelationshipsCreated.Should().Be(6);
            }
        }
Esempio n. 3
0
        public void RunCustomCypherWithReturnsQuery()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                string cypherCreateQuery = @"CREATE (Neo:Crew {name:'Neo'}), 
                (Morpheus:Crew {name: 'Morpheus'}), 
                (Trinity:Crew {name: 'Trinity'}), 
                (Cypher:Crew:Matrix {name: 'Cypher'}), 
                (Smith:Matrix {name: 'Agent Smith'}), 
                (Architect:Matrix {name:'The Architect'}),
                (Neo)-[:KNOWS]->(Morpheus), 
                (Neo)-[:LOVES]->(Trinity), 
                (Morpheus)-[:KNOWS]->(Trinity),
                (Morpheus)-[:KNOWS]->(Cypher), 
                (Cypher)-[:KNOWS]->(Smith), 
                (Smith)-[:CODED_BY]->(Architect)";

                IStatementResult createResult = client.RunCustomQuery(
                    query: cypherCreateQuery
                    );

                string cypherQuery = @"match (n:Crew)-[r:KNOWS*]-(m) where n.name='Neo' return n as Neo,r,m";

                IStatementResult queryResult = client.RunCustomQuery(
                    query: cypherQuery
                    );

                IList <object> result = queryResult.GetValues();

                createResult.Should().NotBeNull();
                createResult.Summary.Counters.LabelsAdded.Should().Be(7);
                createResult.Summary.Counters.NodesCreated.Should().Be(6);
                createResult.Summary.Counters.PropertiesSet.Should().Be(6);
                createResult.Summary.Counters.RelationshipsCreated.Should().Be(6);
                queryResult.Should().NotBeNull();
                result.Should().NotBeNullOrEmpty();
            }
        }
        public virtual void Dispose(bool isDisposing)
        {
            if (!isDisposing)
            {
                return;
            }

            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();
                client.RunCustomQuery("MATCH (n) DETACH DELETE n");
            }
        }
Esempio n. 5
0
        public void ErrorToRunInvalidCypher()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var exception = Record.Exception(() => client.RunCustomQuery("Invalid Cypher"));

                exception
                .Should()
                .BeOfType <ClientException>();
            }
        }
Esempio n. 6
0
        public IHttpActionResult GetMovieByTitle(string title)
        {
            var statementTemplate   = "MATCH (movie:Movie {title:$title}) OPTIONAL MATCH (movie)<-[r]-(person:Person) RETURN movie.title as title, collect([person.name, head(split(ToLower(type(r)), '_')), r.roles]) as castRef LIMIT 1";
            var statementParameters = new Dictionary <string, object> {
                { "title", title }
            };

            MovieResult result = null;

            using (INeoClient client = new NeoClient(WebApiConfig.url, WebApiConfig.userName, WebApiConfig.password, WebApiConfig.config))
            {
                client.Connect();

                result = client
                         .RunCustomQuery <MovieResult>(statementTemplate, statementParameters)
                         .SingleOrDefault();
            }

            return(Ok(result));
        }