Exemplo n.º 1
0
        private IVertex IncludeAndQueryVertex(string vertexLabel, string propertyName, string type, object value,
                                              string expectedString, bool verifyToString = true)
        {
            IVertex vertex;

            using (var cluster = ClusterBuilder()
                                 .AddContactPoint(TestClusterManager.InitialContactPoint)
                                 .WithGraphOptions(new GraphOptions().SetName(GraphTests.GraphName))
                                 .Build())
            {
                var session = cluster.Connect();

                var schemaQuery = $"schema.propertyKey(propertyName).{type}.ifNotExists().create();\n" +
                                  "schema.vertexLabel(vertexLabel).properties(propertyName).ifNotExists().create();";

                session.ExecuteGraph(new SimpleGraphStatement(schemaQuery, new { vertexLabel, propertyName }));

                var parameters = new { vertexLabel, propertyName, val = value };
                session.ExecuteGraph(new SimpleGraphStatement("g.addV(vertexLabel).property(propertyName, val)", parameters));

                var rs =
                    session.ExecuteGraph(
                        new SimpleGraphStatement("g.V().hasLabel(vertexLabel).has(propertyName, val).next()", parameters));
                var first = rs.FirstOrDefault();
                Assert.NotNull(first);
                vertex = first.To <IVertex>();
                if (verifyToString)
                {
                    GraphTests.ValidateVertexResult(vertex, vertexLabel, propertyName, expectedString);
                }
            }
            return(vertex);
        }
Exemplo n.º 2
0
        public void Should_Support_Types(string type, object value, string expectedString)
        {
            var id           = _idGenerator++;
            var vertexLabel  = "vertex" + id;
            var propertyName = "prop" + id;

            GraphTests.IncludeAndQueryVertex(vertexLabel, propertyName, type, value, expectedString);
        }
Exemplo n.º 3
0
        private void TestInsertSelectProperty <T>(string type, T value, bool verifyToString = true)
        {
            var id           = _idGenerator++;
            var vertexLabel  = "vertex" + id;
            var propertyName = "prop" + id;
            var vertex       = GraphTests.IncludeAndQueryVertex(vertexLabel, propertyName, type, value, value.ToString(), verifyToString);
            var propObject   = vertex.GetProperty(propertyName).Value.To <T>();

            Assert.AreEqual(value, propObject);
        }