示例#1
0
        public async void TestInsertNodesWithRelationGeneric()
        {
            var country = new Country()
            {
                CountryID = "555", CountryName = "NOM COUNTRY"
            };
            var city = new City()
            {
                CityId = "5555", CityName = "NOM CITY"
            };

            country.Cities = new List <City>()
            {
                city
            };
            var context         = new NeoContext(Driver);
            var resultExecuting = await context.InsertNodeWithRelation <City, EXISTS_IN, Country>(city, new EXISTS_IN(), country);

            var resultCountry = await context.QueryDefaultIncludeable <Country, City>("MATCH (n:Country { CountryID: '555' })<-[e:EXISTS_IN]-(c:City) return n,c",
                                                                                      (country, city) =>
            {
                country.Cities = new List <City>()
                {
                    city
                };
                return(country);
            }
                                                                                      );

            Assert.True(resultExecuting.QueryType == Neo4j.Driver.QueryType.WriteOnly);
            Assert.True(IsEqual(country, resultCountry));
            await context.ExecuteQuery("MATCH (n:Country { CountryID: '555' }) DETACH DELETE n");

            await context.ExecuteQuery("MATCH (n:City { CityId: '5555' }) DETACH DELETE n");
        }
        public async void TestQueryDoubleInclude()
        {
            var expected = new Country()
            {
                CountryID   = "216",
                CountryName = "United States",
                Cities      = new List <City>()
                {
                    new City()
                    {
                        CityId   = "3308",
                        CityName = "Chicago",
                        Airports = new List <Airport>()
                        {
                            new Airport()
                            {
                                AirportId   = "3830",
                                AirportName = "Chicago O'Hare International Airport"
                            },
                            new Airport()
                            {
                                AirportId   = "3747",
                                AirportName = "Chicago Midway International Airport"
                            }
                        }
                    },
                }
            };
            var countryHolder = new Dictionary <string, Country>();
            var cityHolder    = new Dictionary <string, City>();
            var parameters    = new Dictionary <string, object>
            {
                { "Country", "United States" },
                { "City", "Chicago" }
            };
            var context = new NeoContext(Driver);
            var result  = await context.QueryDefaultIncludeable <Country, City, Airport>("match(n:Country {countryName:$Country})<-[e:EXISTS_IN]-(c:City {cityName:$City})<-[:IS_IN]-(a:Airport) return n,c,a", parameters,
                                                                                         (country, city, airport) =>
            {
                if (!countryHolder.ContainsKey(country.CountryID))
                {
                    countryHolder.Add(country.CountryID, country);
                    country.Cities = new List <City>();
                }
                if (!cityHolder.ContainsKey(city.CityId))
                {
                    cityHolder.Add(city.CityId, city);
                    countryHolder[country.CountryID].Cities.Add(city);
                    city.Airports = new List <Airport>();
                }
                cityHolder[city.CityId].Airports.Add(airport);
                return(countryHolder[country.CountryID]);
            }
                                                                                         );

            Assert.NotNull(result);
            Assert.True(IsEqual(result, expected));
        }
示例#3
0
        public async void TestInsertNodesWithRelation()
        {
            var person = new Person()
            {
                Age         = 50,
                DateOfBirth = DateTime.Now.AddYears(-50),
                Id          = Guid.NewGuid(),
                Name        = "neo",
                Salary      = 5400.77,
                Owns        = new List <Owns>()
                {
                    new Owns()
                    {
                        OwnedFrom = DateTime.Now.AddYears(-2),
                        OwnedTill = DateTime.Now.AddYears(-1),
                        House     = new House()
                        {
                            Address = "test address",
                            Age     = 150
                        }
                    }
                }
            };
            INeoContext    context         = new NeoContext(Driver);
            IResultSummary resultExecuting = await context.InsertNodeWithRelation <Person, Owns, House>(person, person.Owns.First(), person.Owns.First().House);

            Dictionary <Guid, Person> personContainer = new Dictionary <Guid, Person>();
            var resultPerson = await context.QueryDefaultIncludeable <Person, Owns, House>("MATCH (p:Person { Name: 'neo' })-[o:Owns]->(h:House) return p,o,h",
                                                                                           (p, o, h) =>
            {
                if (!personContainer.ContainsKey(p.Id))
                {
                    personContainer.Add(p.Id, p);
                    p.Owns = new List <Owns>();
                }
                personContainer[p.Id].Owns.Add(o);
                o.House = h;
                return(personContainer[p.Id]);
            }
                                                                                           );

            await context.ExecuteQuery("MATCH (n:Person { Name: 'neo' }) DETACH DELETE n");

            await context.ExecuteQuery("MATCH (p:House {Address: 'test address'}) DETACH DELETE p");

            Assert.Equal <Person>(person, resultPerson);
        }
        public async void TestQuerySingleInclude()
        {
            var expected = new Country()
            {
                CountryID   = "186",
                CountryName = "Russia",
                Cities      = new List <City>()
                {
                    new City()
                    {
                        CityId   = "2654",
                        CityName = "Sochi"
                    },
                    new City()
                    {
                        CityId   = "2675",
                        CityName = "Kazan"
                    },
                    new City()
                    {
                        CityId   = "2657",
                        CityName = "Chelyabinsk"
                    }
                }
            };
            var countryHolder = new Dictionary <string, Country>();
            var parameters    = new Dictionary <string, object>();

            parameters.Add("Country", "Russia");
            var context = new NeoContext(Driver);
            var result  = await context.QueryDefaultIncludeable <Country, City>("match(n:Country {countryName:$Country})<-[e:EXISTS_IN]-(c:City) return n,c", parameters,
                                                                                (country, city) =>
            {
                if (!countryHolder.ContainsKey(country.CountryID))
                {
                    countryHolder.Add(country.CountryID, country);
                    country.Cities = new List <City>();
                }
                countryHolder[country.CountryID].Cities.Add(city);
                return(countryHolder[country.CountryID]);
            }
                                                                                );

            Assert.NotNull(result);
            Assert.True(IsEqual(result, expected));
        }
        public async void TestQueryQuadrupleInclude()
        {
            var expected = new Country()
            {
                CountryID   = "216",
                CountryName = "United States",
                Cities      = new List <City>()
                {
                    new City()
                    {
                        CityId   = "3308",
                        CityName = "Chicago",
                        Airports = new List <Airport>()
                        {
                            new Airport()
                            {
                                AirportId       = "3830",
                                AirportName     = "Chicago O'Hare International Airport",
                                IncomingFlights = new List <Flight>()
                                {
                                    new Flight()
                                    {
                                        FlightId = "8879",
                                        Airline  = new Airline()
                                        {
                                            AirlineId = "137"
                                        }
                                    },
                                    new Flight()
                                    {
                                        FlightId = "9999",
                                        Airline  = new Airline()
                                        {
                                            AirlineId = "137"
                                        }
                                    }
                                }
                            },
                            new Airport()
                            {
                                AirportId       = "3747",
                                AirportName     = "Chicago Midway International Airport",
                                IncomingFlights = new List <Flight>()
                                {
                                    new Flight()
                                    {
                                        FlightId = "8858",
                                        Airline  = new Airline()
                                        {
                                            AirlineId = "137"
                                        }
                                    }
                                }
                            }
                        }
                    },
                }
            };
            var countryHolder = new Dictionary <string, Country>();
            var cityHolder    = new Dictionary <string, City>();
            var airportHolder = new Dictionary <string, Airport>();
            var flightHolder  = new Dictionary <string, Flight>();
            var parameters    = new Dictionary <string, object>
            {
                { "Country", "United States" },
                { "City", "Chicago" }
            };
            var context = new NeoContext(Driver);
            var result  = await context.QueryDefaultIncludeable <Country, City, Airport, Flight, Airline>("match(n:Country {countryName:$Country})<-[e:EXISTS_IN]-(c:City {cityName:$City})<-[:IS_IN]-(a:Airport)<-[:DESTINATION]-(f:Flight)-[:OF]->(al:Airline) return n,c,a,f,al", parameters,
                                                                                                          (country, city, airport, incFlight, airline) =>
            {
                if (!countryHolder.ContainsKey(country.CountryID))
                {
                    countryHolder.Add(country.CountryID, country);
                    country.Cities = new List <City>();
                }
                if (!cityHolder.ContainsKey(city.CityId))
                {
                    cityHolder.Add(city.CityId, city);
                    countryHolder[country.CountryID].Cities.Add(city);
                    city.Airports = new List <Airport>();
                }
                if (!airportHolder.ContainsKey(airport.AirportId))
                {
                    airportHolder.Add(airport.AirportId, airport);
                    cityHolder[city.CityId].Airports.Add(airport);
                    airport.IncomingFlights = new List <Flight>();
                }
                if (!flightHolder.ContainsKey(incFlight.FlightId))
                {
                    flightHolder.Add(incFlight.FlightId, incFlight);
                    airportHolder[airport.AirportId].IncomingFlights.Add(incFlight);
                    incFlight.Airline = airline;
                }
                return(countryHolder[country.CountryID]);
            }
                                                                                                          );

            Assert.NotNull(result);
            Assert.True(IsEqual(result, expected));
        }