예제 #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();
            }
        }
예제 #2
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();
            }
        }
예제 #3
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();
            }
        }
예제 #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();
            }
        }
예제 #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);
            }
        }
예제 #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();
            }
        }
예제 #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);
            }
        }
예제 #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();
            }
        }
예제 #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);
            }
        }
예제 #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>();
            }
        }
예제 #11
0
        public void CreateDriverWithBasicAuthenticationAndConfiguration()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                client.IsConnected.Should().BeTrue();
            }
        }
예제 #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>();
            }
        }
예제 #13
0
        public void ShouldConnectAndPing()
        {
            using (var client = new NeoClient(URL, USER, PASSWORD, CONFIG))
            {
                client.Connect();

                bool response = client.Ping();

                response.Should().BeTrue();
            }
        }
예제 #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>();
            }
        }
예제 #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 })));
        }
예제 #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>();
            }
        }
예제 #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");
            }
        }
예제 #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();
            }
        }
예제 #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();
            }
        }
예제 #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();
            }
        }
예제 #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();
            }
        }
예제 #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();
            }
        }
예제 #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);
            }
        }
예제 #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 }));
        }
예제 #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();
            }
        }
예제 #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();
            }
        }
예제 #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));
        }
예제 #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();
            }
        }
예제 #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();
            }
        }
예제 #30
0
 public ProductRepository()
 {
     _client = NeoClient.Create().Client;
 }