TINKERPOP-2053 Added OptionsStrategy support for .NET
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/f134c8a8 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/f134c8a8 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/f134c8a8 Branch: refs/heads/TINKERPOP-2053 Commit: f134c8a8fdae5a9fff009dd4a3100d36da3e86a7 Parents: a21cde1 Author: Stephen Mallette <sp...@genoprime.com> Authored: Tue Oct 2 12:42:49 2018 -0400 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Fri Oct 5 10:30:19 2018 -0400 ---------------------------------------------------------------------- .../Strategy/Decoration/OptionsStrategy.cs | 53 ++++++++++++++++++++ .../GraphTraversalTests.cs | 21 ++++++++ 2 files changed, 74 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f134c8a8/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/OptionsStrategy.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/OptionsStrategy.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/OptionsStrategy.cs new file mode 100644 index 0000000..a5d70b0 --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/Strategy/Decoration/OptionsStrategy.cs @@ -0,0 +1,53 @@ +#region License + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#endregion + +using System.Collections.Generic; + +namespace Gremlin.Net.Process.Traversal.Strategy.Decoration +{ + /// <summary> + /// OptionsStrategy makes no changes to the traversal itself - it just carries configuration information + /// at the traversal level. + /// </summary> + public class OptionsStrategy : AbstractTraversalStrategy + { + /// <summary> + /// Initializes a new instance of the <see cref="OptionsStrategy" /> class. + /// </summary> + public OptionsStrategy() + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="OptionsStrategy" /> class. + /// </summary> + /// <param name="options">Specifies the options for the traversal.</param> + public OptionsStrategy(IDictionary<string,object> options) + { + foreach(var item in options) + { + Configuration[item.Key] = item.Value; + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f134c8a8/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs index 27ac0f5..e46fa22 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs @@ -27,6 +27,7 @@ using System.Threading.Tasks; using Gremlin.Net.Process.Traversal; using Gremlin.Net.Structure; using Xunit; +using Gremlin.Net.Process.Traversal.Strategy.Decoration; namespace Gremlin.Net.IntegrationTest.Process.Traversal.DriverRemoteConnection { @@ -181,6 +182,26 @@ namespace Gremlin.Net.IntegrationTest.Process.Traversal.DriverRemoteConnection var count = g.V().Has(b.Of("propertyKey", "name"), b.Of("propertyValue", "marko")).OutE().Count().Next(); Assert.Equal(3, count); + } + + [Fact] + public void ShouldUseOptionsInTraversal() + { + // smoke test to validate serialization of OptionsStrategy. no way to really validate this from an integration + // test perspective because there's no way to access the internals of the strategy via bytecode + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var options = new Dictionary<string,object> + { + {"x", "test"}, + {"y", true} + }; + var g = graph.Traversal().WithRemote(connection); + + var b = new Bindings(); + var count = g.WithStrategies(new OptionsStrategy(options)).V().Count().Next(); + + Assert.Equal(6, count); } [Fact]