Ejemplo 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();
            }
        }
Ejemplo n.º 2
0
        public void CreateRelationshipWithProperties()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user1 = client.Add(new User {
                    Email = "FakeEmail1", FirstName = "FakeFirstName1", LastName = "FakeLastName1"
                });
                var user2 = client.Add(new User {
                    Email = "FakeEmail2", FirstName = "FakeFirstName2", LastName = "FakeLastName2"
                });

                var isCreated1 = client.CreateRelationship(
                    user1.Uuid,
                    user2.Uuid,
                    new RelationshipAttribute
                {
                    Direction = DIRECTION.INCOMING,
                    Name      = "BROTHER"
                },
                    new Dictionary <string, object>()
                {
                    { "CreatedAt", DateTime.UtcNow },
                    { "Kinship_Level", 1 },
                    { "Name", "FakeName" }
                }
                    );

                isCreated1.Should().BeTrue();
            }
        }
Ejemplo n.º 3
0
        public void DropRelationship()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user1 = client.Add(new User {
                    Email = "FakeEmail1", FirstName = "FakeFirstName1", LastName = "FakeLastName1"
                });
                var user2 = client.Add(new User {
                    Email = "FakeEmail2", FirstName = "FakeFirstName2", LastName = "FakeLastName2"
                });

                var relationship = new RelationshipAttribute
                {
                    Direction = DIRECTION.INCOMING,
                    Name      = "BROTHER"
                };

                client.CreateRelationship(
                    user1.Uuid,
                    user2.Uuid,
                    relationship);

                bool result = client.DropRelationshipBetweenTwoNodes(
                    user1.Uuid,
                    user2.Uuid,
                    relationship);

                result.Should().BeTrue();
            }
        }
Ejemplo n.º 4
0
        public void CreateMultipleRelationship()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user1 = client.Add(new User {
                    Email = "FakeEmail1", FirstName = "FakeFirstName1", LastName = "FakeLastName1"
                });
                var user2 = client.Add(new User {
                    Email = "FakeEmail2", FirstName = "FakeFirstName2", LastName = "FakeLastName2"
                });

                var isCreated1 = client.CreateRelationship(
                    user1.Uuid,
                    user2.Uuid,
                    new RelationshipAttribute
                {
                    Direction = DIRECTION.INCOMING,
                    Name      = "BROTHER"
                });

                var isCreated2 = client.CreateRelationship(
                    user1.Uuid,
                    user2.Uuid,
                    new RelationshipAttribute
                {
                    Direction = DIRECTION.INCOMING,
                    Name      = "FAMILY"
                });

                isCreated1.Should().BeTrue();
                isCreated2.Should().BeTrue();
            }
        }
Ejemplo n.º 5
0
        public void MergeOnUpdateNodes()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user1 = new User()
                {
                    Email = "FakeEmail1", FirstName = "FakeFirstName1", LastName = "FakeLastName1"
                };
                var user2 = new User()
                {
                    Email = "FakeEmail2", FirstName = "FakeFirstName2", LastName = "FakeLastName2"
                };

                var entity = client.Add(user1);

                User result = client.Merge(
                    entityOnCreate: user1,
                    entityOnUpdate: user2,
                    $"Uuid:\"{entity.Uuid}\""
                    );

                result.Should().NotBeNull();
                result.Uuid.Should().Be(entity.Uuid);
            }
        }
Ejemplo n.º 6
0
        public void MatchRelationship()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                User user1 = client.Add(new User {
                    Email = "FakeEmail1", FirstName = "FakeFirstName1", LastName = "FakeLastName1"
                });
                User user2 = client.Add(new User {
                    Email = "FakeEmail2", FirstName = "FakeFirstName2", LastName = "FakeLastName2"
                });

                var relationship = new RelationshipAttribute
                {
                    Direction = DIRECTION.INCOMING,
                    Name      = "BROTHER"
                };

                bool isCreatedRelationship = client.CreateRelationship(
                    user1.Uuid,
                    user2.Uuid,
                    relationship
                    );

                bool isUpdatedRelatiionship = client.MergeRelationship(
                    uuidFrom: user1.Uuid,
                    uuidTo: user2.Uuid,
                    relationshipAttribute: relationship
                    );

                isCreatedRelationship.Should().BeTrue();
                isUpdatedRelatiionship.Should().BeTrue();
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        public void GetAllNodes()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var userList = new List <User>();

                for (int i = 0; i < 10; i++)
                {
                    userList.Add(new User
                    {
                        Email     = "*****@*****.**",
                        FirstName = $"FakeFirstName{i}",
                        LastName  = $"FakeLastName{i}"
                    });
                }

                userList.ForEach((user) => client.Add(user));

                IList <User> entities = client.GetAll <User>();

                entities.Should().NotBeNullOrEmpty();
            }
        }
Ejemplo n.º 9
0
        public void DropNodesByProperties()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var userList = new List <User>();

                for (int i = 0; i < 10; i++)
                {
                    userList.Add(new User
                    {
                        Email     = "*****@*****.**",
                        FirstName = $"FakeFirstName{i}",
                        LastName  = $"FakeLastName{i}"
                    });
                }

                var properties = new Dictionary <string, object>()
                {
                    { nameof(User.Email), "*****@*****.**" },
                };

                userList.ForEach((user) => client.Add(user));

                int nodesDeleted = client.DropByProperties <User>(properties);

                nodesDeleted.Should().Be(10);
            }
        }
Ejemplo n.º 10
0
        public void ShouldReportWrongScheme()
        {
            using (var client = new NeoClient("http://localhost", USER, PASSWORD, CONFIG))
            {
                var exception = Record.Exception(() => client.Connect());

                exception.Should().BeOfType <NotSupportedException>();
            }
        }
Ejemplo n.º 11
0
        public void CreateDriverWithBasicAuthenticationAndConfiguration()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                client.IsConnected.Should().BeTrue();
            }
        }
Ejemplo n.º 12
0
        public void AuthenticationErrorIfWrongAuthToken()
        {
            using (var client = new NeoClient(URL, "fake", "fake", CONFIG))
            {
                client.Connect();

                var exception = Record.Exception(() => client.Ping());

                exception.Should().BeOfType <AuthenticationException>();
            }
        }
Ejemplo n.º 13
0
        public void ShouldConnectAndPing()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                bool response = client.Ping();

                response.Should().BeTrue();
            }
        }
Ejemplo n.º 14
0
        public void ServiceUnavailableExceptionError()
        {
            using (var client = new NeoClient("bolt://localhost:1111", USER, PASSWORD))
            {
                client.Connect();

                var exception = Record.Exception(() => client.Ping());

                exception.Should().BeOfType <ServiceUnavailableException>();
            }
        }
Ejemplo n.º 15
0
        public IHttpActionResult SearchMoviesByTitle(string q = "Matrix")
        {
            IList <Movie> movies = null;

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

                movies = client.GetAll <Movie>($"n.title CONTAINS '{q}'");
            }

            return(Ok(movies?.Select(m => new { movie = m })));
        }
Ejemplo n.º 16
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>();
            }
        }
Ejemplo n.º 17
0
        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");
            }
        }
Ejemplo n.º 18
0
        public void CreateDriverWithConnectionPool()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, Config.Builder
                                              .WithMaxConnectionLifetime(TimeSpan.FromMinutes(30))
                                              .WithMaxConnectionPoolSize(100)
                                              .WithConnectionAcquisitionTimeout(TimeSpan.FromMinutes(2))
                                              .WithEncryptionLevel(EncryptionLevel.None)
                                              .ToConfig()))
            {
                client.Connect();

                client.IsConnected.Should().BeTrue();
            }
        }
Ejemplo n.º 19
0
        public void DropNodeById()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user = client.Add(new User {
                    Email = "*****@*****.**", FirstName = "Oktay", LastName = "Kýr"
                });

                bool result = client.Drop <User>(user.Uuid);

                result.Should().BeTrue();
            }
        }
Ejemplo n.º 20
0
        public void GetNodesBySingleProperty()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user = client.Add(new User {
                    Email = "*****@*****.**", FirstName = "Oktay", LastName = "Kýr"
                });

                IList <User> entities = client.GetByProperty <User>(nameof(User.Email), user.Email);

                entities.Should().NotBeNullOrEmpty();
            }
        }
Ejemplo n.º 21
0
        public void CreateLabel()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user = client.Add(new User {
                    Email = "*****@*****.**", FirstName = "Oktay", LastName = "Kýr"
                });

                bool result = client.AddLabel(user.Uuid, "Father");

                result.Should().BeTrue();
            }
        }
Ejemplo n.º 22
0
        public void CreateNode()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user = new User {
                    Email = "*****@*****.**", FirstName = "Oktay", LastName = "Kýr"
                };

                client.Add(user);

                client.IsConnected.Should().BeTrue();
            }
        }
Ejemplo n.º 23
0
        public void GetNodeByUuid()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user = client.Add(new User {
                    Email = "*****@*****.**", FirstName = "Oktay", LastName = "Kýr"
                });

                User entity = client.GetByUuidWithRelatedNodes <User>(user.Uuid);

                entity.Should().NotBeNull();
                user.Should().BeEquivalentTo(entity);
            }
        }
Ejemplo n.º 24
0
        public IHttpActionResult Index(int limit = 100)
        {
            var nodes         = new List <NodeResult>();
            var relationships = new List <object>();
            var config        = Config.Builder
                                .WithEncryptionLevel(EncryptionLevel.None)
                                .ToConfig();

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

                IList <Movie> movieList = client
                                          .GetAll <Movie>()
                                          .Where(p => p.ActorList != null)
                                          .ToList();

                var i = 0;

                foreach (var movie in movieList)
                {
                    var target = i;
                    nodes.Add(new NodeResult {
                        title = movie.title, label = movie.Label
                    });
                    i += 1;

                    var castMembers = movie.ActorList;
                    foreach (var castMember in castMembers)
                    {
                        var source = nodes.FindIndex(c => c.title == castMember.name);
                        if (source == -1)
                        {
                            nodes.Add(new NodeResult {
                                title = castMember.name, label = "actor"
                            });
                            source = i;
                            i     += 1;
                        }
                        relationships.Add(new { source, target });
                    }
                }
            }

            return(Ok(new { nodes, links = relationships }));
        }
Ejemplo n.º 25
0
        public void UpdateNodeAndFetchResult()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user = client.Add(new User {
                    Email = "*****@*****.**", FirstName = "Oktay", LastName = "Kýr"
                });

                user.FirstName = "UpdatedName";

                var updatedEntity = client.Update(user, user.Uuid, fetchResult: true);

                updatedEntity.Should().NotBeNull();
            }
        }
Ejemplo n.º 26
0
        public void DeleteNode()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user = client.Add(new User {
                    Email = "*****@*****.**", FirstName = "Oktay", LastName = "Kýr"
                });

                var deletedEntity = client.Delete <User>(user.Uuid);

                var entity = client.GetByUuidWithRelatedNodes <User>(user.Uuid);

                deletedEntity.IsDeleted.Should().BeTrue();
                entity.Should().BeNull();
            }
        }
Ejemplo n.º 27
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));
        }
Ejemplo n.º 28
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();
            }
        }
Ejemplo n.º 29
0
        public void GetNodesByMultipleProperties()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                var user = client.Add(new User {
                    Email = "*****@*****.**", FirstName = "Oktay", LastName = "Kýr"
                });

                var properties = new Dictionary <string, object>()
                {
                    { nameof(User.Email), user.Email },
                    { nameof(User.FirstName), user.FirstName },
                    { nameof(User.LastName), user.LastName }
                };

                IList <User> entities = client.GetByProperties <User>(properties);

                entities.Should().NotBeNullOrEmpty();
            }
        }