Exemplo n.º 1
0
 public void NotStore()
 {
     using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
     {
         GraphTraversal traversal = graphCommand.g().V().Not(GraphTraversal.__().HasLabel("person")).Store("x").Cap("x").Unfold();
         List <string>  result    = traversal.Next();
         foreach (var r in result)
         {
             Console.WriteLine(r);
         }
         Assert.AreEqual(2, result.Count);
     }
 }
Exemplo n.º 2
0
        public void HasVIdOutHasVIds()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                string id1 = this.ConvertToVertexId(GraphViewCommand, "marko");
                string id2 = this.ConvertToVertexId(GraphViewCommand, "vadas");
                string id3 = this.ConvertToVertexId(GraphViewCommand, "lop");

                var traversal = GraphViewCommand.g().V().HasId(id1).Out().HasId(id2, id3);

                Assert_g_VX1X_out_hasXid_2_3X(id2, id3, traversal);
            }
        }
Exemplo n.º 3
0
        public void VertexWithIdLocalOutEKnowsLimit1InVName()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                string          markoVertexId = this.ConvertToVertexId(command, "marko");
                GraphTraversal2 traversal     = command.g().V(markoVertexId).Local(GraphTraversal2.__().OutE("knows").Limit(1)).InV().Values("name");

                List <string> result = traversal.Next();

                Assert.AreEqual(1, result.Count);
                Assert.IsTrue(result[0].Equals("vadas") || result[0].Equals("josh"));
            }
        }
Exemplo n.º 4
0
        public void GetInVertexes()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = command.g()
                                            .V(this.ConvertToVertexId(command, "vadas"))
                                            .In()
                                            .Values("name");
                List <string> result = traversal.Next();

                AssertVadasIn(result);
            }
        }
        public void SelectMarvelQuery4()
        {
            GraphViewConnection connection = new GraphViewConnection("https://graphview.documents.azure.com:443/",
                                                                     "MqQnw4xFu7zEiPSD+4lLKRBQEaQHZcKsjlHxXn2b96pE/XlJ8oePGhjnOofj1eLpUdsfYgEhzhejk2rjH/+EKA==",
                                                                     "GroupMatch", "MarvelTest");
            GraphViewCommand graph = new GraphViewCommand(connection);
            var results            = graph.g().V().Has("name", "AVF 4").In("appeared").Has("weapon", "shield").Values("name").Next();

            foreach (var result in results)
            {
                Console.WriteLine(result);
            }
        }
Exemplo n.º 6
0
 public void EdgesHasLabelKnows()
 {
     using (GraphViewCommand command = new GraphViewCommand(graphConnection))
     {
         GraphTraversal2 traversal = command.g().E().HasLabel("knows");
         List <string>   result    = traversal.Label().Next();
         Assert.AreEqual(2, result.Count);
         foreach (string res in result)
         {
             Assert.AreEqual("knows", res);
         }
     }
 }
Exemplo n.º 7
0
        public void GetVertexByIdList()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                string[]        expectedNames = new[] { "marko", "vadas", "lop" };
                GraphTraversal2 traversal     = command.g()
                                                .V(expectedNames.Select(n => this.ConvertToVertexId(command, n)).ToArray <object>())
                                                .Values("name");
                List <string> result = traversal.Next();

                CheckUnOrderedResults(expectedNames, result);
            }
        }
Exemplo n.º 8
0
        public void VerticesStoreAByOutECountOutOutStoreAByInECreatedValuesWeightSumCapA()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = graphCommand.g().V().Store("a").By(GraphTraversal.__().OutE("created").Count()).Out().Out().Store("a").By(GraphTraversal.__().InE("created").Values("weight").Sum()).Cap("a");

                var result         = traversal.Next().First().Trim('[', ']').Split(',').Select(r => r.Trim(' '));
                var expectedResult = new List <string> {
                    "2", "1", "1", "1", "1", "0", "0", "0"
                };
                CheckUnOrderedResults(expectedResult, result);
            }
        }
Exemplo n.º 9
0
 public void NoneReversedEdges()
 {
     using (GraphViewCommand command = new GraphViewCommand(graphConnection))
     {
         var traversal = command.g().V().Optional(GraphTraversal.__().OutE()).Union().Out();
         var result    = traversal.Next();
         foreach (var r in result)
         {
             Console.WriteLine(r);
         }
         Debugger.Break();
     }
 }
Exemplo n.º 10
0
        public void ConstantWithChoose()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().V().Choose(
                    GraphTraversal.__().HasLabel("person"),
                    GraphTraversal.__().Values("name"),
                    GraphTraversal.__().Constant("inhuman"));
                var result = traversal.Next();

                AbstractGremlinTest.CheckUnOrderedResults(new string[] { "marko", "vadas", "inhuman", "josh", "inhuman", "peter" }, result);
            }
        }
Exemplo n.º 11
0
        public void VerticesStoreAByNameOutCapA()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = graphCommand.g().V().Store("a").By("name").Out().Cap("a");

                var result         = traversal.Next().First().Trim('[', ']').Split(',').Select(r => r.Trim(' '));
                var expectedResult = new List <string> {
                    "marko", "josh", "peter", "lop", "ripple", "vadas"
                };
                CheckUnOrderedResults(expectedResult, result);
            }
        }
Exemplo n.º 12
0
 public void IsAggregate()
 {
     using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
     {
         GraphTraversal traversal = graphCommand.g().V().Values("age").Is(Predicate.lte(30)).Aggregate("x").Cap("x").Unfold();
         List <string>  result    = traversal.Next();
         foreach (var r in result)
         {
             Console.WriteLine(r);
         }
         Assert.AreEqual(2, result.Count);
     }
 }
Exemplo n.º 13
0
        public void FilterPath()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = graphCommand.g().V().Aggregate("x").Has("lang").Path();
                var result    = traversal.Next();

                foreach (var r in result)
                {
                    Console.WriteLine(r);
                }
            }
        }
Exemplo n.º 14
0
 public void FlatMapFilter()
 {
     using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
     {
         GraphTraversal traversal = graphCommand.g().V().FlatMap(GraphTraversal.__().Aggregate("x").Has("age")).Cap("x").Unfold();
         List <string>  result    = traversal.Next();
         foreach (var r in result)
         {
             Console.WriteLine(r);
         }
         Assert.AreEqual(6, result.Count);
     }
 }
Exemplo n.º 15
0
        public void DedupWithBoth()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().V()
                                .Both()
                                .Dedup()
                                .Values("name");
                var result = traversal.Next();

                AbstractGremlinTest.CheckUnOrderedResults(new string[] { "vadas", "josh", "lop", "marko", "peter", "ripple" }, result);
            }
        }
Exemplo n.º 16
0
        public void BasicFold()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                graphCommand.OutputFormat = OutputFormat.GraphSON;
                var     traversal = graphCommand.g().V().Fold();
                dynamic result    = JsonConvert.DeserializeObject <dynamic>(traversal.Next().FirstOrDefault());
                graphCommand.OutputFormat = OutputFormat.Regular;

                Assert.AreEqual(1, ((JArray)result).Count);
                Assert.AreEqual(6, ((JArray)result[0]).Count);
            }
        }
Exemplo n.º 17
0
        public void EdgesHasEIdHasLabelKnows()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                string edgeId = this.ConvertToEdgeId(command, "marko", "knows", "vadas");

                GraphTraversal2 traversal = command.g().E().HasId(edgeId).HasLabel("knows");

                List <string> result = traversal.Label().Next();
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual("knows", result.FirstOrDefault());
            }
        }
Exemplo n.º 18
0
        public void HasVertexIdOutAsHereHasLangJavaSelectHereName()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                string vertexId1 = this.ConvertToVertexId(graphCommand, "josh");
                var    traversal = graphCommand.g().V().HasId(vertexId1).Out().As("here").Has("lang", "java").Select("here").Values("name");

                var result = traversal.Next();
                Assert.AreEqual(2, result.Count);
                Assert.IsTrue(result.Contains("ripple"));
                Assert.IsTrue(result.Contains("lop"));
            }
        }
Exemplo n.º 19
0
        public void GetBothVertexes()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = command.g()
                                            .V(this.ConvertToVertexId(command, "josh"))
                                            .Both()
                                            .Values("name");
                List <string> result = traversal.Next();

                CheckUnOrderedResults(new[] { "marko", "ripple", "lop" }, result);
            }
        }
Exemplo n.º 20
0
        public void VerticesAsAOutCreatedWhereAsANameIsJoshInCreatedName()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = graphCommand.g().V().As("a")
                                            .Out("created")
                                            .Where(GraphTraversal2.__().As("a").Values("name").Is("josh"))
                                            .In("created").Values("name");

                List <string> result = traversal.Next();
                CheckUnOrderedResults(new [] { "josh", "josh", "marko", "peter" }, result);
            }
        }
Exemplo n.º 21
0
        public void GetOutVertexes()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2 traversal = command.g()
                                            .V(this.ConvertToVertexId(command, "marko"))
                                            .Out()
                                            .Values("name");
                List <string> result = traversal.Next();

                AssertMarkoOut(result);
            }
        }
Exemplo n.º 22
0
        public void GetOutVertexes()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = graphCommand.g()
                                .V(this.ConvertToVertexId(graphCommand, "marko"))
                                .Out()
                                .Values("name");
                var result = traversal.Next();

                AssertMarkoOut(result);
            }
        }
Exemplo n.º 23
0
        public void CoalesceWithNonexistentTraversals()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().V()
                                .Coalesce(
                    GraphTraversal.__().Out("foo"),
                    GraphTraversal.__().Out("bar"));
                var result = traversal.Next();

                Assert.IsFalse(result.Any());
            }
        }
Exemplo n.º 24
0
        public void GetInVertexes()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = graphCommand.g()
                                .V(this.ConvertToVertexId(graphCommand, "vadas"))
                                .In()
                                .Values("name");
                var result = traversal.Next();

                AssertVadasIn(result);
            }
        }
Exemplo n.º 25
0
        public void HasVIdOutHasVId()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                string markoVertexId = this.ConvertToVertexId(GraphViewCommand, "marko");
                string vadasVertexId = this.ConvertToVertexId(GraphViewCommand, "vadas");

                var traversal = GraphViewCommand.g().V().HasId(markoVertexId)
                                .Out().HasId(vadasVertexId);

                this.AssertVadasAsOnlyValueReturned(GraphViewCommand, traversal);
            }
        }
Exemplo n.º 26
0
        public void get_g_V_groupXaX_byXlabelX_byXoutE_weight_sumX_capXaX()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                command.OutputFormat = OutputFormat.GraphSON;
                GraphTraversal2 traversal = command.g().V().Group("a").By("label").By(GraphTraversal2.__().OutE().Values("weight").Sum()).Cap("a");
                dynamic         results   = JsonConvert.DeserializeObject <dynamic>(traversal.FirstOrDefault());

                Assert.AreEqual(1, results.Count);
                Assert.AreEqual(0.0, double.Parse(results[0]["software"].ToString()));
                Assert.AreEqual(3.5, double.Parse(results[0]["person"].ToString()));
            }
        }
Exemplo n.º 27
0
        public void InHasIdNEQVId()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                string vertexId = this.ConvertToVertexId(GraphViewCommand, "marko");

                var traversal = GraphViewCommand.g().V().In().Has("id", Predicate.neq(vertexId));

                var result = traversal.Values("name").Next();
                Assert.AreEqual(3, result.Count);
                Assert.IsTrue(result.Contains("josh") && result.Contains("peter"));
            }
        }
Exemplo n.º 28
0
        public void VertexWithIdLocalBothELimit1OtherVName()
        {
            using (GraphViewCommand graphCommand = new GraphViewCommand(graphConnection))
            {
                string joshVertexId = this.ConvertToVertexId(graphCommand, "josh");
                var    traversal    = graphCommand.g().V(joshVertexId).Local(GraphTraversal.__().BothE().Limit(1)).OtherV().Values("name");

                var result = traversal.Next();

                Assert.AreEqual(1, result.Count);
                Assert.IsTrue(result[0].Equals("marko") || result[0].Equals("ripple") || result[0].Equals("lop"));
            }
        }
Exemplo n.º 29
0
        public void VerticesLocalOutECount()
        {
            using (GraphViewCommand command = new GraphViewCommand(graphConnection))
            {
                GraphTraversal2    traversal = command.g().V().Local(GraphTraversal2.__().OutE().Count());
                IEnumerable <long> result    = traversal.Next().Select(r => long.Parse(r));

                List <long> expectedResult = new List <long> {
                    3, 0, 0, 0, 1, 2
                };
                CheckUnOrderedResults(expectedResult, result);
            }
        }
Exemplo n.º 30
0
        public void VerticesValuesAgeIsGTE29IsLT34()
        {
            using (GraphViewCommand GraphViewCommand = new GraphViewCommand(graphConnection))
            {
                var traversal = GraphViewCommand.g().V().Values("age").Is(Predicate.gte(29)).Is(Predicate.lt(34));

                var result = traversal.Next();
                Assert.AreEqual(2, result.Count);
                CheckUnOrderedResults(new List <string> {
                    "29", "32"
                }, result);
            }
        }