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_Coalesce() { using (var client = TestDatabase.GetClient("coalesce")) { var countQuery = VertexQuery.All().Count(); Assert.AreEqual(client.Execute(countQuery).Result.First(), 0); var baseQuery = VertexQuery.All().HasLabel("test").Fold(); var existsQuery = baseQuery.CreateSubQuery().Unfold(); var createQuery = baseQuery.CreateSubQuery().AddVertex("test"); VertexQuery query = baseQuery.Coalesce <GraphVertex>(existsQuery, createQuery); // client.Execute("g.V().has('person','name','bill').fold().coalesce(unfold(),addV('person').property('name', 'bill'))").Wait(); client.Execute(query).Wait(); Assert.AreEqual(client.Execute(countQuery).Result.First(), 1); client.Execute(query).Wait(); Assert.AreEqual(client.Execute(countQuery).Result.First(), 1); client.Execute(VertexQuery.All().Drop()).Wait(); } }
public override void Dispose() { var query = VertexQuery.All().Drop(); this.Execute(query).Wait(); this.DeleteCollectionAsync(db_name, collection).Wait(); base.Dispose(); }
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_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"); } }
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_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")); } }
public void Steps_Vertex_OutV() { using (var client = TestDatabase.GetClient("steps_vertex_outV")) { Setup_Test_Database(client); Assert.AreEqual(client.Execute(VertexQuery.All().HasLabel("one").OutE().OutV()).Result.First().label, "one"); } }
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_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_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_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_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_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_Vertex_BothE() { using (var client = TestDatabase.GetClient("steps_vertex_bothE")) { Setup_Test_Database(client); var result = client.Execute(VertexQuery.All().HasLabel("two").BothE()).Result; Assert.AreEqual(result.Count(), 2); Assert.IsTrue(result.ToList().Exists(v => v.label == "one_to_two")); Assert.IsTrue(result.ToList().Exists(v => v.label == "two_to_three")); } }
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_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 static TestDatabase GetClient(string collection) { TestDatabase client = new TestDatabase("https://localhost:8081/", "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="); client.CreateDatabaseIfNotExistsAsync(db_name).Wait(); client.collection = collection; client.CreateDocumentCollectionIfNotExistsAsync(db_name, collection).Wait(); client.Open(db_name, collection).Wait(); var query = VertexQuery.All().Drop(); client.Execute(query).Wait(); return(client); }
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_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")); } }