I'm using Gremlin.Net and I want to write unit tests for the functions that query the database. I want the queries to run on a mock data, to see if the result is being converted correctly to my desired format, especially with Traverser.Object that has a dynamic type.
Is there any way I can achieve this? Maybe run a server in code or have an in-memory instance of graph.
Here's a toy example:
var query = graphTraversalSource.V(leafIds).As("leaf")
.Emit(__.HasLabel("root"))
.As("root")
.Repeat(
__.InE("related_to").OtherV()
.SimplePath())
.Dedup()
.Select<Vertex>("leaf", "root")
.By(__.ValueMap<string, string>(true));
var res = new List<MyFormat>();
foreach (var t in query.Traversers)
{
var leafInfo = t.Object["leaf"];
var rootInfo = t.Object["root"];
var tmp = new MyFormat
{
LeafId = leafInfo[T.Id],
LeafLabel = leafInfo[T.Label],
LeafProperty = leafInfo["some_property"][0],
RootId = rootInfo[T.Id],
RootProperty = rootInfo["some_other_propert"][0]
};
res.Add(tmp);
}
return res;
In the example above, leafInfo and rootInfo have dynamic types, so having this function run against a test graph could assert that those variables are used correctly, e.g. leafInfo["some_property"][0] is assignable to MyFormat.LeafProperty