public void Steps_Choose() { using (var client = TestDatabase.GetClient("choose")) { var countQuery = VertexQuery.All().Count(); Assert.AreEqual(client.Execute(countQuery).Result.First(), 0); var insertQuery = VertexQuery.Create("test"); client.Execute(insertQuery).Wait(); client.Execute(insertQuery).Wait(); Assert.AreEqual(client.Execute(countQuery).Result.First(), 2); var baseQuery = VertexQuery.All(); var findQuery = baseQuery.CreateSubQuery().HasLabel("new"); var trueQuery = baseQuery.CreateSubQuery().HasLabel("new"); var falseQuery = baseQuery.CreateSubQuery().AddVertex("new"); var query = baseQuery.Choose <GraphVertex>(findQuery, trueQuery, falseQuery); client.Execute(query).Wait(); Assert.AreEqual(client.Execute(countQuery).Result.First(), 4); client.Execute(query).Wait(); Assert.AreEqual(client.Execute(countQuery).Result.First(), 6); } }
public void Query_VertexSerialization() { using (var client = TestDatabase.GetClient("vertex_serialization")) { client.Execute(VertexQuery.Create(GetPopulatedObject())).Wait(); var vertex = client.Execute(VertexQuery.All()).Result.FirstOrDefault(); Assert.IsNotNull(vertex); var result = vertex.Deserialize <SerializationDataContractTestObject>(); var truth = GetPopulatedObject(); Assert.AreEqual(truth.testString, result.testString); Assert.AreEqual(truth.testBool, result.testBool); Assert.AreEqual(truth.testFloat, result.testFloat); Assert.AreEqual(truth.testDouble, result.testDouble); Assert.AreEqual(truth.testDecimal, result.testDecimal); Assert.AreEqual(truth.testInt, result.testInt); Assert.AreEqual(truth.testLong, result.testLong); Assert.AreEqual(null, result.testList0); Assert.AreEqual(1, result.testList1.Count()); Assert.IsTrue(result.testList1.Contains(truth.testList1.First())); Assert.AreEqual(2, result.testList2.Count()); Assert.IsTrue(result.testList2.Contains(truth.testList2[0])); Assert.IsTrue(result.testList2.Contains(truth.testList2[1])); Assert.AreEqual(truth.testDateTime, result.testDateTime); Assert.AreEqual(truth.testRandom, result.testRandom); } }
public void Steps_Values() { using (var client = TestDatabase.GetClient("values")) { client.Execute(VertexQuery.Create("foo").AddProperty("key", "value")).Wait(); Assert.AreEqual(client.Execute(VertexQuery.All().Values()).Result.First(), "value"); } }
public void Steps_Id() { using (var client = TestDatabase.GetClient("id")) { client.Execute(VertexQuery.Create("foo")).Wait(); Assert.AreEqual(client.Execute(VertexQuery.All().Id()).Result.Count(), 1); } }
public void Steps_Key() { using (var client = TestDatabase.GetClient("key")) { client.Execute(VertexQuery.Create("foo").AddProperty("key", "value")).Wait(); Assert.IsTrue(client.Execute(VertexQuery.All().Properties().Key()).Result.First().Contains("key")); } }
private void Setup_Test_Database(TestDatabase client) { client.Execute(VertexQuery.Create("one")).Wait(); client.Execute(VertexQuery.Create("two")).Wait(); client.Execute(VertexQuery.Create("three")).Wait(); client.Execute(VertexQuery.All().HasLabel("one").AddEdge("one_to_two", DirectionStep.To(VertexQuery.Find("two")))).Wait(); client.Execute(VertexQuery.All().HasLabel("two").AddEdge("two_to_three", DirectionStep.To(VertexQuery.Find("three")))).Wait(); }
public void Steps_Sum() { using (var client = TestDatabase.GetClient("sum")) { client.Execute(VertexQuery.Create("foo").AddProperty("age", 30)).Wait(); client.Execute(VertexQuery.Create("bar").AddProperty("age", 20)).Wait(); Assert.AreEqual(client.Execute(VertexQuery.All().Values("age").Sum()).Result.First(), 50L); } }
public void Predicates_Outside() { using (var client = TestDatabase.GetClient("predicates_outside")) { client.Execute(VertexQuery.Create("test").AddProperty("age", 30)).Wait(); Assert.AreEqual(0, client.Execute(VertexQuery.All().Values("age").Is(GraphPredicate.Outside(age - 1, age + 1))).Result.Count()); Assert.AreEqual(1, client.Execute(VertexQuery.All().Values("age").Is(GraphPredicate.Outside(age + 1, age + 2))).Result.Count()); } }
public void Steps_HasId() { using (var client = TestDatabase.GetClient("hasId")) { var result = client.Execute(VertexQuery.Create("foo")).Result; Assert.AreEqual(client.Execute(VertexQuery.All().HasId(result.First().id).Count()).Result.First(), 1); Assert.AreEqual(client.Execute(VertexQuery.All().HasId(Guid.NewGuid().ToString()).Count()).Result.First(), 0); } }
public void Steps_Drop() { using (var client = TestDatabase.GetClient("drop")) { client.Execute(VertexQuery.Create("foo")).Wait(); client.Execute(VertexQuery.All().Drop()).Wait(); Assert.AreEqual(client.Execute(VertexQuery.All().Count()).Result.First(), 0); } }
public void Steps_Vertex_AddV() { using (var client = TestDatabase.GetClient("steps_vertex_addV")) { var query = VertexQuery.Create(new SerializationTestObject()); var output = client.Execute(query).Result; var obj = output.First().Deserialize <SerializationTestObject>(); } }
public void Steps_HasNot() { using (var client = TestDatabase.GetClient("hasNot")) { client.Execute(VertexQuery.Create("foo").AddProperty("key", "value")).Wait(); Assert.AreEqual(client.Execute(VertexQuery.All().HasNot("key").Count()).Result.First(), 0); Assert.AreEqual(client.Execute(VertexQuery.All().HasNot("not_key").Count()).Result.First(), 1); } }
public void Steps_Or() { using (var client = TestDatabase.GetClient("or")) { client.Execute(VertexQuery.Create("foo")).Wait(); var subQuery1 = VertexQuery.All().CreateSubQuery().HasLabel("bar"); var subQuery2 = VertexQuery.All().CreateSubQuery().HasLabel("foo"); Assert.AreEqual(client.Execute(VertexQuery.All().Or(subQuery1, subQuery2)).Result.First().label, "foo"); } }
public void Steps_Count() { using (var client = TestDatabase.GetClient("count")) { client.Execute(VertexQuery.Create("foo")).Wait(); var result = client.Execute(VertexQuery.All().Count()).Result; Assert.AreEqual(result.Count(), 1); Assert.AreEqual(result.First(), 1); } }
public void Steps_Is() { using (var client = TestDatabase.GetClient("is")) { client.Execute(VertexQuery.Create("foo").AddProperty("age", 30)).Wait(); Assert.AreEqual(client.Execute(VertexQuery.All().Values("age").Is(30).Count()).Result.First(), 1); Assert.AreEqual(client.Execute(VertexQuery.All().Values("age").Is(40).Count()).Result.First(), 0); Assert.AreEqual(client.Execute(VertexQuery.All().Values("age").Is(GraphPredicate.Inside(25, 35)).Count()).Result.First(), 1); } }
public void Steps_Not() { using (var client = TestDatabase.GetClient("not")) { client.Execute(VertexQuery.Create("foo")).Wait(); var baseQuery = VertexQuery.All(); var subQuery = baseQuery.CreateSubQuery().HasLabel("foo"); Assert.AreEqual(client.Execute(baseQuery.Not(subQuery)).Result.Count(), 0); } }
public void Steps_Inject() { using (var client = TestDatabase.GetClient("inject")) { client.Execute(VertexQuery.Create("foo").AddProperty("key", "value")).Wait(); var result = client.Execute(VertexQuery.All().Values("key").Inject("injected_value")).Result; Assert.IsTrue(result.Contains("value")); Assert.IsTrue(result.Contains("injected_value")); } }
public void Steps_Barrier() { using (var client = TestDatabase.GetClient("barrier")) { client.Execute(VertexQuery.Create("test")).Wait(); var query = VertexQuery.All().Barrier().Count(); var result = client.Execute(query).Result; Assert.AreEqual(result.First(), 1); } }
public void Predicates_Without() { using (var client = TestDatabase.GetClient("predicates_without")) { int[] empty = { }; int[] values = { age }; int[] outValues = { age + 1 }; client.Execute(VertexQuery.Create("test").AddProperty("age", 30)).Wait(); Assert.ThrowsException <ArgumentException>(() => { GraphPredicate.Without(empty); }); Assert.AreEqual(0, client.Execute(VertexQuery.All().Values("age").Is(GraphPredicate.Without(values))).Result.Count()); Assert.AreEqual(1, client.Execute(VertexQuery.All().Values("age").Is(GraphPredicate.Without(outValues))).Result.Count()); } }
public void Steps_AddV() { using (var client = TestDatabase.GetClient("addV")) { var properties = new Dictionary <string, object>(); properties.Add("key1", "value1"); properties.Add("key2", "value2"); Assert.AreEqual(client.Execute(VertexQuery.Create("test", properties)).Result.Count(), 1); Assert.AreEqual(client.Execute(VertexQuery.All()).Result.Count(), 1); client.Execute(VertexQuery.All().AddVertex("test2", properties)).Wait(); Assert.AreEqual(client.Execute(VertexQuery.All()).Result.Count(), 2); } }
public void Steps_Optional() { using (var client = TestDatabase.GetClient("optional")) { client.Execute(VertexQuery.Create("one")).Wait(); var subQuery = VertexQuery.All().CreateSubQuery().Out(); Assert.AreEqual(client.Execute(VertexQuery.All().Optional(subQuery)).Result.First().label, "one"); client.Execute(VertexQuery.Create("two")).Wait(); client.Execute(VertexQuery.All().HasLabel("one").AddEdge("to", DirectionStep.To(VertexQuery.Find("two")))).Wait(); Assert.AreEqual(client.Execute(VertexQuery.All().Optional(subQuery)).Result.First().label, "two"); } }
public void Steps_AddE() { using (var client = TestDatabase.GetClient("addE")) { // Setup var vertex1 = client.Execute(VertexQuery.Create("vertex1")).Result; var vertex2 = client.Execute(VertexQuery.Create("vertex2")).Result; // Test var query = VertexQuery.All().HasLabel("vertex1").AddEdge("edge1", DirectionStep.To(vertex2.First().id)); client.Execute(query).Wait(); // Verify Assert.AreEqual(client.Execute(VertexQuery.All().HasLabel("vertex1").Out()).Result.First().id, vertex2.First().id); } }
public void Steps_Constant() { using (var client = TestDatabase.GetClient("constant")) { client.Execute(VertexQuery.Create("foo").AddProperty("name", "steve")).Wait(); var baseQuery = VertexQuery.All(); var conditionQuery = baseQuery.CreateSubQuery().HasLabel("bar"); var trueQuery = baseQuery.CreateSubQuery().Values("name"); var falseQuery = baseQuery.CreateSubQuery().Constant("unknown"); var result = client.Execute(baseQuery.Choose(conditionQuery, trueQuery, falseQuery)).Result; Assert.AreEqual(result.First(), "unknown"); } }
public void Steps_Aggregate() { using (var client = TestDatabase.GetClient("aggregate")) { client.Execute(VertexQuery.Create("test")).Wait(); var query = VertexQuery.All().Aggregate("x").Where(GraphPredicate.Without(new List <object>() { "x" })); Assert.AreEqual(client.Execute(query).Result.Count(), 0); } }
public void Steps_SimplePath() { using (var client = TestDatabase.GetClient("simple_path")) { client.Execute(VertexQuery.Create("one")).Wait(); client.Execute(VertexQuery.Create("two")).Wait(); client.Execute(VertexQuery.Create("three")).Wait(); client.Execute(VertexQuery.All().HasLabel("one").AddEdge("to", DirectionStep.To(VertexQuery.Find("two")))).Wait(); client.Execute(VertexQuery.All().HasLabel("two").AddEdge("to", DirectionStep.To(VertexQuery.Find("three")))).Wait(); Assert.AreEqual(client.Execute(VertexQuery.All().HasLabel("one").Both().Both().Count()).Result.First(), 2L); Assert.AreEqual(client.Execute(VertexQuery.All().HasLabel("one").Both().Both().SimplePath().Count()).Result.First(), 1L); } }
public void Steps_Union() { using (var client = TestDatabase.GetClient("union")) { client.Execute(VertexQuery.Create("foo").AddProperty("firstName", "John").AddProperty("lastName", "Doe")).Wait(); var query = VertexQuery.All().Union( VertexQuery.All().CreateSubQuery().Values("firstName"), VertexQuery.All().CreateSubQuery().Values("lastName") ); var result = client.Execute(query).Result; Assert.AreEqual(result.Count(), 2); Assert.IsTrue(result.Contains("John")); Assert.IsTrue(result.Contains("Doe")); } }
public void Steps_Order() { using (var client = TestDatabase.GetClient("order")) { client.Execute(VertexQuery.Create("foo").AddProperty("age", 30)).Wait(); client.Execute(VertexQuery.Create("bar").AddProperty("age", 20)).Wait(); var result = client.Execute(VertexQuery.All().Label().Order(true)).Result; Assert.AreEqual(result.First(), "bar"); Assert.AreEqual(result.ElementAt(1), "foo"); var vertexResult = client.Execute(VertexQuery.All().OrderBy("age", true)).Result; Assert.AreEqual(vertexResult.First().label, "bar"); Assert.AreEqual(vertexResult.ElementAt(1).label, "foo"); } }
public void Steps_And() { using (var client = TestDatabase.GetClient("and")) { client.Execute(VertexQuery.Create("test").AddProperty("age", 30).AddProperty("name", "steve")).Wait(); client.Execute(VertexQuery.Create("test")).Wait(); var baseQuery = VertexQuery.All(); var query = VertexQuery.All().And(baseQuery.CreateSubQuery().Values("age").Is(30), baseQuery.CreateSubQuery().Values("name").Is("steve")); var result = client.Execute(query).Result; Assert.AreEqual(result.Count(), 1); Assert.AreEqual(client.Execute(VertexQuery.All()).Result.Count(), 2); } }
public void Steps_Where() { using (var client = TestDatabase.GetClient("where")) { client.Execute(VertexQuery.Create("one")).Wait(); client.Execute(VertexQuery.Create("two")).Wait(); client.Execute(VertexQuery.Create("three")).Wait(); client.Execute(VertexQuery.All().HasLabel("one").AddEdge("to", DirectionStep.To(VertexQuery.Find("two")))).Wait(); client.Execute(VertexQuery.All().HasLabel("two").AddEdge("to", DirectionStep.To(VertexQuery.Find("three")))).Wait(); var query = VertexQuery.All().HasLabel("one").As("a").Both().Both().Where(GraphPredicate.NotEqualTo("a")); var result = client.Execute(query).Result; Assert.AreEqual(result.Count(), 1); Assert.AreEqual(result.First().label, "three"); } }
public void Steps_Select() { using (var client = TestDatabase.GetClient("select")) { client.Execute(VertexQuery.Create("one")).Wait(); client.Execute(VertexQuery.Create("two")).Wait(); client.Execute(VertexQuery.All().HasLabel("one").AddEdge("to", DirectionStep.To(VertexQuery.Find("two")))).Wait(); var query = VertexQuery.All().As("a").Out().As("b").Select("a", "b"); var result = client.Execute(query).Result; Assert.IsTrue(result.First().ContainsKey("a")); Assert.IsTrue(result.First().ContainsKey("b")); } }