public void HasAggregate() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { GraphTraversal traversal = graphCommand.g().V().Has("age").Aggregate("x").Cap("x").Unfold(); List <string> result = traversal.Next(); foreach (var r in result) { Console.WriteLine(r); } Assert.AreEqual(4, result.Count); } }
public void StoreNot() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { GraphTraversal traversal = graphCommand.g().V().Store("x").Not(GraphTraversal.__().HasLabel("person")).Cap("x").Unfold(); List <string> result = traversal.Next(); foreach (var r in result) { Console.WriteLine(r); } Assert.AreEqual(6, result.Count); } }
public void CoinWithProbabilityEqHalf() { using (GraphViewCommand command = new GraphViewCommand(graphConnection)) { GraphTraversal traversal = command.g().V().Coin(0.5).Values("name"); List <string> result = traversal.Next(); HashSet <string> allNames = new HashSet <string> { "marko", "vadas", "lop", "josh", "ripple", "peter" }; Assert.IsTrue(result.Count >= 0 && result.Count <= 6); Assert.IsTrue(result.TrueForAll(name => allNames.Contains(name))); } }
public void IsStore() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { GraphTraversal traversal = graphCommand.g().V().Values("age").Is(Predicate.lte(30)).Store("x").Cap("x").Unfold(); List <string> result = traversal.Next(); foreach (var r in result) { Console.WriteLine(r); } Assert.AreEqual(2, result.Count); } }
public void WhereAggregate() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { GraphTraversal traversal = graphCommand.g().V().Out("created").In("created") .Where(GraphTraversal.__().Out("created").Count().Is(Predicate.gt(1))).Aggregate("x").Values("name") .Cap("x").Unfold(); List <string> result = traversal.Next(); foreach (var r in result) { Console.WriteLine(r); } Assert.AreEqual(4, result.Count); } }
public void StoreOr() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { GraphTraversal traversal = graphCommand.g().V().Store("x") .Or(GraphTraversal.__().OutE("created"), GraphTraversal.__().InE("created").Count().Is(Predicate.gt(1))).Cap("x").Unfold(); List <string> result = traversal.Next(); foreach (var r in result) { Console.WriteLine(r); } Assert.AreEqual(6, result.Count); } }
public void get_g_VX1X_name_path() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.Regular; string vertexId1 = this.ConvertToVertexId(graphCommand, "marko"); graphCommand.OutputFormat = OutputFormat.GraphSON; GraphTraversal traversal = graphCommand.g().V(vertexId1).Values("name").Path(); dynamic result = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault())[0]; Assert.AreEqual(vertexId1, (string)result["objects"][0].id); Assert.AreEqual("marko", (string)result["objects"][1]); } }
public void get_g_V_asXaX_hasXname_markoX_asXbX_hasXage_29X_asXcX_path() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.GraphSON; var vertex = this.getVertexString(graphCommand, "marko"); GraphTraversal traversal = graphCommand.g().V().As("a").Has("name", "marko").As("b").Has("age", 29).As("c").Path(); dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault()); Assert.AreEqual(1, results[0]["objects"].Count); Assert.AreEqual(vertex, results[0]["objects"][0].ToString()); } }
public void PathFromToTest() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.Regular; var vertex = this.getVertexString(graphCommand, "marko"); string vertexId = this.ConvertToVertexId(graphCommand, "marko"); graphCommand.OutputFormat = OutputFormat.Regular; GraphTraversal traversal = graphCommand.g().V(vertexId).As("a").Out().As("a").In().As("b").Out().As("c").In().As("d").Out() .As("d").CyclicPath().From("a").To("c").SimplePath().From("c").To("d").Path(); var results = traversal.Next(); Assert.AreEqual(13, results.Count); } }
public void get_g_V_out_out_path_byXnameX_byXageX() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.GraphSON; GraphTraversal traversal = graphCommand.g().V().Out().Out().Path().By("name").By("age"); dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault()); Assert.AreEqual(2, results.Count); int counter = 0; foreach (dynamic result in results) { List <object> actualList = new List <object>(); actualList.Add((string)result["objects"][0]); actualList.Add((int)result["objects"][1]); actualList.Add((string)result["objects"][2]); if (actualList.Last().Equals("ripple")) { CheckPathResults(new List <object> { "marko", 32, "ripple" }, actualList); counter++; } else { CheckPathResults(new List <object> { "marko", 32, "lop" }, actualList); counter++; } } Assert.AreEqual(2, counter); } }
private void AssertCommonA(GraphTraversal traversal) { dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next()[0]); Assert.AreEqual(1, results.Count); bool isContained = false; JObject markoChildren = TreeNodesContainName(results[0], "marko", out isContained); Assert.IsTrue(isContained); Assert.AreEqual(1, markoChildren.Count); JObject joshChildren = this.TreeNodesContainName(markoChildren, "josh", out isContained); Assert.IsTrue(isContained); this.TreeNodesContainName(joshChildren, "lop", out isContained); Assert.IsTrue(isContained); this.TreeNodesContainName(joshChildren, "ripple", out isContained); Assert.IsTrue(isContained); }
public void get_g_VX1X_out_path_byXageX_byXnameX() { using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection)) { graphCommand.OutputFormat = OutputFormat.Regular; string vertexId1 = this.ConvertToVertexId(graphCommand, "marko"); graphCommand.OutputFormat = OutputFormat.GraphSON; GraphTraversal traversal = graphCommand.g().V(vertexId1).Out().Path().By("age").By("name"); dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault()); Assert.AreEqual(3, results.Count); List <string> expected = new List <string>(); foreach (var result in results) { expected.Add((string)result["objects"][1]); } CheckUnOrderedResults(new List <string>() { "lop", "vadas", "josh" }, expected); } }
private void AssertCommonC(GraphTraversal traversal, GraphViewCommand graphCommand) { string vertexId = this.ConvertToVertexId(graphCommand, "marko"); dynamic results = JsonConvert.DeserializeObject <dynamic>(traversal.Next()[0]); Assert.AreEqual(1, results.Count); bool isContained = false; JObject markoChildren = TreeNodesContainId( results[0], this.ConvertToVertexId(graphCommand, "marko"), out isContained); Assert.IsTrue(isContained); Assert.AreEqual(1, markoChildren.Count); JObject joshChildren = this.TreeNodesContainId( markoChildren, this.ConvertToVertexId(graphCommand, "josh"), out isContained); Assert.IsTrue(isContained); this.TreeNodesContainId(joshChildren, this.ConvertToVertexId(graphCommand, "lop"), out isContained); Assert.IsTrue(isContained); this.TreeNodesContainId(joshChildren, this.ConvertToVertexId(graphCommand, "ripple"), out isContained); Assert.IsTrue(isContained); }