private static IEnumerable <Edge> GenerateEdges(int count)
        {
            StringBuilder propertyName = new StringBuilder();

            for (int i = 0; i < count - 1; i++)
            {
                Edge e = new Edge(
                    "e" + i,
                    "knows",
                    i.ToString(),
                    (i + 1).ToString(),
                    "vertex",
                    "vertex",
                    i,
                    i + 1);

                for (int j = 0; j < 5; j++)
                {
                    propertyName.Append("property");
                    propertyName.Append(j);
                    e.AddProperty(propertyName.ToString(), "dummyvalue");
                    propertyName.Clear();
                }

                yield return(e);
            }
        }
Exemple #2
0
        public void HashCodeIsDeterministic()
        {
            var edgeA = new Edge();

            edgeA.Id = 100;
            edgeA.RelationshipType = "R1";
            edgeA.Source           = 1;
            edgeA.Destination      = 2;
            edgeA.AddProperty("Hello", "World");

            var edgeB = new Edge();

            edgeB.Id = 100;
            edgeB.RelationshipType = "R1";
            edgeB.Source           = 1;
            edgeB.Destination      = 2;
            edgeB.AddProperty("Hello", "World");

            Assert.Equal(edgeA.GetHashCode(), edgeB.GetHashCode());
        }
Exemple #3
0
        public void TestRecord()
        {
            string name        = "roi";
            long   age         = 32;
            double doubleValue = 3.14;
            bool   boolValue   = true;

            string place = "TLV";
            long   since = 2000;

            Property nameProperty         = new Property("name", name);
            Property ageProperty          = new Property("age", age);
            Property doubleProperty       = new Property("doubleValue", doubleValue);
            Property trueBooleanProperty  = new Property("boolValue", true);
            Property falseBooleanProperty = new Property("boolValue", false);
            Property nullProperty         = new Property("nullValue", null);

            Property placeProperty = new Property("place", place);
            Property sinceProperty = new Property("since", since);

            Node expectedNode = new Node();

            expectedNode.Id = 0;
            expectedNode.AddLabel("person");
            expectedNode.AddProperty(nameProperty);
            expectedNode.AddProperty(ageProperty);
            expectedNode.AddProperty(doubleProperty);
            expectedNode.AddProperty(trueBooleanProperty);

            Assert.Equal("Node{labels=[person], id=0, propertyMap={name=Property{name='name', value=roi}, age=Property{name='age', value=32}, doubleValue=Property{name='doubleValue', value=3.14}, boolValue=Property{name='boolValue', value=True}}}", expectedNode.ToString());

            Edge expectedEdge = new Edge();

            expectedEdge.Id               = 0;
            expectedEdge.Source           = 0;
            expectedEdge.Destination      = 1;
            expectedEdge.RelationshipType = "knows";
            expectedEdge.AddProperty(placeProperty);
            expectedEdge.AddProperty(sinceProperty);
            expectedEdge.AddProperty(doubleProperty);
            expectedEdge.AddProperty(falseBooleanProperty);

            Assert.Equal("Edge{relationshipType='knows', source=0, destination=1, id=0, propertyMap={place=Property{name='place', value=TLV}, since=Property{name='since', value=2000}, doubleValue=Property{name='doubleValue', value=3.14}, boolValue=Property{name='boolValue', value=False}}}", expectedEdge.ToString());

            var parms = new Dictionary <string, object>
            {
                { "name", name },
                { "age", age },
                { "boolValue", boolValue },
                { "doubleValue", doubleValue }
            };

            Assert.NotNull(_api.Query("social", "CREATE (:person{name:$name,age:$age, doubleValue:$doubleValue, boolValue:$boolValue, nullValue:null})", parms));
            Assert.NotNull(_api.Query("social", "CREATE (:person{name:'amit',age:30})"));
            Assert.NotNull(_api.Query("social", "MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows{place:'TLV', since:2000,doubleValue:3.14, boolValue:false, nullValue:null}]->(b)"));

            ResultSet resultSet = _api.Query("social", "MATCH (a:person)-[r:knows]->(b:person) RETURN a,r, a.name, a.age, a.doubleValue, a.boolValue, a.nullValue, r.place, r.since, r.doubleValue, r.boolValue, r.nullValue");

            Assert.NotNull(resultSet);

            Assert.Equal(0, resultSet.Statistics.NodesCreated);
            Assert.Equal(0, resultSet.Statistics.NodesDeleted);
            Assert.Equal(0, resultSet.Statistics.LabelsAdded);
            Assert.Equal(0, resultSet.Statistics.PropertiesSet);
            Assert.Equal(0, resultSet.Statistics.RelationshipsCreated);
            Assert.Equal(0, resultSet.Statistics.RelationshipsDeleted);
            Assert.NotNull(resultSet.Statistics.GetStringValue(Label.QueryInternalExecutionTime));
            Assert.Single(resultSet);

            Record record = resultSet.First();

            Node node = record.GetValue <Node>(0);

            Assert.NotNull(node);

            Assert.Equal(expectedNode, node);

            node = record.GetValue <Node>("a");

            Assert.Equal(expectedNode, node);

            Edge edge = record.GetValue <Edge>(1);

            Assert.NotNull(edge);
            Assert.Equal(expectedEdge, edge);

            edge = record.GetValue <Edge>("r");
            Assert.Equal(expectedEdge, edge);

            Assert.Equal(new[] { "a", "r", "a.name", "a.age", "a.doubleValue", "a.boolValue", "a.nullValue", "r.place", "r.since", "r.doubleValue", "r.boolValue", "r.nullValue" }, record.Keys);

            Assert.Equal(new List <object> {
                expectedNode, expectedEdge, name, age, doubleValue, true, null, place, since, doubleValue, false, null
            }, record.Values);

            Assert.Equal("roi", record.GetString(2));
            Assert.Equal("32", record.GetString(3));
            Assert.Equal(32, record.GetValue <long>(3));
            Assert.Equal(32, record.GetValue <long>("a.age"));
            Assert.Equal("roi", record.GetString("a.name"));
            Assert.Equal("32", record.GetString("a.age"));
        }