public void ShouldSelectOrderByDescending() { using (TestDatabaseContext testContext = new TestDatabaseContext()) { using (ODatabase database = new ODatabase(TestConnection.ConnectionOptions)) { // prerequisites database .Create.Class <TestVertexClass>() .Extends <OVertex>() .Run(); TestVertexClass obj1 = new TestVertexClass(); obj1.Foo = "foo string value1"; obj1.Bar = 1; TestVertexClass obj2 = new TestVertexClass(); obj2.Foo = "foo string value2"; obj2.Bar = 2; TestVertexClass obj3 = new TestVertexClass(); obj3.Foo = "foo string value3"; obj3.Bar = 3; database .Create.Vertex <TestVertexClass>() .Set(obj1) .Run(); database .Create.Vertex <TestVertexClass>() .Set(obj2) .Run(); database .Create.Vertex <TestVertexClass>() .Set(obj3) .Run(); List <ODocument> result = database .Select("Foo").As("CustomFoo") .Also("Bar").As("CustomBar") .From <TestVertexClass>() .OrderBy("CustomBar").Descending() .ToList(); Assert.AreEqual(result.Count, 3); Assert.AreEqual(result[0].GetField <string>("CustomFoo"), obj3.Foo); Assert.AreEqual(result[0].GetField <int>("CustomBar"), obj3.Bar); Assert.AreEqual(result[1].GetField <string>("CustomFoo"), obj2.Foo); Assert.AreEqual(result[1].GetField <int>("CustomBar"), obj2.Bar); Assert.AreEqual(result[2].GetField <string>("CustomFoo"), obj1.Foo); Assert.AreEqual(result[2].GetField <int>("CustomBar"), obj1.Bar); } } }
public void ShouldSelectTyped() { using (TestDatabaseContext testContext = new TestDatabaseContext()) { using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias)) { TestVertexClass obj1 = new TestVertexClass(); obj1.Foo = "foo string value1"; obj1.Bar = 12345; TestVertexClass obj2 = new TestVertexClass(); obj2.Foo = "foo string value2"; obj2.Bar = 54321; // create test class database .Create.Class<TestVertexClass>() .Extends("OGraphVertex") .Run(); // load database with some testing data database .Create.Vertex<TestVertexClass>() .Set(obj1) .Run(); database .Create.Vertex<TestVertexClass>() .Set(obj2) .Run(); // perform simple select List<TestVertexClass> result = database .Select("Foo", "Bar") .From<TestVertexClass>() .ToList<TestVertexClass>(); Assert.AreEqual(result.Count, 2); Assert.AreEqual(result[0].Foo, obj1.Foo); Assert.AreEqual(result[0].Bar, obj1.Bar); Assert.AreEqual(result[1].Foo, obj2.Foo); Assert.AreEqual(result[1].Bar, obj2.Bar); } } }
public void ShouldSelectAsAnd() { using (TestDatabaseContext testContext = new TestDatabaseContext()) { using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS)) { // prerequisites database .Create.Class<TestVertexClass>() .Extends<OVertex>() .Run(); TestVertexClass obj1 = new TestVertexClass(); obj1.Foo = "foo string value1"; obj1.Bar = 12345; TestVertexClass obj2 = new TestVertexClass(); obj2.Foo = "foo string value2"; obj2.Bar = 54321; database .Create.Vertex<TestVertexClass>() .Set(obj1) .Run(); database .Create.Vertex<TestVertexClass>() .Set(obj2) .Run(); List<ODocument> result = database .Select("Foo").As("CustomFoo") .Also("Bar").As("CustomBar") .From<TestVertexClass>() .ToList(); Assert.AreEqual(result.Count, 2); Assert.AreEqual(result[0].GetField<string>("CustomFoo"), obj1.Foo); Assert.AreEqual(result[0].GetField<int>("CustomBar"), obj1.Bar); Assert.AreEqual(result[1].GetField<string>("CustomFoo"), obj2.Foo); Assert.AreEqual(result[1].GetField<int>("CustomBar"), obj2.Bar); } } }
public void ShouldCreateVertexTyped() { using (TestDatabaseContext testContext = new TestDatabaseContext()) { using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias)) { TestVertexClass testVertex = new TestVertexClass(); testVertex.Foo = "foo string value"; testVertex.Bar = 12345; // create test class for vertex database .Create.Class<TestVertexClass>() .Extends<OGraphVertex>() .Run(); // create test vertex from previously created class ORecord loadedVertex1 = database .Create.Vertex<TestVertexClass>() .Set(testVertex) .Run(); Assert.AreEqual(loadedVertex1.HasField("Foo"), true); Assert.AreEqual(loadedVertex1.HasField("Bar"), true); Assert.AreEqual(loadedVertex1.GetField<string>("Foo"), testVertex.Foo); Assert.AreEqual(loadedVertex1.GetField<int>("Bar"), testVertex.Bar); } } }
public void ShouldSelectOrderByDescending() { using (TestDatabaseContext testContext = new TestDatabaseContext()) { using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias)) { // prerequisites database .Create.Class<TestVertexClass>() .Extends<OVertex>() .Run(); TestVertexClass obj1 = new TestVertexClass(); obj1.Foo = "foo string value1"; obj1.Bar = 1; TestVertexClass obj2 = new TestVertexClass(); obj2.Foo = "foo string value2"; obj2.Bar = 2; TestVertexClass obj3 = new TestVertexClass(); obj3.Foo = "foo string value3"; obj3.Bar = 3; database .Create.Vertex<TestVertexClass>() .Set(obj1) .Run(); database .Create.Vertex<TestVertexClass>() .Set(obj2) .Run(); database .Create.Vertex<TestVertexClass>() .Set(obj3) .Run(); List<ODocument> result = database .Select("Foo").As("CustomFoo") .Also("Bar").As("CustomBar") .From<TestVertexClass>() .OrderBy("CustomBar").Descending() .ToList(); Assert.AreEqual(result.Count, 3); Assert.AreEqual(result[0].GetField<string>("CustomFoo"), obj3.Foo); Assert.AreEqual(result[0].GetField<int>("CustomBar"), obj3.Bar); Assert.AreEqual(result[1].GetField<string>("CustomFoo"), obj2.Foo); Assert.AreEqual(result[1].GetField<int>("CustomBar"), obj2.Bar); Assert.AreEqual(result[2].GetField<string>("CustomFoo"), obj1.Foo); Assert.AreEqual(result[2].GetField<int>("CustomBar"), obj1.Bar); } } }
public void ShouldSelectFromORID() { using (TestDatabaseContext testContext = new TestDatabaseContext()) { using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias)) { TestVertexClass obj = new TestVertexClass(); obj.Foo = "foo string value1"; obj.Bar = 12345; // create test class database .Create.Class<TestVertexClass>() .Extends("OGraphVertex") .Run(); // load database with some testing data ORecord vertex = database .Create.Vertex<TestVertexClass>() .Set(obj) .Run(); // perform simple select List<TestVertexClass> result = database .Select() .From(vertex.ORID) .ToList<TestVertexClass>(); Assert.AreEqual(result.Count, 1); Assert.AreEqual(result[0].Foo, obj.Foo); Assert.AreEqual(result[0].Bar, obj.Bar); } } }
public void ShouldGenerateCreateVertexQuery() { string generatedUntypedQuery = new OSqlCreateVertex() .Vertex("TestVertexClass") .Cluster("OGraphVertex") .Set("Foo", "foo string value") .Also("Bar", 12345) .ToString(); TestVertexClass testObj = new TestVertexClass(); testObj.Foo = "foo string value"; testObj.Bar = 12345; string generatedTypedQuery = new OSqlCreateVertex() .Vertex<TestVertexClass>() .Cluster<OGraphVertex>() .Set(testObj) .ToString(); string query = "CREATE VERTEX TestVertexClass " + "CLUSTER OGraphVertex " + "SET Foo = 'foo string value', " + "Bar = 12345"; Assert.AreEqual(generatedUntypedQuery, query); Assert.AreEqual(generatedTypedQuery, query); }
public void ShouldSelectSkipLimit() { using (TestDatabaseContext testContext = new TestDatabaseContext()) { using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias)) { // prerequisites database .Create.Class <TestVertexClass>() .Extends <OVertex>() .Run(); TestVertexClass obj1 = new TestVertexClass(); obj1.Foo = "foo string value1"; obj1.Bar = 1; TestVertexClass obj2 = new TestVertexClass(); obj2.Foo = "foo string value2"; obj2.Bar = 2; TestVertexClass obj3 = new TestVertexClass(); obj3.Foo = "foo string value3"; obj3.Bar = 3; TestVertexClass obj4 = new TestVertexClass(); obj4.Foo = "foo string value4"; obj4.Bar = 4; TestVertexClass obj5 = new TestVertexClass(); obj5.Foo = "foo string value5"; obj5.Bar = 5; database .Create.Vertex <TestVertexClass>() .Set(obj1) .Run(); database .Create.Vertex <TestVertexClass>() .Set(obj2) .Run(); database .Create.Vertex <TestVertexClass>() .Set(obj3) .Run(); database .Create.Vertex <TestVertexClass>() .Set(obj4) .Run(); database .Create.Vertex <TestVertexClass>() .Set(obj5) .Run(); List <ODocument> result = database .Select("Foo").As("CustomFoo") .Also("Bar").As("CustomBar") .From <TestVertexClass>() .Skip(2) .Limit(2) .ToList(); Assert.Equal(result.Count, 2); Assert.Equal(result[0].GetField <string>("CustomFoo"), obj3.Foo); Assert.Equal(result[0].GetField <int>("CustomBar"), obj3.Bar); Assert.Equal(result[1].GetField <string>("CustomFoo"), obj4.Foo); Assert.Equal(result[1].GetField <int>("CustomBar"), obj4.Bar); } } }