http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalSerializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalSerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalSerializer.cs new file mode 100644 index 0000000..cc809aa --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalSerializer.cs @@ -0,0 +1,38 @@ +#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; +using Gremlin.Net.Process.Traversal; + +namespace Gremlin.Net.Structure.IO.GraphSON +{ + internal class TraversalSerializer : IGraphSONSerializer + { + public Dictionary<string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer) + { + ITraversal traversal = objectData; + var bytecode = traversal.Bytecode; + return writer.ToDict(bytecode); + } + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalStrategySerializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalStrategySerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalStrategySerializer.cs new file mode 100644 index 0000000..9b70978 --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalStrategySerializer.cs @@ -0,0 +1,37 @@ +#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; +using Gremlin.Net.Process.Traversal.Strategy; + +namespace Gremlin.Net.Structure.IO.GraphSON +{ + internal class TraversalStrategySerializer : IGraphSONSerializer + { + public Dictionary<string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer) + { + AbstractTraversalStrategy strategy = objectData; + return GraphSONUtil.ToTypedValue(strategy.StrategyName, writer.ToDict(strategy.Configuration)); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraverserReader.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraverserReader.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraverserReader.cs new file mode 100644 index 0000000..abbb45f --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraverserReader.cs @@ -0,0 +1,38 @@ +#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 Gremlin.Net.Process.Traversal; +using Newtonsoft.Json.Linq; + +namespace Gremlin.Net.Structure.IO.GraphSON +{ + internal class TraverserReader : IGraphSONDeserializer + { + public dynamic Objectify(JToken graphsonObject, GraphSONReader reader) + { + var bulkObj = reader.ToObject(graphsonObject["bulk"]); + var valueObj = reader.ToObject(graphsonObject["value"]); + return new Traverser(valueObj, bulkObj); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/UuidDeserializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/UuidDeserializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/UuidDeserializer.cs new file mode 100644 index 0000000..82ca43d --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/UuidDeserializer.cs @@ -0,0 +1,36 @@ +#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; +using Newtonsoft.Json.Linq; + +namespace Gremlin.Net.Structure.IO.GraphSON +{ + internal class UuidDeserializer : IGraphSONDeserializer + { + public dynamic Objectify(JToken graphsonObject, GraphSONReader reader) + { + return graphsonObject.ToObject<Guid>(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/UuidSerializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/UuidSerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/UuidSerializer.cs new file mode 100644 index 0000000..5f31bfc --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/UuidSerializer.cs @@ -0,0 +1,37 @@ +#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; +using System.Collections.Generic; + +namespace Gremlin.Net.Structure.IO.GraphSON +{ + internal class UuidSerializer : IGraphSONSerializer + { + public Dictionary<string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer) + { + Guid guid = objectData; + return GraphSONUtil.ToTypedValue("UUID", guid); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexDeserializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexDeserializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexDeserializer.cs new file mode 100644 index 0000000..f1d64ed --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexDeserializer.cs @@ -0,0 +1,37 @@ +#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 Newtonsoft.Json.Linq; + +namespace Gremlin.Net.Structure.IO.GraphSON +{ + internal class VertexDeserializer : IGraphSONDeserializer + { + public dynamic Objectify(JToken graphsonObject, GraphSONReader reader) + { + var id = reader.ToObject(graphsonObject["id"]); + var label = (string) graphsonObject["label"] ?? Vertex.DefaultLabel; + return new Vertex(id, label); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexPropertyDeserializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexPropertyDeserializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexPropertyDeserializer.cs new file mode 100644 index 0000000..7c2505f --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexPropertyDeserializer.cs @@ -0,0 +1,41 @@ +#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 Newtonsoft.Json.Linq; + +namespace Gremlin.Net.Structure.IO.GraphSON +{ + internal class VertexPropertyDeserializer : IGraphSONDeserializer + { + public dynamic Objectify(JToken graphsonObject, GraphSONReader reader) + { + var id = reader.ToObject(graphsonObject["id"]); + var label = (string) graphsonObject["label"]; + var value = reader.ToObject(graphsonObject["value"]); + var vertex = graphsonObject["vertex"] != null + ? new Vertex(reader.ToObject(graphsonObject["vertex"])) + : null; + return new VertexProperty(id, label, value, vertex); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexPropertySerializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexPropertySerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexPropertySerializer.cs new file mode 100644 index 0000000..12cc7ac --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexPropertySerializer.cs @@ -0,0 +1,43 @@ +#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.Structure.IO.GraphSON +{ + internal class VertexPropertySerializer : IGraphSONSerializer + { + public Dictionary<string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer) + { + VertexProperty vertexProperty = objectData; + var valueDict = new Dictionary<string, dynamic> + { + {"id", writer.ToDict(vertexProperty.Id)}, + {"label", vertexProperty.Label}, + {"value", writer.ToDict(vertexProperty.Value)}, + {"vertex", writer.ToDict(vertexProperty.Vertex.Id)} + }; + return GraphSONUtil.ToTypedValue(nameof(VertexProperty), valueDict); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexSerializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexSerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexSerializer.cs new file mode 100644 index 0000000..d3ad9f1 --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexSerializer.cs @@ -0,0 +1,41 @@ +#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.Structure.IO.GraphSON +{ + internal class VertexSerializer : IGraphSONSerializer + { + public Dictionary<string, dynamic> Dictify(dynamic objectData, GraphSONWriter writer) + { + Vertex vertex = objectData; + var vertexDict = new Dictionary<string, dynamic> + { + {"id", writer.ToDict(vertex.Id)}, + {"label", writer.ToDict(vertex.Label)} + }; + return GraphSONUtil.ToTypedValue(nameof(Vertex), vertexDict); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/Path.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/Path.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/Path.cs new file mode 100644 index 0000000..01a436a --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/Path.cs @@ -0,0 +1,193 @@ +#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; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Gremlin.Net.Process.Traversal; + +namespace Gremlin.Net.Structure +{ + /// <summary> + /// A Path denotes a particular walk through a graph as defined by a <see cref="ITraversal" />. + /// </summary> + /// <remarks> + /// In abstraction, any Path implementation maintains two lists: a list of sets of labels and a list of objects. + /// The list of labels are the labels of the steps traversed. The list of objects are the objects traversed. + /// </remarks> + public class Path : IReadOnlyList<object>, IEquatable<Path> + { + /// <summary> + /// Initializes a new instance of the <see cref="Path" /> class. + /// </summary> + /// <param name="labels">The labels associated with the path</param> + /// <param name="objects">The objects in the <see cref="Path" />.</param> + public Path(List<List<string>> labels, List<object> objects) + { + Labels = labels; + Objects = objects; + } + + /// <summary> + /// Gets an ordered list of the labels associated with the <see cref="Path" />. + /// </summary> + public List<List<string>> Labels { get; } + + /// <summary> + /// Gets an ordered list of the objects in the <see cref="Path" />. + /// </summary> + public List<object> Objects { get; } + + /// <summary> + /// Gets the object associated with the particular label of the path. + /// </summary> + /// <remarks>If the path has multiple labels of the type, then get a collection of those objects.</remarks> + /// <param name="label">The label of the path</param> + /// <returns>The object associated with the label of the path</returns> + /// <exception cref="KeyNotFoundException">Thrown if the path does not contain the label.</exception> + public object this[string label] + { + get + { + var objFound = TryGetValue(label, out object obj); + if (!objFound) + throw new KeyNotFoundException($"The step with label {label} does not exist"); + return obj; + } + } + + /// <inheritdoc /> + public bool Equals(Path other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return ObjectsEqual(other.Objects) && LabelsEqual(other.Labels); + } + + /// <summary> + /// Get the object associated with the specified index into the path. + /// </summary> + /// <param name="index">The index of the path</param> + /// <returns>The object associated with the index of the path</returns> + public dynamic this[int index] => Objects[index]; + + /// <summary> + /// Gets the number of steps in the path. + /// </summary> + public int Count => Objects.Count; + + /// <inheritdoc /> + public IEnumerator<object> GetEnumerator() + { + return ((IReadOnlyList<object>) Objects).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IReadOnlyList<object>) Objects).GetEnumerator(); + } + + /// <inheritdoc /> + public override string ToString() + { + return $"[{string.Join(", ", Objects)}]"; + } + + /// <summary> + /// Returns true if the path has the specified label, else return false. + /// </summary> + /// <param name="key">The label to search for.</param> + /// <returns>True if the label exists in the path.</returns> + public bool ContainsKey(string key) + { + return Labels.Any(objLabels => objLabels.Contains(key)); + } + + /// <summary> + /// Tries to get the object associated with the particular label of the path. + /// </summary> + /// <remarks>If the path has multiple labels of the type, then get a collection of those objects.</remarks> + /// <param name="label">The label of the path.</param> + /// <param name="value">The object associated with the label of the path.</param> + /// <returns>True, if an object was found for the label.</returns> + public bool TryGetValue(string label, out object value) + { + value = null; + for (var i = 0; i < Labels.Count; i++) + { + if (!Labels[i].Contains(label)) continue; + if (value == null) + value = Objects[i]; + else if (value.GetType() == typeof(List<object>)) + ((List<object>) value).Add(Objects[i]); + else + value = new List<object> {value, Objects[i]}; + } + return value != null; + } + + private bool ObjectsEqual(IReadOnlyCollection<object> otherObjects) + { + if (Objects == null) + return otherObjects == null; + return Objects.SequenceEqual(otherObjects); + } + + private bool LabelsEqual(IReadOnlyList<List<string>> otherLabels) + { + if (Labels == null) + return otherLabels == null; + if (Labels.Count != otherLabels.Count) + return false; + var foundUnequalObjLabels = Labels.Where((objLabels, i) => !objLabels.SequenceEqual(otherLabels[i])).Any(); + return !foundUnequalObjLabels; + } + + /// <inheritdoc /> + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((Path) obj); + } + + /// <inheritdoc /> + public override int GetHashCode() + { + unchecked + { + var hashCode = 19; + if (Labels != null) + hashCode = Labels.Where(objLabels => objLabels != null) + .Aggregate(hashCode, + (current1, objLabels) => objLabels.Aggregate(current1, + (current, label) => current * 31 + label.GetHashCode())); + if (Objects != null) + hashCode = Objects.Aggregate(hashCode, (current, obj) => current * 31 + obj.GetHashCode()); + return hashCode; + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/Property.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/Property.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/Property.cs new file mode 100644 index 0000000..daa052a --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/Property.cs @@ -0,0 +1,96 @@ +#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; + +namespace Gremlin.Net.Structure +{ + /// <summary> + /// A <see cref="Property" /> denotes a key/value pair associated with an <see cref="Edge" />. + /// </summary> + public class Property : IEquatable<Property> + { + /// <summary> + /// Initializes a new instance of the <see cref="Property" /> class. + /// </summary> + /// <param name="key">The key of the property.</param> + /// <param name="value">The value of the property.</param> + /// <param name="element">The element that the property is associated with.</param> + public Property(string key, dynamic value, Element element) + { + Key = key; + Value = value; + Element = element; + } + + /// <summary> + /// Gets the key of the property. + /// </summary> + public string Key { get; } + + /// <summary> + /// Gets the value of the property. + /// </summary> + public dynamic Value { get; } + + /// <summary> + /// Gets the element that this property is associated with. + /// </summary> + public Element Element { get; } + + /// <inheritdoc /> + public bool Equals(Property other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return string.Equals(Key, other.Key) && Equals(Value, other.Value) && Equals(Element, other.Element); + } + + /// <inheritdoc /> + public override string ToString() + { + return $"p[{Key}->{Value}]"; + } + + /// <inheritdoc /> + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((Property) obj); + } + + /// <inheritdoc /> + public override int GetHashCode() + { + unchecked + { + var hashCode = Key?.GetHashCode() ?? 0; + hashCode = (hashCode * 397) ^ (Value != null ? Value.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ (Element?.GetHashCode() ?? 0); + return hashCode; + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/Vertex.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/Vertex.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/Vertex.cs new file mode 100644 index 0000000..f667d26 --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/Vertex.cs @@ -0,0 +1,52 @@ +#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 + +namespace Gremlin.Net.Structure +{ + /// <summary> + /// Represents a vertex. + /// </summary> + public class Vertex : Element + { + /// <summary> + /// The default label to use for a vertex. + /// </summary> + public const string DefaultLabel = "vertex"; + + /// <summary> + /// Initializes a new instance of the <see cref="Vertex" /> class. + /// </summary> + /// <param name="id">The id of the vertex.</param> + /// <param name="label">The label of the vertex.</param> + public Vertex(object id, string label = DefaultLabel) + : base(id, label) + { + } + + /// <inheritdoc /> + public override string ToString() + { + return $"v[{Id}]"; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/Gremlin.Net/Structure/VertexProperty.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/VertexProperty.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/VertexProperty.cs new file mode 100644 index 0000000..8e20723 --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/VertexProperty.cs @@ -0,0 +1,66 @@ +#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 + +namespace Gremlin.Net.Structure +{ + /// <summary> + /// A <see cref="VertexProperty" /> denotes a key/value pair associated with a <see cref="Vertex" />. + /// </summary> + public class VertexProperty : Element + { + /// <summary> + /// Initializes a new instance of the <see cref="VertexProperty" /> class. + /// </summary> + /// <param name="id">The id of the vertex property.</param> + /// <param name="label">The label of the vertex property.</param> + /// <param name="value">The id of the vertex property.</param> + /// <param name="vertex">The <see cref="Vertex" /> that owns this <see cref="VertexProperty" />.</param> + public VertexProperty(object id, string label, dynamic value, Vertex vertex) + : base(id, label) + { + Value = value; + Vertex = vertex; + } + + /// <summary> + /// The value of this <see cref="VertexProperty" />. + /// </summary> + public dynamic Value { get; } + + /// <summary> + /// The <see cref="Vertex" /> that owns this <see cref="VertexProperty" />. + /// </summary> + public Vertex Vertex { get; } + + /// <summary> + /// The key of this <see cref="VertexProperty" />. + /// </summary> + public string Key => Label; + + /// <inheritdoc /> + public override string ToString() + { + return $"vp[{Label}->{Value}]"; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/src/pom.xml ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/pom.xml b/gremlin-dotnet/src/pom.xml new file mode 100644 index 0000000..5fef134 --- /dev/null +++ b/gremlin-dotnet/src/pom.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tinkerpop</groupId> + <artifactId>gremlin-dotnet</artifactId> + <version>3.2.5-SNAPSHOT</version> + </parent> + <artifactId>Gremlin-DotNet-Source</artifactId> + <packaging>${packaging.type}</packaging> + <profiles> + <profile> + <id>gremlin-dotnet-standard</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <properties> + <packaging.type>pom</packaging.type> + </properties> + </profile> + <!-- activates the building of .NET components and requires that the .NET Core SDK be installed on the system --> + <profile> + <id>gremlin-dotnet</id> + <activation> + <activeByDefault>false</activeByDefault> + <file> + <exists>.glv</exists> + </file> + </activation> + <properties> + <packaging.type>dotnet-library</packaging.type> + </properties> + <build> + <directory>${basedir}/target</directory> + <finalName>${project.artifactId}-${project.version}</finalName> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.eobjects.build</groupId> + <artifactId>dotnet-maven-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <packOutput>${project.parent.basedir}/target/nuget</packOutput> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/BytecodeGeneration/BytecodeGenerationTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/BytecodeGeneration/BytecodeGenerationTests.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/BytecodeGeneration/BytecodeGenerationTests.cs new file mode 100644 index 0000000..672ff35 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/BytecodeGeneration/BytecodeGenerationTests.cs @@ -0,0 +1,76 @@ +#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 Gremlin.CSharp.Process; +using Gremlin.CSharp.Structure; +using Xunit; + +namespace Gremlin.CSharp.IntegrationTest.BytecodeGeneration +{ + public class BytecodeGenerationTests + { + [Fact] + public void g_V_OutXcreatedX() + { + var g = new Graph().Traversal(); + + var bytecode = g.V().Out("created").Bytecode; + + Assert.Equal(0, bytecode.SourceInstructions.Count); + Assert.Equal(2, bytecode.StepInstructions.Count); + Assert.Equal("V", bytecode.StepInstructions[0].OperatorName); + Assert.Equal("out", bytecode.StepInstructions[1].OperatorName); + Assert.Equal("created", bytecode.StepInstructions[1].Arguments[0]); + Assert.Equal(1, bytecode.StepInstructions[1].Arguments.Length); + } + + [Fact] + public void g_WithSackX1X_E_GroupCount_ByXweightX() + { + var g = new Graph().Traversal(); + + var bytecode = g.WithSack(1).E().GroupCount().By("weight").Bytecode; + + Assert.Equal(1, bytecode.SourceInstructions.Count); + Assert.Equal("withSack", bytecode.SourceInstructions[0].OperatorName); + Assert.Equal(1, bytecode.SourceInstructions[0].Arguments[0]); + Assert.Equal(3, bytecode.StepInstructions.Count); + Assert.Equal("E", bytecode.StepInstructions[0].OperatorName); + Assert.Equal("groupCount", bytecode.StepInstructions[1].OperatorName); + Assert.Equal("by", bytecode.StepInstructions[2].OperatorName); + Assert.Equal("weight", bytecode.StepInstructions[2].Arguments[0]); + Assert.Equal(0, bytecode.StepInstructions[0].Arguments.Length); + Assert.Equal(0, bytecode.StepInstructions[1].Arguments.Length); + Assert.Equal(1, bytecode.StepInstructions[2].Arguments.Length); + } + + [Fact] + public void AnonymousTraversal_Start_EmptyBytecode() + { + var bytecode = __.Start().Bytecode; + + Assert.Equal(0, bytecode.SourceInstructions.Count); + Assert.Equal(0, bytecode.StepInstructions.Count); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/BytecodeGeneration/StrategiesTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/BytecodeGeneration/StrategiesTests.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/BytecodeGeneration/StrategiesTests.cs new file mode 100644 index 0000000..6afda71 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/BytecodeGeneration/StrategiesTests.cs @@ -0,0 +1,170 @@ +#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; +using Gremlin.CSharp.Process; +using Gremlin.CSharp.Structure; +using Gremlin.Net.Process.Traversal.Strategy.Decoration; +using Gremlin.Net.Process.Traversal.Strategy.Finalization; +using Gremlin.Net.Process.Traversal.Strategy.Optimization; +using Gremlin.Net.Process.Traversal.Strategy.Verification; +using Xunit; + +namespace Gremlin.CSharp.IntegrationTest.BytecodeGeneration +{ + public class StrategiesTests + { + [Fact] + public void TraversalWithoutStrategies_AfterWithStrategiesWasCalled_WithStrategiesNotAffected() + { + var graph = new Graph(); + var g = graph.Traversal().WithStrategies(new ReadOnlyStrategy(), new IncidentToAdjacentStrategy()); + + var bytecode = g.WithoutStrategies(new ReadOnlyStrategy()).Bytecode; + + Assert.Equal(2, bytecode.SourceInstructions.Count); + Assert.Equal("withStrategies", bytecode.SourceInstructions[0].OperatorName); + Assert.Equal(2, bytecode.SourceInstructions[0].Arguments.Length); + Assert.Equal(new ReadOnlyStrategy(), bytecode.SourceInstructions[0].Arguments[0]); + Assert.Equal(new IncidentToAdjacentStrategy(), bytecode.SourceInstructions[0].Arguments[1]); + + Assert.Equal("withoutStrategies", bytecode.SourceInstructions[1].OperatorName); + Assert.Equal(1, bytecode.SourceInstructions[1].Arguments.Length); + Assert.Equal(new ReadOnlyStrategy(), bytecode.SourceInstructions[1].Arguments[0]); + } + + [Fact] + public void ShouldIncludeMultipleStrategiesInBytecodeWhenGivenToWithoutStrategies() + { + var graph = new Graph(); + var g = graph.Traversal(); + + var bytecode = g.WithoutStrategies(new ReadOnlyStrategy(), new LazyBarrierStrategy()).Bytecode; + + Assert.Equal(1, bytecode.SourceInstructions.Count); + Assert.Equal(2, bytecode.SourceInstructions[0].Arguments.Length); + Assert.Equal("withoutStrategies", bytecode.SourceInstructions[0].OperatorName); + Assert.Equal(new ReadOnlyStrategy(), bytecode.SourceInstructions[0].Arguments[0]); + Assert.Equal(new LazyBarrierStrategy(), bytecode.SourceInstructions[0].Arguments[1]); + } + + [Fact] + public void ShouldIncludeOneStrategyInBytecodeWhenGivenToWithoutStrategies() + { + var graph = new Graph(); + var g = graph.Traversal(); + + var bytecode = g.WithoutStrategies(new ReadOnlyStrategy()).Bytecode; + + Assert.Equal(1, bytecode.SourceInstructions.Count); + Assert.Equal(1, bytecode.SourceInstructions[0].Arguments.Length); + Assert.Equal("withoutStrategies", bytecode.SourceInstructions[0].OperatorName); + Assert.Equal(new ReadOnlyStrategy(), bytecode.SourceInstructions[0].Arguments[0]); + } + + [Fact] + public void ShouldIncludeConfigurationInBytecodeWhenGivenToWithStrategies() + { + var graph = new Graph(); + var g = graph.Traversal(); + + var bytecode = g.WithStrategies(new MatchAlgorithmStrategy("greedy")).Bytecode; + + Assert.Equal(1, bytecode.SourceInstructions.Count); + Assert.Equal(1, bytecode.SourceInstructions[0].Arguments.Length); + Assert.Equal("withStrategies", bytecode.SourceInstructions[0].OperatorName); + Assert.Equal(new MatchAlgorithmStrategy(), bytecode.SourceInstructions[0].Arguments[0]); + Assert.Contains("greedy", + ((MatchAlgorithmStrategy) bytecode.SourceInstructions[0].Arguments[0]).Configuration.Values); + } + + [Fact] + public void ShouldIncludeMultipleStrategiesInBytecodeWhenGivenToWithStrategies() + { + var graph = new Graph(); + var g = graph.Traversal(); + + var bytecode = g.WithStrategies(new ReadOnlyStrategy(), new IncidentToAdjacentStrategy()).Bytecode; + + Assert.Equal(1, bytecode.SourceInstructions.Count); + Assert.Equal(2, bytecode.SourceInstructions[0].Arguments.Length); + Assert.Equal("withStrategies", bytecode.SourceInstructions[0].OperatorName); + Assert.Equal(new ReadOnlyStrategy(), bytecode.SourceInstructions[0].Arguments[0]); + Assert.Equal(new IncidentToAdjacentStrategy(), bytecode.SourceInstructions[0].Arguments[1]); + } + + [Fact] + public void ShouldIncludeOneStrategyInBytecodeWhenGivenToWithStrategies() + { + var graph = new Graph(); + var g = graph.Traversal(); + + var bytecode = g.WithStrategies(new ReadOnlyStrategy()).Bytecode; + + Assert.Equal(1, bytecode.SourceInstructions.Count); + Assert.Equal(1, bytecode.SourceInstructions[0].Arguments.Length); + Assert.Equal("withStrategies", bytecode.SourceInstructions[0].OperatorName); + Assert.Equal(new ReadOnlyStrategy(), bytecode.SourceInstructions[0].Arguments[0]); + Assert.Equal("ReadOnlyStrategy", bytecode.SourceInstructions[0].Arguments[0].ToString()); + Assert.Equal(new ReadOnlyStrategy().GetHashCode(), bytecode.SourceInstructions[0].Arguments[0].GetHashCode()); + Assert.Equal(0, g.TraversalStrategies.Count); + } + + [Fact] + public void TraversalWithStrategies_Strategies_ApplyToReusedGraphTraversalSource() + { + var graph = new Graph(); + var g = graph.Traversal().WithStrategies(new ReadOnlyStrategy(), new IncidentToAdjacentStrategy()); + + var bytecode = g.V().Bytecode; + + Assert.Equal(1, bytecode.SourceInstructions.Count); + Assert.Equal(2, bytecode.SourceInstructions[0].Arguments.Length); + Assert.Equal("withStrategies", bytecode.SourceInstructions[0].OperatorName); + Assert.Equal(new ReadOnlyStrategy(), bytecode.SourceInstructions[0].Arguments[0]); + Assert.Equal(new IncidentToAdjacentStrategy(), bytecode.SourceInstructions[0].Arguments[1]); + Assert.Equal(1, bytecode.StepInstructions.Count); + Assert.Equal("V", bytecode.StepInstructions[0].OperatorName); + } + + [Fact] + public void TraversalWithStrategies_StrategyWithTraversalInConfig_IncludeTraversalInInConfigInBytecode() + { + var graph = new Graph(); + var g = graph.Traversal(); + + var bytecode = g.WithStrategies(new SubgraphStrategy(__.Has("name", "marko"))).Bytecode; + + Assert.Equal(1, bytecode.SourceInstructions.Count); + Assert.Equal(1, bytecode.SourceInstructions[0].Arguments.Length); + Assert.Equal("withStrategies", bytecode.SourceInstructions[0].OperatorName); + Assert.Equal(new SubgraphStrategy(), bytecode.SourceInstructions[0].Arguments[0]); + SubgraphStrategy strategy = bytecode.SourceInstructions[0].Arguments[0]; + Assert.Equal(1, strategy.Configuration.Count); + Assert.Equal(typeof(GraphTraversal), strategy.Configuration["vertices"].GetType()); + GraphTraversal traversal = strategy.Configuration["vertices"]; + Assert.Equal("has", traversal.Bytecode.StepInstructions[0].OperatorName); + Assert.Equal(new List<string> {"name", "marko"}, traversal.Bytecode.StepInstructions[0].Arguments); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/ConfigProvider.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/ConfigProvider.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/ConfigProvider.cs new file mode 100644 index 0000000..27e7009 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/ConfigProvider.cs @@ -0,0 +1,47 @@ +#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.IO; +using Microsoft.Extensions.Configuration; + +namespace Gremlin.CSharp.IntegrationTest +{ + public static class ConfigProvider + { + static ConfigProvider() + { + Configuration = GetConfig(); + } + + public static IConfiguration Configuration { get; } + + private static IConfiguration GetConfig() + { + var configFile = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"); + var builder = new ConfigurationBuilder() + .AddJsonFile(configFile, false, false); + + return builder.Build(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/EnumTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/EnumTests.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/EnumTests.cs new file mode 100644 index 0000000..a49a09d --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/EnumTests.cs @@ -0,0 +1,59 @@ +#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; +using Gremlin.CSharp.Process; +using Gremlin.CSharp.Structure; +using Xunit; + +namespace Gremlin.CSharp.IntegrationTest.DriverRemoteConnection +{ + public class EnumTests + { + private readonly RemoteConnectionFactory _connectionFactory = new RemoteConnectionFactory(); + + [Fact] + public void ShouldUseOrderDecrInByStep() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var orderedAges = g.V().Values("age").Order().By(Order.decr).ToList(); + + Assert.Equal(new List<object> {35, 32, 29, 27}, orderedAges); + } + + [Fact] + public void ShouldUseTLabelInHasStep() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var personsCount = g.V().Has(T.label, "person").Count().Next(); + + Assert.Equal((long) 4, personsCount); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/GraphTraversalSourceTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/GraphTraversalSourceTests.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/GraphTraversalSourceTests.cs new file mode 100644 index 0000000..f8c12e2 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/GraphTraversalSourceTests.cs @@ -0,0 +1,55 @@ +#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; +using Gremlin.CSharp.Process; +using Gremlin.CSharp.Structure; +using Xunit; + +namespace Gremlin.CSharp.IntegrationTest.DriverRemoteConnection +{ + public class GraphTraversalSourceTests + { + private readonly RemoteConnectionFactory _connectionFactory = new RemoteConnectionFactory(); + + [Fact] + public void ShouldUseSideEffectSpecifiedInWithSideEffect() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var results = g.WithSideEffect("a", new List<string> {"josh", "peter"}) + .V(1) + .Out("created") + .In("created") + .Values("name") + .Where(P.Within("a")) + .ToList(); + + Assert.Equal(2, results.Count); + Assert.Contains("josh", results); + Assert.Contains("peter", results); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/GraphTraversalTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/GraphTraversalTests.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/GraphTraversalTests.cs new file mode 100644 index 0000000..91a41ba --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/GraphTraversalTests.cs @@ -0,0 +1,171 @@ +#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; +using System.Linq; +using System.Threading.Tasks; +using Gremlin.CSharp.Process; +using Gremlin.CSharp.Structure; +using Gremlin.Net.Process.Traversal; +using Gremlin.Net.Structure; +using Xunit; + +namespace Gremlin.CSharp.IntegrationTest.DriverRemoteConnection +{ + public class GraphTraversalTests + { + private readonly RemoteConnectionFactory _connectionFactory = new RemoteConnectionFactory(); + + [Fact] + public void g_V_Count() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var count = g.V().Count().Next(); + + Assert.Equal((long) 6, count); + } + + [Fact] + public void g_VX1X_Next() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var vertex = (Vertex) g.V(1).Next(); + + Assert.Equal(new Vertex((long) 1), vertex); + Assert.Equal((long) 1, vertex.Id); + } + + [Fact] + public void g_VX1X_NextTraverser() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var traverser = g.V(1).NextTraverser(); + + Assert.Equal(new Traverser(new Vertex((long)1)), traverser); + } + + [Fact] + public void g_VX1X_ToList() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var list = g.V(1).ToList(); + + Assert.Equal(1, list.Count); + } + + [Fact] + public void g_V_RepeatXBothX_TimesX5X_NextX10X() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var result = g.V().Repeat(__.Both()).Times(5).Next(10); + + Assert.Equal(10, result.Count()); + } + + [Fact] + public void g_V_HasXname_markoX_ValueMap_Next() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var receivedValueMap = g.V().Has("name", "marko").ValueMap().Next(); + + var expectedValueMap = new Dictionary<string, dynamic> + { + {"age", new List<object> {29}}, + {"name", new List<object> {"marko"}} + }; + Assert.Equal(expectedValueMap, receivedValueMap); + } + + [Fact] + public void g_V_RepeatXOutX_TimesX2X_ValuesXNameX() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var t = g.V().Repeat(__.Out()).Times(2).Values("name"); + var names = t.ToList(); + + Assert.Equal((long) 2, names.Count); + Assert.Contains("lop", names); + Assert.Contains("ripple", names); + } + + [Fact] + public void ShortestPathTest() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var shortestPath = + (Path) g.V(5).Repeat(__.Both().SimplePath()).Until(__.HasId(6)).Limit(1).Path().Next(); + + Assert.Equal((long) 4, shortestPath.Count); + Assert.Equal(new Vertex((long) 6), shortestPath[3]); + } + + [Fact] + public void ShouldUseBindingsInTraversal() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var b = new Bindings(); + var count = g.V().Has(b.Of("propertyKey", "name"), b.Of("propertyValue", "marko")).OutE().Count().Next(); + + Assert.Equal((long) 3, count); + } + + [Fact] + public async Task ShouldExecuteAsynchronouslyWhenPromiseIsCalled() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var count = await g.V().Count().Promise(t => t.Next()); + + Assert.Equal((long) 6, count); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/PredicateTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/PredicateTests.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/PredicateTests.cs new file mode 100644 index 0000000..8dffa43 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/PredicateTests.cs @@ -0,0 +1,58 @@ +#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 Gremlin.CSharp.Process; +using Gremlin.CSharp.Structure; +using Xunit; + +namespace Gremlin.CSharp.IntegrationTest.DriverRemoteConnection +{ + public class PredicateTests + { + private readonly RemoteConnectionFactory _connectionFactory = new RemoteConnectionFactory(); + + [Fact] + public void ShouldUsePredicatesCombinedWithPAndInHasStep() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var count = g.V().Has("age", P.Gt(30).And(P.Lt(35))).Count().Next(); + + Assert.Equal((long) 1, count); + } + + [Fact] + public void ShouldUsePWithinInHasStep() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var count = g.V().Has("name", P.Within("josh", "vadas")).Count().Next(); + + Assert.Equal((long) 2, count); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/RemoteConnectionFactory.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/RemoteConnectionFactory.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/RemoteConnectionFactory.cs new file mode 100644 index 0000000..53b6e50 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/RemoteConnectionFactory.cs @@ -0,0 +1,41 @@ +#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; +using Gremlin.Net.Driver; +using Gremlin.Net.Process.Remote; + +namespace Gremlin.CSharp.IntegrationTest.DriverRemoteConnection +{ + internal class RemoteConnectionFactory + { + private static readonly string TestHost = ConfigProvider.Configuration["TestServerIpAddress"]; + private static readonly int TestPort = Convert.ToInt32(ConfigProvider.Configuration["TestServerPort"]); + + public IRemoteConnection CreateRemoteConnection() + { + return new Net.Driver.Remote.DriverRemoteConnection( + new GremlinClient(new GremlinServer(TestHost, TestPort))); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/SideEffectTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/SideEffectTests.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/SideEffectTests.cs new file mode 100644 index 0000000..8051167 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/SideEffectTests.cs @@ -0,0 +1,221 @@ +#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; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Gremlin.CSharp.Structure; +using Xunit; + +namespace Gremlin.CSharp.IntegrationTest.DriverRemoteConnection +{ + public class SideEffectTests + { + private readonly RemoteConnectionFactory _connectionFactory = new RemoteConnectionFactory(); + + [Fact] + public void ShouldReturnCachedSideEffectWhenGetIsCalledAfterClose() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + var t = g.V().Aggregate("a").Iterate(); + + t.SideEffects.Get("a"); + t.SideEffects.Close(); + var results = t.SideEffects.Get("a"); + + Assert.NotNull(results); + } + + [Fact] + public void ShouldThrowWhenGetIsCalledAfterCloseAndNoSideEffectsAreCachec() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + var t = g.V().Aggregate("a").Iterate(); + + t.SideEffects.Close(); + Assert.Throws<InvalidOperationException>(() => t.SideEffects.Get("a")); + } + + [Fact] + public void ShouldThrowWhenGetIsCalledAfterDisposeAndNoSideEffectsAreCachec() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + var t = g.V().Aggregate("a").Iterate(); + + t.SideEffects.Dispose(); + Assert.Throws<InvalidOperationException>(() => t.SideEffects.Get("a")); + } + + [Fact] + public void ShouldReturnSideEffectValueWhenGetIsCalledForGroupCountTraversal() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + var t = g.V().Out("created").GroupCount("m").By("name").Iterate(); + t.SideEffects.Keys(); + + var m = t.SideEffects.Get("m") as Dictionary<string, dynamic>; + + Assert.Equal(2, m.Count); + Assert.Equal((long) 3, m["lop"]); + Assert.Equal((long) 1, m["ripple"]); + } + + [Fact] + public void ShouldReturnSideEffectValueWhenGetIsCalledOnATraversalWithSideEffect() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + var t = g.WithSideEffect("a", new List<string> {"first", "second"}).V().Iterate(); + t.SideEffects.Keys(); + + var a = t.SideEffects.Get("a") as List<object>; + + Assert.Equal(2, a.Count); + Assert.Equal("first", a[0]); + Assert.Equal("second", a[1]); + } + + [Fact] + public void ShouldThrowWhenGetIsCalledWithAnUnknownKey() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + var t = g.V().Iterate(); + + Assert.Throws<KeyNotFoundException>(() => t.SideEffects.Get("m")); + } + + [Fact] + public void ShouldReturnBothSideEffectForTraversalWithTwoSideEffects_() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var t = g.V().Out("created").GroupCount("m").By("name").Values("name").Aggregate("n").Iterate(); + + var keys = t.SideEffects.Keys().ToList(); + Assert.Equal(2, keys.Count); + Assert.Contains("m", keys); + Assert.Contains("n", keys); + var n = (Dictionary<object, long>) t.SideEffects.Get("n"); + Assert.Equal(2, n.Count); + Assert.Equal(3, n["lop"]); + Assert.Equal(1, n["ripple"]); + } + + [Fact] + public void ShouldReturnAnEmptyCollectionWhenKeysIsCalledForTraversalWithoutSideEffect() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var t = g.V().Iterate(); + var keys = t.SideEffects.Keys(); + + Assert.Equal(0, keys.Count); + } + + [Fact] + public void ShouldReturnCachedKeysWhenForCloseAfterSomeGet() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + var t = g.V().Aggregate("a").Aggregate("b").Iterate(); + + t.SideEffects.Get("a"); + t.SideEffects.Close(); + var keys = t.SideEffects.Keys(); + + Assert.Equal(2, keys.Count); + Assert.Contains("a", keys); + Assert.Contains("b", keys); + } + + [Fact] + public void ShouldReturnSideEffectKeyWhenKeysIsCalledForNamedGroupCount() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + var t = g.V().Out("created").GroupCount("m").By("name").Iterate(); + + var keys = t.SideEffects.Keys(); + + var keysList = keys.ToList(); + Assert.Equal(1, keysList.Count); + Assert.Contains("m", keysList); + } + + [Fact] + public async Task ShouldReturnSideEffectsKeysWhenKeysIsCalledOnTraversalThatExecutedAsynchronously() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var t = await g.V().Aggregate("a").Promise(x => x); + var keys = t.SideEffects.Keys(); + + Assert.Equal(1, keys.Count); + Assert.Contains("a", keys); + } + + [Fact] + public async Task ShouldReturnSideEffectValueWhenGetIsCalledOnTraversalThatExecutedAsynchronously() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var t = await g.V().Aggregate("a").Promise(x => x); + var value = t.SideEffects.Get("a"); + + Assert.NotNull(value); + } + + [Fact] + public async Task ShouldNotThrowWhenCloseIsCalledOnTraversalThatExecutedAsynchronously() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection); + + var t = await g.V().Aggregate("a").Promise(x => x); + t.SideEffects.Close(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/StrategiesTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/StrategiesTests.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/StrategiesTests.cs new file mode 100644 index 0000000..59e2092 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/DriverRemoteConnection/StrategiesTests.cs @@ -0,0 +1,193 @@ +#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.Threading.Tasks; +using Gremlin.CSharp.Process; +using Gremlin.CSharp.Structure; +using Gremlin.Net.Driver.Exceptions; +using Gremlin.Net.Process.Traversal.Strategy.Decoration; +using Gremlin.Net.Process.Traversal.Strategy.Verification; +using Xunit; + +namespace Gremlin.CSharp.IntegrationTest.DriverRemoteConnection +{ + public class StrategiesTests + { + private readonly RemoteConnectionFactory _connectionFactory = new RemoteConnectionFactory(); + + [Fact] + public void g_V_Count_Next_WithVertexLabelSubgraphStrategy() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = + graph.Traversal() + .WithRemote(connection) + .WithStrategies(new SubgraphStrategy(vertexCriterion: __.HasLabel("person"))); + + var count = g.V().Count().Next(); + + Assert.Equal((long) 4, count); + } + + [Fact] + public void g_E_Count_Next_WithVertexAndEdgeLabelSubgraphStrategy() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = + graph.Traversal() + .WithRemote(connection) + .WithStrategies(new SubgraphStrategy(vertexCriterion: __.HasLabel("person"), + edgeCriterion: __.HasLabel("created"))); + + var count = g.E().Count().Next(); + + Assert.Equal((long)0, count); + } + + [Fact] + public void g_V_Label_Dedup_Count_Next_WithVertexLabelSubgraphStrategy() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = + graph.Traversal() + .WithRemote(connection) + .WithStrategies(new SubgraphStrategy(vertexCriterion: __.HasLabel("person"))); + + var count = g.V().Label().Dedup().Count().Next(); + + Assert.Equal((long)1, count); + } + + [Fact] + public void g_V_Label_Dedup_Next_WWithVertexLabelSubgraphStrategy() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = + graph.Traversal() + .WithRemote(connection) + .WithStrategies(new SubgraphStrategy(vertexCriterion: __.HasLabel("person"))); + + var label = g.V().Label().Dedup().Next(); + + Assert.Equal("person", label); + } + + [Fact] + public void g_V_Count_Next_WithVertexHasPropertySubgraphStrategy() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = + graph.Traversal() + .WithRemote(connection) + .WithStrategies(new SubgraphStrategy(vertexCriterion: __.Has("name", "marko"))); + + var count = g.V().Count().Next(); + + Assert.Equal((long)1, count); + } + + [Fact] + public void g_E_Count_Next_WithEdgeLimitSubgraphStrategy() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = + graph.Traversal() + .WithRemote(connection) + .WithStrategies(new SubgraphStrategy(edgeCriterion: __.Limit(0))); + + var count = g.E().Count().Next(); + + Assert.Equal((long)0, count); + } + + [Fact] + public void g_V_Label_Dedup_Next_WithVertexHasPropertySubgraphStrategy() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = + graph.Traversal() + .WithRemote(connection) + .WithStrategies(new SubgraphStrategy(vertexCriterion: __.Has("name", "marko"))); + + var label = g.V().Label().Dedup().Next(); + + Assert.Equal("person", label); + } + + [Fact] + public void g_V_ValuesXnameX_Next_WithVertexHasPropertySubgraphStrategy() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = + graph.Traversal() + .WithRemote(connection) + .WithStrategies(new SubgraphStrategy(vertexCriterion: __.Has("name", "marko"))); + + var name = g.V().Values("name").Next(); + + Assert.Equal("marko", name); + } + + [Fact] + public void g_V_Count_Next_WithComputer() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection).WithComputer(); + + var count = g.V().Count().Next(); + + Assert.Equal((long)6, count); + } + + [Fact] + public void g_E_Count_Next_WithComputer() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection).WithComputer(); + + var count = g.E().Count().Next(); + + Assert.Equal((long)6, count); + } + + [Fact] + public async Task ShouldThrowWhenModifyingTraversalSourceWithReadOnlyStrategy() + { + var graph = new Graph(); + var connection = _connectionFactory.CreateRemoteConnection(); + var g = graph.Traversal().WithRemote(connection).WithStrategies(new ReadOnlyStrategy()); + + await Assert.ThrowsAsync<ResponseException>(async () => await g.AddV("person").Promise(t => t.Next())); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/GraphSONWriterTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/GraphSONWriterTests.cs b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/GraphSONWriterTests.cs new file mode 100644 index 0000000..99a1b65 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/GraphSONWriterTests.cs @@ -0,0 +1,50 @@ +#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 Gremlin.CSharp.Process; +using Gremlin.Net.Structure.IO.GraphSON; +using Xunit; + +namespace Gremlin.CSharp.IntegrationTest +{ + public class GraphSONWriterTests + { + [Fact] + public void ShouldSerializeLongPredicateCorrectly() + { + var writer = CreateStandardGraphSONWriter(); + var predicate = P.Lt("b").Or(P.Gt("c")).And(P.Neq("d")); + + var graphSon = writer.WriteObject(predicate); + + const string expected = + "{\"@type\":\"g:P\",\"@value\":{\"predicate\":\"and\",\"value\":[{\"@type\":\"g:P\",\"@value\":{\"predicate\":\"or\",\"value\":[{\"@type\":\"g:P\",\"@value\":{\"predicate\":\"lt\",\"value\":\"b\"}},{\"@type\":\"g:P\",\"@value\":{\"predicate\":\"gt\",\"value\":\"c\"}}]}},{\"@type\":\"g:P\",\"@value\":{\"predicate\":\"neq\",\"value\":\"d\"}}]}}"; + Assert.Equal(expected, graphSon); + } + + private GraphSONWriter CreateStandardGraphSONWriter() + { + return new GraphSONWriter(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/37a24719/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/Gremlin.CSharp.IntegrationTest.csproj ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/Gremlin.CSharp.IntegrationTest.csproj b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/Gremlin.CSharp.IntegrationTest.csproj new file mode 100644 index 0000000..1e7a7d2 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.CSharp.IntegrationTest/Gremlin.CSharp.IntegrationTest.csproj @@ -0,0 +1,38 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>netcoreapp1.0</TargetFramework> + <AssemblyName>Gremlin.CSharp.IntegrationTest</AssemblyName> + <PackageId>Gremlin.CSharp.IntegrationTest</PackageId> + <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> + <RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion> + <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> + <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> + <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\..\src\Gremlin.CSharp\Gremlin.CSharp.csproj" /> + <ProjectReference Include="..\..\src\Gremlin.Net.Process\Gremlin.Net.Process.csproj" /> + <ProjectReference Include="..\..\src\Gremlin.Net\Gremlin.Net.csproj" /> + </ItemGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> + <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> + <PackageReference Include="xunit" Version="2.2.0" /> + <PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.1" /> + <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" /> + </ItemGroup> + + <ItemGroup> + <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> + </ItemGroup> + + <ItemGroup> + <None Update="appsettings.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + </ItemGroup> + +</Project>
