public void Can_query_multiple_match_clauses_with_implicit_intersection() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { var results = session.Advanced.RawQuery <JObject>(@" match(Users as u1)-[HasRated where Score > 1 select Movie]->(Movies as m where id() = 'movies/2')<-[HasRated select Movie]-(Users as u2) select u1.Name as U1,u2.Name as U2 ").ToList().Select(x => new { u1 = x["U1"].Value <string>(), u2 = x["U2"].Value <string>(), }).ToList(); //since we didn't use "where" clause to make sure (u1 != u2), we would have all permutations Assert.NotEmpty(results); Assert.Equal(4, results.Count); Assert.Contains(results, item => item.u1 == "Jack" && item.u2 == "Jill"); Assert.Contains(results, item => item.u1 == "Jack" && item.u2 == "Jack"); Assert.Contains(results, item => item.u1 == "Jill" && item.u2 == "Jill"); Assert.Contains(results, item => item.u1 == "Jack" && item.u2 == "Jack"); } } }
public void Can_flatten_result_for_single_vertex_in_row() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { var allVerticesQuery = session.Advanced.RawQuery <JObject>(@"match (_ as v)").ToList(); Assert.False(allVerticesQuery.Any(row => row.ContainsKey("_ as v"))); //we have "flat" results } } }
public void Empty_vertex_node_should_work() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { var results = session.Advanced.RawQuery <Movie>("match ()-[HasRated select Movie]->(Movies as m) select m").ToList(); Assert.Equal(5, results.Count); } } }
public void Mutliple_results_in_row_wont_flatten_results() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { var allVerticesQuery = session.Advanced.RawQuery <JObject>(@"match (_ as u)-[HasRated select Movie]->(_ as m)").ToList(); Assert.True(allVerticesQuery.All(row => row.ContainsKey("m"))); Assert.True(allVerticesQuery.All(row => row.ContainsKey("u"))); } } }
public void Select_in_node_without_alias_should_properly_throw() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { var e = Assert.Throws <InvalidQueryException>(() => session.Advanced.RawQuery <JObject>(@" match (Users select Name)-[HasRated select Movie]->(Movies as m) ").ToArray()); Assert.True(e.Message.Contains("select", StringComparison.OrdinalIgnoreCase) && e.Message.Contains("forbidden", StringComparison.OrdinalIgnoreCase)); } } }
public void Missing_as_keyword_in_node_without_additional_clauses_should_properly_throw_in_non_recursive_query() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { var e = Assert.Throws <InvalidQueryException>(() => session.Advanced.RawQuery <JObject>(@" match (Users u1)-[HasRated select Movie]->(Movies as m) ").ToArray()); Assert.True(e.Message.Contains("invalid", StringComparison.OrdinalIgnoreCase) && e.Message.Contains("alias", StringComparison.OrdinalIgnoreCase) && e.Message.Contains("u1", StringComparison.OrdinalIgnoreCase)); } } }
public void Incomplete_union_query_should_properly_fail() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { Assert.Throws <InvalidQueryException>(() => session.Advanced.RawQuery <JObject>(@" match(Users as u1)-[HasRated where Score > 1 select Movie]->(Movies as m) OR select u1,u2 ").ToList()); } } }
public void Can_filter_vertices_with_explicit_with_clause() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { var results = session.Advanced.RawQuery <JObject>(@" with {from Users where id() = 'users/2'} as u match (u) select u.Name").ToList().Select(x => x["Name"].Value <string>()).ToArray(); Assert.Equal(1, results.Length); results[0] = "Jill"; } } }
public void Can_use_explicit_with_clause() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { var results = session.Advanced.RawQuery <JObject>(@" with {from Users} as u match (u)").ToList(); Assert.Equal(3, results.Count); var docTypes = results.Select(x => x["@metadata"]["@collection"].Value <string>()).ToArray(); Assert.Equal(3, docTypes.Count(t => t == "Users")); } } }
public void Can_query_without_collection_identifier() { using (var store = GetDocumentStore()) { Samples.CreateMoviesData(store); using (var session = store.OpenSession()) { var allVerticesQuery = session.Advanced.RawQuery <JObject>(@"match (_ as v)").ToList(); Assert.Equal(9, allVerticesQuery.Count); var docTypes = allVerticesQuery.Select(x => x["@metadata"]["@collection"].Value <string>()).ToArray(); Assert.Equal(3, docTypes.Count(t => t == "Genres")); Assert.Equal(3, docTypes.Count(t => t == "Movies")); Assert.Equal(3, docTypes.Count(t => t == "Users")); } } }