Skip to content

Commit 0e6b408

Browse files
committed
Address comments, added overload for property with cardinality and map
1 parent 35c7815 commit 0e6b408

6 files changed

Lines changed: 60 additions & 5 deletions

File tree

gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,30 @@ public GraphTraversal<TStart, TEnd> Property (IDictionary<object, object> map)
18011801
return Wrap<TStart, TEnd>(this);
18021802
}
18031803

1804+
/// <summary>
1805+
/// Adds the property step to this <see cref="GraphTraversal{SType, EType}" />.
1806+
/// When a <see cref="IDictionary{TKey, TValue}" /> is supplied, each key/value pair in the map
1807+
/// will be added as a property with the given <see cref="Cardinality" />.
1808+
/// A value may be a <see cref="CardinalityValue" /> to override the cardinality for that entry.
1809+
/// </summary>
1810+
public GraphTraversal<TStart, TEnd> Property(Cardinality cardinality, IDictionary<object, object> map)
1811+
{
1812+
if (map == null) throw new ArgumentNullException(nameof(map));
1813+
1814+
foreach (var entry in map)
1815+
{
1816+
if (entry.Value is CardinalityValue cardVal)
1817+
{
1818+
Property(cardVal.Cardinality!, entry.Key, cardVal.Value);
1819+
}
1820+
else
1821+
{
1822+
Property(cardinality, entry.Key, entry.Value);
1823+
}
1824+
}
1825+
return Wrap<TStart, TEnd>(this);
1826+
}
1827+
18041828

18051829
/// <summary>
18061830
/// Adds the propertyMap step to this <see cref="GraphTraversal{SType, EType}" />.

gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversalSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public GraphTraversalSource(ICollection<ITraversalStrategy> traversalStrategies,
7575
GremlinLang = gremlinLang;
7676
}
7777

78-
public GraphTraversalSource(ICollection<ITraversalStrategy> traversalStrategies,
79-
GremlinLang gremlinLang, IRemoteConnection connection)
78+
public GraphTraversalSource(ICollection<ITraversalStrategy> traversalStrategies, GremlinLang gremlinLang,
79+
IRemoteConnection connection)
8080
: this(traversalStrategies.Where(strategy => strategy.GetType() != typeof(RemoteStrategy)).ToList(),
8181
gremlinLang)
8282
{

gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GremlinLang.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ private string ArgAsString(object? arg)
180180

181181
if (arg is byte byteVal)
182182
return $"{byteVal}B";
183+
if (arg is sbyte sbyteVal)
184+
return $"{sbyteVal}B";
183185
if (arg is short shortVal)
184186
return $"{shortVal}S";
185187
if (arg is int intVal)

gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/BytecodeGenerationTests.cs renamed to gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/GremlinLangGeneration/GremlinLangGenerationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
using Gremlin.Net.Process.Traversal;
2626
using Xunit;
2727

28-
namespace Gremlin.Net.IntegrationTest.Process.Traversal.BytecodeGeneration
28+
namespace Gremlin.Net.IntegrationTest.Process.Traversal.GremlinLangGeneration
2929
{
30-
public class BytecodeGenerationTests
30+
public class GremlinLangGenerationTests
3131
{
3232
[Fact]
3333
public void GraphTraversalStepsShouldUnrollParamsParameters()

gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/BytecodeGeneration/StrategiesTests.cs renamed to gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/GremlinLangGeneration/StrategiesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
using Gremlin.Net.Process.Traversal.Strategy.Verification;
2929
using Xunit;
3030

31-
namespace Gremlin.Net.IntegrationTest.Process.Traversal.BytecodeGeneration
31+
namespace Gremlin.Net.IntegrationTest.Process.Traversal.GremlinLangGeneration
3232
{
3333
public class StrategiesTests
3434
{

gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/GremlinLangTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,5 +1012,34 @@ public void GValue_reuse_same_instance()
10121012
Assert.Equal("g.inject(ids).V(ids)", result.GetGremlin());
10131013
Assert.True(result.Parameters.ContainsKey("ids"));
10141014
}
1015+
1016+
// --- Cardinality with Map Tests ---
1017+
1018+
[Fact]
1019+
public void g_V_1_Property_List_Map_With_CardinalityValue()
1020+
{
1021+
var map = new Dictionary<object, object>
1022+
{
1023+
{ "age", CardinalityValue.Single(36) },
1024+
{ "city", "wilmington" },
1025+
{ "state", "delaware" }
1026+
};
1027+
Assert.Equal(
1028+
"g.V(\"1\").property(Cardinality.single,\"age\",36).property(Cardinality.list,\"city\",\"wilmington\").property(Cardinality.list,\"state\",\"delaware\")",
1029+
_g.V("1").Property(Cardinality.List, map).GremlinLang.GetGremlin());
1030+
}
1031+
1032+
[Fact]
1033+
public void g_V_1_Property_Set_Map_All_Same_Cardinality()
1034+
{
1035+
var map = new Dictionary<object, object>
1036+
{
1037+
{ "city", "wilmington" },
1038+
{ "state", "delaware" }
1039+
};
1040+
Assert.Equal(
1041+
"g.V(\"1\").property(Cardinality.set,\"city\",\"wilmington\").property(Cardinality.set,\"state\",\"delaware\")",
1042+
_g.V("1").Property(Cardinality.Set, map).GremlinLang.GetGremlin());
1043+
}
10151044
}
10161045
}

0 commit comments

Comments
 (0)