Features discovery fix and DecimalConverter tests

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

Branch: refs/heads/tp32
Commit: 2e5d893f7fb73b9f8877e35bfacd12cb4eca4483
Parents: 74d7ad6
Author: Jorge Bay Gondra <jorgebaygon...@gmail.com>
Authored: Mon Dec 4 12:10:55 2017 +0100
Committer: Jorge Bay Gondra <jorgebaygon...@gmail.com>
Committed: Mon Dec 4 12:10:55 2017 +0100

----------------------------------------------------------------------
 .../Structure/IO/GraphSON/DecimalConverter.cs   |  1 +
 .../Structure/IO/GraphSON/GraphSONReader.cs     |  6 ++++-
 .../Structure/IO/GraphSON/NumberConverter.cs    |  8 ++++++-
 .../Gherkin/GherkinTestRunner.cs                |  4 ++--
 .../IO/GraphSON/GraphSONReaderTests.cs          | 24 ++++++++++++++++++++
 .../IO/GraphSON/GraphSONWriterTests.cs          | 10 ++++++++
 6 files changed, 49 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2e5d893f/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DecimalConverter.cs
----------------------------------------------------------------------
diff --git 
a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DecimalConverter.cs 
b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DecimalConverter.cs
index 82cc646..6860137 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DecimalConverter.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/DecimalConverter.cs
@@ -30,5 +30,6 @@ namespace Gremlin.Net.Structure.IO.GraphSON
         protected override string GraphSONTypeName => "BigDecimal";
         protected override Type HandledType => typeof(decimal);
         protected override string Prefix => "gx";
+        protected override bool StringifyValue => true;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2e5d893f/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
----------------------------------------------------------------------
diff --git 
a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs 
b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
index 60bafed..10835c8 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONReader.cs
@@ -113,7 +113,11 @@ namespace Gremlin.Net.Structure.IO.GraphSON
         private dynamic ReadTypedValue(JToken typedValue)
         {
             var graphSONType = (string) typedValue[GraphSONTokens.TypeKey];
-            return 
_deserializerByGraphSONType[graphSONType].Objectify(typedValue[GraphSONTokens.ValueKey],
 this);
+            if (!_deserializerByGraphSONType.TryGetValue(graphSONType, out var 
deserializer))
+            {
+                throw new InvalidOperationException($"Deserializer for 
\"{graphSONType}\" not found");
+            }
+            return deserializer.Objectify(typedValue[GraphSONTokens.ValueKey], 
this);
         }
 
         private dynamic ReadDictionary(JToken jtokenDict)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2e5d893f/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs
----------------------------------------------------------------------
diff --git 
a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs 
b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs
index 294db12..53dad94 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/NumberConverter.cs
@@ -32,6 +32,7 @@ namespace Gremlin.Net.Structure.IO.GraphSON
         protected abstract string GraphSONTypeName { get; }
         protected abstract Type HandledType { get; }
         protected virtual string Prefix => "g";
+        protected virtual bool StringifyValue => false;
 
         public dynamic Objectify(JToken graphsonObject, GraphSONReader reader)
         {
@@ -40,7 +41,12 @@ namespace Gremlin.Net.Structure.IO.GraphSON
 
         public Dictionary<string, dynamic> Dictify(dynamic objectData, 
GraphSONWriter writer)
         {
-            return GraphSONUtil.ToTypedValue(GraphSONTypeName, objectData, 
Prefix);
+            object value = objectData;
+            if (StringifyValue)
+            {
+                value = value?.ToString();
+            }
+            return GraphSONUtil.ToTypedValue(GraphSONTypeName, value, Prefix);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2e5d893f/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
----------------------------------------------------------------------
diff --git 
a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
index 3610199..9cb3cf0 100644
--- 
a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
+++ 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
@@ -365,11 +365,11 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
                 dir.Parent != null;
                 dir = dir.Parent)
             {
-                if (dir.Name == "gremlin-dotnet" && dir.Parent?.Name == 
"tinkerpop")
+                if (dir.Name == "gremlin-dotnet" && 
dir.GetFiles("pom.xml").Length == 1)
                 {
                     rootDir = dir.Parent;
                     break;
-                }   
+                }
             }
             if (rootDir == null)
             {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2e5d893f/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
----------------------------------------------------------------------
diff --git 
a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
 
b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
index 747a94e..d82dc86 100644
--- 
a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
+++ 
b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs
@@ -164,6 +164,30 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON
         }
 
         [Fact]
+        public void ShouldDeserializeDecimal()
+        {
+            var serializedValue = 
"{\"@type\":\"gx:BigDecimal\",\"@value\":-8.201}";
+            var reader = CreateStandardGraphSONReader();
+
+            var jObject = JObject.Parse(serializedValue);
+            decimal deserializedValue = reader.ToObject(jObject);
+
+            Assert.Equal(-8.201M, deserializedValue);
+        }
+
+        [Fact]
+        public void ShouldDeserializeDecimalValueAsString()
+        {
+            var serializedValue = 
"{\"@type\":\"gx:BigDecimal\",\"@value\":\"7.50\"}";
+            var reader = CreateStandardGraphSONReader();
+
+            var jObject = JObject.Parse(serializedValue);
+            decimal deserializedValue = reader.ToObject(jObject);
+
+            Assert.Equal(7.5M, deserializedValue);
+        }
+
+        [Fact]
         public void ShouldDeserializeList()
         {
             var serializedValue = 
"[{\"@type\":\"g:Int32\",\"@value\":5},{\"@type\":\"g:Int32\",\"@value\":6}]";

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2e5d893f/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
----------------------------------------------------------------------
diff --git 
a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
 
b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
index 4cd831f..cf17b3c 100644
--- 
a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
+++ 
b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs
@@ -80,6 +80,16 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON
         }
 
         [Fact]
+        public void ShouldSerializeDecimal()
+        {
+            var writer = CreateStandardGraphSONWriter();
+
+            var graphSon = writer.WriteObject(6.5M);
+
+            Assert.Equal("{\"@type\":\"gx:BigDecimal\",\"@value\":\"6.5\"}", 
graphSon);
+        }
+
+        [Fact]
         public void ShouldSerializeBoolean()
         {
             var writer = CreateStandardGraphSONWriter();

Reply via email to