You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/11/30 12:06:31 UTC

[11/15] tinkerpop git commit: TINKERPOP-1734 Added DSL tests for anonymous traversals

TINKERPOP-1734 Added DSL tests for anonymous traversals

Can't extend __ with extension methods and can't extend static classes in C# so not sure what else to do here. The only thing you can do is write wrapper methods in your DSL for the __ methods which kinda stinks. I guess we could do code generation here, but doesn't seem worth it. Not sure.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/d68c9aa4
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d68c9aa4
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d68c9aa4

Branch: refs/heads/TINKERPOP-1734
Commit: d68c9aa430363df7df940c96da5d155337756336
Parents: 2f345ca
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Nov 29 15:45:41 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Nov 30 07:05:40 2017 -0500

----------------------------------------------------------------------
 .../Process/Traversal/Dsl/DslTest.cs            | 32 ++++++++++++++++++--
 1 file changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d68c9aa4/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/Dsl/DslTest.cs
----------------------------------------------------------------------
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/Dsl/DslTest.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/Dsl/DslTest.cs
index d1541ef..d92e680 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/Dsl/DslTest.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/Dsl/DslTest.cs
@@ -30,13 +30,35 @@ using Xunit;
 namespace Gremlin.Net.IntegrationTest.Process.Traversal.Dsl {
 
     public static class SocialTraversal {
-        public static GraphTraversal<Vertex,Vertex> knows(this GraphTraversal<Vertex,Vertex> t, string personName) {
+        public static GraphTraversal<Vertex,Vertex> Knows(this GraphTraversal<Vertex,Vertex> t, string personName) {
             return t.Out("knows").HasLabel("person").Has("name", personName);
         }
+
+        public static GraphTraversal<Vertex, int> YoungestFriendsAge(this GraphTraversal<Vertex,Vertex> t) {
+            return t.Out("knows").HasLabel("person").Values<int>("age").Min<int>();
+        }
+
+        public static GraphTraversal<Vertex,long> CreatedAtLeast(this GraphTraversal<Vertex,Vertex> t, long number) {
+            return t.OutE("created").Count().Is(P.Gte(number));
+        }
+    }
+
+    public static class __Social {
+        public static GraphTraversal<object,Vertex> Knows(string personName) {
+            return __.Out("knows").HasLabel("person").Has("name", personName);
+        }
+
+        public static GraphTraversal<object, int> YoungestFriendsAge() {
+            return __.Out("knows").HasLabel("person").Values<int>("age").Min<int>();
+        }
+
+        public static GraphTraversal<object,long> CreatedAtLeast(long number) {
+            return __.OutE("created").Count().Is(P.Gte(number));
+        }
     }
 
     public static class SocialTraversalSource {
-        public static GraphTraversal<Vertex,Vertex> persons(this GraphTraversalSource g, params string[] personNames) {
+        public static GraphTraversal<Vertex,Vertex> Persons(this GraphTraversalSource g, params string[] personNames) {
             GraphTraversal<Vertex,Vertex> t = g.V().HasLabel("person");
 
             if (personNames.Length > 0) {    
@@ -56,7 +78,11 @@ namespace Gremlin.Net.IntegrationTest.Process.Traversal.Dsl {
             var connection = _connectionFactory.CreateRemoteConnection();
             var social = graph.Traversal().WithRemote(connection);
 
-            Assert.NotNull(social.persons("marko").knows("josh").Next());
+            Assert.NotNull(social.Persons("marko").Knows("josh").Next());
+            Assert.Equal(27, social.Persons("marko").YoungestFriendsAge().Next());
+            Assert.Equal(4, social.Persons().Count().Next());
+            Assert.Equal(2, social.Persons("marko", "josh").Count().Next());
+            Assert.Equal(1, social.Persons().Filter(__Social.CreatedAtLeast(2)).Count().Next());
         }
     }
 }
\ No newline at end of file