Ejemplo n.º 1
0
        public void ProblemDeseralizingObjectWithDateTimeFields_31()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
            {
                var startRecords = database.CountRecords;

                // explicitly setting the timezone to UTC instead of the JVM default timezone
                // FIXME: this is a work around for now
                database.Command("ALTER DATABASE TIMEZONE UTC");
                database.Create.Class<File>().Extends<OVertex>().CreateProperties().Run();

                var dateTime = DateTime.UtcNow;
                // OrientDB truncates milliseconds, so do so here for a proper comparison
                dateTime = dateTime.AddTicks( - (dateTime.Ticks % TimeSpan.TicksPerSecond));

                database.Insert(new File
                    {
                        Filename = "myfile",
                        Created = dateTime
                    }).Run();

                var doc = database.Select().From<File>().ToList().First();
                var file = doc.To<File>();

                // FIXME: the time zone is off
                Assert.That(file.Created, Is.EqualTo(dateTime));

                var endRecords = database.CountRecords;
                Assert.AreEqual(startRecords + 1, endRecords);
            }

        }
        public void ShouldUpdateClassFromDocument()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document = new ODocument();
                    document.OClassName = "TestClass";
                    document
                        .SetField("foo", "foo string value")
                        .SetField("bar", 12345);

                    database
                        .Insert(document)
                        .Run();

                    database
                        .Insert(document)
                        .Run();

                    document
                        .SetField("bar", 54321)
                        .SetField("baz", "new baz value");

                    int documentsUpdated = database
                        .Update(document)
                        .Run();

                    Assert.AreEqual(documentsUpdated, 2);

                    List<ODocument> documents = database
                        .Select()
                        .From("TestClass")
                        .ToList();

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, document.OClassName);
                        Assert.AreEqual(documents[i].GetField<string>("foo"), document.GetField<string>("foo"));
                        Assert.AreEqual(documents[i].GetField<int>("bar"), document.GetField<int>("bar"));
                        Assert.AreEqual(documents[i].GetField<string>("baz"), document.GetField<string>("baz"));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void ShouldSelectUntyped()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    string className = "TestVertexClass";

                    ODocument document1 = new ODocument();
                    document1
                        .SetField("foo", "foo string value1")
                        .SetField("bar", 12345);

                    ODocument document2 = new ODocument();
                    document2
                        .SetField("foo", "foo string value2")
                        .SetField("bar", 54321);

                    // create test class
                    database
                        .Create.Class("TestVertexClass")
                        .Extends("OGraphVertex")
                        .Run();

                    // load database with some testing data
                    database
                        .Create.Vertex(className)
                        .Set(document1)
                        .Run();

                    database
                        .Create.Vertex(className)
                        .Set(document2)
                        .Run();

                    // perform simple select
                    List<ORecord> result = database
                        .Select("foo", "bar")
                        .From("TestVertexClass")
                        .ToList();

                    Assert.AreEqual(result.Count, 2);
                    Assert.AreEqual(result[0].GetField<string>("foo"), document1.GetField<string>("foo"));
                    Assert.AreEqual(result[0].GetField<int>("bar"), document1.GetField<int>("bar"));
                    Assert.AreEqual(result[1].GetField<string>("foo"), document2.GetField<string>("foo"));
                    Assert.AreEqual(result[1].GetField<int>("bar"), document2.GetField<int>("bar"));
                }
            }
        }
Ejemplo n.º 4
0
        public void ShouldUpdateClassFromObject()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                    .Create.Class <TestProfileClass>()
                    .Run();

                    TestProfileClass profile = new TestProfileClass();
                    profile.Name = "Johny";

                    database
                    .Insert(profile)
                    .Run();

                    database
                    .Insert(profile)
                    .Run();

                    profile.Name    = "Julia";
                    profile.Surname = "Bravo";

                    int documentsUpdated = database
                                           .Update(profile)
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 2);

                    List <TestProfileClass> documents = database
                                                        .Select()
                                                        .From <TestProfileClass>()
                                                        .ToList <TestProfileClass>();

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, typeof(TestProfileClass).Name);
                        Assert.AreEqual(documents[i].Name, profile.Name);
                        Assert.AreEqual(documents[i].Surname, profile.Surname);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void ShouldUpdateRemoveFieldQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    ODocument document1 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value1")
                                          .Set("bar", 11111)
                                          .Run();

                    ODocument document2 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value2")
                                          .Set("bar", 12345)
                                          .Run();

                    int documentsUpdated = database
                                           .Update(document2)
                                           .Remove("bar")
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 1);

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From("TestClass")
                                                 .Where("foo").Equals("foo string value2")
                                                 .ToList();

                    Assert.AreEqual(documents.Count, 1);

                    Assert.AreEqual(documents[0].ORID, document2.ORID);
                    Assert.AreEqual(documents[0].OClassName, document2.OClassName);
                    Assert.AreEqual(documents[0].GetField <string>("foo"), document2.GetField <string>("foo"));
                    Assert.IsFalse(documents[0].HasField("bar"));
                }
            }
        }
        public void ShouldSelectFromDocumentOClassNameQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document1 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", "foo string value1")
                        .Set("bar", 12345)
                        .Run();

                    ODocument document2 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", "foo string value2")
                        .Set("bar", 54321)
                        .Run();

                    ODocument document = new ODocument();
                    document.OClassName = "TestClass";

                    List<ODocument> documents = database
                        .Select()
                        .From(document)
                        .ToList();

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, document.OClassName);
                        Assert.IsTrue(documents[i].HasField("foo"));
                        Assert.IsTrue(documents[i].HasField("bar"));
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void ShouldSelectFromDocumentOClassNameQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.ConnectionOptions))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    ODocument document1 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value1")
                                          .Set("bar", 12345)
                                          .Run();

                    ODocument document2 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value2")
                                          .Set("bar", 54321)
                                          .Run();

                    ODocument document = new ODocument();
                    document.OClassName = "TestClass";

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From(document)
                                                 .ToList();

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, document.OClassName);
                        Assert.IsTrue(documents[i].HasField("foo"));
                        Assert.IsTrue(documents[i].HasField("bar"));
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void ShouldSelectToObjectList()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.ConnectionOptions))
                {
                    // prerequisites
                    database
                    .Create.Class <TestProfileClass>()
                    .Run();

                    TestProfileClass document1 = database
                                                 .Insert()
                                                 .Into <TestProfileClass>()
                                                 .Set("Name", "Johny")
                                                 .Set("Surname", "Bravo")
                                                 .Run <TestProfileClass>();

                    TestProfileClass document2 = database
                                                 .Insert()
                                                 .Into <TestProfileClass>()
                                                 .Set("Name", "Johny")
                                                 .Set("Surname", "Bravo")
                                                 .Run <TestProfileClass>();

                    List <TestProfileClass> documents = database
                                                        .Select()
                                                        .From <TestProfileClass>()
                                                        .ToList <TestProfileClass>();

                    Assert.AreEqual(documents.Count, 2);

                    Assert.AreEqual(documents[0].ORID, document1.ORID);
                    Assert.AreEqual(documents[0].OClassName, document1.OClassName);
                    Assert.AreEqual(documents[0].Name, document1.Name);
                    Assert.AreEqual(documents[0].Surname, document1.Surname);

                    Assert.AreEqual(documents[1].ORID, document2.ORID);
                    Assert.AreEqual(documents[1].OClassName, document2.OClassName);
                    Assert.AreEqual(documents[1].Name, document2.Name);
                    Assert.AreEqual(documents[1].Surname, document2.Surname);
                }
            }
        }
Ejemplo n.º 9
0
        public void ShouldSelectAsAnd()
        {
            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 = 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);
                }
            }
        }
Ejemplo n.º 10
0
        public void TestCreateVerticesAndHeavyweightEdge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                    .Create.Class <TestVertexClass>()
                    .Extends <OVertex>()
                    .Run();
                    database
                    .Create.Class <TestEdgeClass>()
                    .Extends <OEdge>()
                    .Run();

                    var testVertex1 = CreateTestVertex(1);
                    var testVertex2 = CreateTestVertex(2);
                    var testEdge    = new TestEdgeClass();
                    testEdge.SetField("item", 1);

                    database.Transaction.Add(testVertex1);
                    database.Transaction.Add(testVertex2);
                    database.Transaction.AddEdge(testEdge, testVertex1, testVertex2);

                    Assert.AreEqual(testVertex1.ORID, testEdge.OutV);
                    Assert.AreEqual(testVertex2.ORID, testEdge.InV);

                    database.Transaction.Commit();

                    var createdVertex1 = database.Select().From("V").Where("bar").Equals(1).ToList <OVertex>().First();
                    var createdVertex2 = database.Select().From("V").Where("bar").Equals(2).ToList <OVertex>().First();

                    var createdEdge = database.Select().From("E").Where("item").Equals(1).ToList <OEdge>().First();
                    Assert.That(createdEdge.OutV, Is.EqualTo(createdVertex1.ORID));
                    Assert.That(createdEdge.InV, Is.EqualTo(createdVertex2.ORID));

                    var testEdge2 = new TestEdgeClass();
                    testEdge2.SetField("item", 2);
                    database.Transaction.AddEdge(testEdge2, createdVertex2, createdVertex1);
                    database.Transaction.Commit();

                    createdVertex1 = database.Select().From("V").Where("bar").Equals(1).ToList <OVertex>().First();
                    createdVertex2 = database.Select().From("V").Where("bar").Equals(2).ToList <OVertex>().First();
                    var createdEdge2 = database.Select().From("E").Where("item").Equals(2).ToList <OEdge>().First();

                    Assert.That(createdEdge2.OutV, Is.EqualTo(createdVertex2.ORID));
                    Assert.That(createdEdge2.InV, Is.EqualTo(createdVertex1.ORID));
                }
            }
        }
Ejemplo n.º 11
0
        public void ShouldUpdateRecordWithEmbeddedLinkedClass()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
                using (var db = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // Arrange
                    if (!db.Schema.IsClassExist <TestEmbeddedClass>())
                    {
                        db.Create.Class <TestEmbeddedClass>().CreateProperties <TestEmbeddedClass>().Run();
                    }

                    if (!db.Schema.IsClassExist <TestClass>())
                    {
                        db.Create.Class <TestClass>().Run();
                        db.Create.Property("SomeString", OType.String).Class("TestClass").Run();
                        db.Create.Property("EmbeddedClass", OType.Embedded).Class("TestClass").LinkedClass("TestEmbeddedClass").Run();
                    }

                    var toInsert = new TestClass()
                    {
                        SomeString    = "apple",
                        EmbeddedClass = new TestEmbeddedClass()
                        {
                            StringProperty = "embeddedApple"
                        },
                    };

                    var saved = db.Insert(toInsert).Run();

                    saved.SetField("SomeString", "pear");
                    saved.SetField("EmbeddedClass.StringProperty", "embeddedPear");

                    // Act
                    db.Transaction.Update(saved);
                    db.Transaction.Commit();

                    // Assert
                    var updated = db.Select().From(saved.ORID).ToList().Single();

                    Assert.AreEqual("pear", saved.GetField <string>("SomeString"));
                    Assert.AreEqual("embeddedPear", saved.GetField <string>("EmbeddedClass.StringProperty"));
                }
        }
Ejemplo n.º 12
0
        public static List <Switch> GetAllSwitches()
        {
            ODatabase            database  = InitDB();
            List <ODocument>     resultset = database.Select().From("Switch").ToList();
            JavaScriptSerializer converter = new JavaScriptSerializer();

            List <Switch> AllSwitches = new List <Switch>();

            foreach (ODocument doc in resultset)
            {
                var    json = converter.Serialize(doc);
                String a    = json.ToString();
                Switch d    = converter.Deserialize <Switch>(a);
                AllSwitches.Add(d);
            }

            database.Close();
            return(AllSwitches);
        }
Ejemplo n.º 13
0
        public void ShouldSelectFromDocumentOrid()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.ConnectionOptions))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    ODocument document1 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value1")
                                          .Set("bar", 12345)
                                          .Run();

                    ODocument document2 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", "foo string value2")
                                          .Set("bar", 54321)
                                          .Run();

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From(document2)
                                                 .ToList();

                    Assert.AreEqual(documents.Count, 1);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.AreEqual(documents[i].ORID, document2.ORID);
                        Assert.AreEqual(documents[i].OClassName, document2.OClassName);
                        Assert.AreEqual(documents[i].GetField <string>("foo"), document2.GetField <string>("foo"));
                        Assert.AreEqual(documents[i].GetField <int>("bar"), document2.GetField <int>("bar"));
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public void ShouldSelectFromDocumentOrid()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document1 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", "foo string value1")
                        .Set("bar", 12345)
                        .Run();

                    ODocument document2 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", "foo string value2")
                        .Set("bar", 54321)
                        .Run();

                    List<ODocument> documents = database
                        .Select()
                        .From(document2)
                        .ToList();

                    Assert.AreEqual(documents.Count, 1);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.AreEqual(documents[i].ORID, document2.ORID);
                        Assert.AreEqual(documents[i].OClassName, document2.OClassName);
                        Assert.AreEqual(documents[i].GetField<string>("foo"), document2.GetField<string>("foo"));
                        Assert.AreEqual(documents[i].GetField<int>("bar"), document2.GetField<int>("bar"));
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public static List <Desktop> GetAllDesktops()
        {
            ODatabase            database  = InitDB();
            string               query     = String.Format("SELECT * FROM Desktop");
            List <ODocument>     resultset = database.Select().From("Desktop").ToList();
            JavaScriptSerializer converter = new JavaScriptSerializer();

            List <Desktop> AllDesktops = new List <Desktop>();

            foreach (ODocument doc in resultset)
            {
                var     json = converter.Serialize(doc);
                String  a    = json.ToString();
                Desktop d    = converter.Deserialize <Desktop>(a);
                AllDesktops.Add(d);
            }

            database.Close();
            return(AllDesktops);
        }
Ejemplo n.º 16
0
        public void ShouldCreateRecordContainingSingleQuote()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            using (var db = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
            {
                if (!db.Schema.IsClassExist<TestClass>())
                {
                    db.Create.Class<TestClass>().CreateProperties<TestClass>().Run();
                }

                db.Command("delete from TestClass");

                var text = @"Jim'n";
                var test = new TestClass() { SomeString = text };
                db.Insert(test).Run();

                var result = db.Select().From<TestClass>().ToList<TestClass>();
                Assert.Equal(text, result.Single().SomeString);
            }
        }
        public void ShouldUpdateRecordUsingContent()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.ConnectionOptions))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    ODocument record1 = database.Insert("TestClass")
                                        .Content(TestConstants.CreateJson)
                                        .Run();

                    ODocument record2 = database.Insert("TestClass")
                                        .Content(TestConstants.CreateJson)
                                        .Run();

                    var recordsUpdated = database.Update(record1.ORID)
                                         .Content(TestConstants.UpdateJson)
                                         .Run();

                    Assert.AreEqual(1, recordsUpdated);

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From("TestClass")
                                                 .Where("simpleString").Equals("TestStringUpdated")
                                                 .ToList();

                    Assert.AreEqual(1, documents.Count);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        checkUpdateContentAssertions(documents[i]);
                    }
                }
            }
        }
        public void ShouldInsertAndReadValuesWithTrailingBackslash()
        {
            _database
            .Create.Class("TestClass")
            .Run();

            ODocument document = new ODocument();

            document.OClassName = "TestClass";
            document
            .SetField("foo", "foo string value \\ test \\")
            .SetField("bar", 12345);

            ODocument insertedDocument = _database
                                         .Insert(document)
                                         .Run();

            Assert.True(insertedDocument.ORID != null);
            Assert.Equal(insertedDocument.OClassName, "TestClass");
            Assert.Equal(insertedDocument.GetField <string>("foo"), document.GetField <string>("foo"));
            Assert.Equal(insertedDocument.GetField <int>("bar"), document.GetField <int>("bar"));


            List <ODocument> documents = _database
                                         .Select()
                                         .From(insertedDocument)
                                         .ToList();

            Assert.Equal(documents.Count, 1);

            for (int i = 0; i < documents.Count; i++)
            {
                Assert.Equal(documents[i].ORID, insertedDocument.ORID);
                Assert.Equal(documents[i].OClassName, insertedDocument.OClassName);
                Assert.Equal(documents[i].GetField <string>("foo"), insertedDocument.GetField <string>("foo"));
                Assert.Equal(documents[i].GetField <int>("bar"), insertedDocument.GetField <int>("bar"));
            }
        }
Ejemplo n.º 19
0
        public void TestTypedCreateVerticesAndLinks()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database.Create.Class <Widget>().Extends <OVertex>().Run();


                    var w1 = new Widget()
                    {
                        Foo = "foo", Bar = 1
                    };
                    var w2 = new Widget()
                    {
                        Foo = "woo", Bar = 2
                    };

                    database.Transaction.Add(w1);
                    database.Transaction.Add(w2);
                    w1.OtherWidget = w2.ORID;

                    database.Transaction.Commit();

                    Assert.AreEqual(w2.ORID, w1.OtherWidget);

                    var createdVertices = database.Select().From <Widget>().ToList <Widget>();
                    Assert.AreEqual(2, createdVertices.Count);

                    var withLink = createdVertices.First(x => x.OtherWidget != null);
                    var noLink   = createdVertices.First(x => x.OtherWidget == null);


                    Assert.AreEqual(noLink.ORID, withLink.OtherWidget);
                }
            }
        }
Ejemplo n.º 20
0
        public void ShouldCreateRecordContainingSingleQuote()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
                using (var db = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    if (!db.Schema.IsClassExist <TestClass>())
                    {
                        db.Create.Class <TestClass>().CreateProperties <TestClass>().Run();
                    }

                    db.Command("delete from TestClass");

                    var text = @"Jim'n";
                    var test = new TestClass()
                    {
                        SomeString = text
                    };
                    db.Insert(test).Run();

                    var result = db.Select().From <TestClass>().ToList <TestClass>();
                    Assert.AreEqual(text, result.Single().SomeString);
                }
        }
Ejemplo n.º 21
0
        public void q_26661636()
        {
            var lukaPerson = new Person {
                Name = "Luca"
            };
            var lpV = _database.Create.Vertex(lukaPerson).Run();

            var ferrariModenaCar = new Car {
                Name = "Ferrari Modena"
            };
            var fmcV   = _database.Create.Vertex(ferrariModenaCar).Run();
            var bmwCar = new Car {
                Name = "BMW"
            };
            var bmwcV    = _database.Create.Vertex(bmwCar).Run();
            var lp_fmcE  = _database.Create.Edge("Owns").From(lpV.ORID).To(fmcV.ORID).Run();
            var lp_bmwcE = _database.Create.Edge("Owns").From(lpV.ORID).To(bmwcV.ORID).Run();

            var countryUS = new Country {
                Name = "US"
            };
            var uscV    = _database.Create.Vertex(countryUS).Run();
            var lp_uscE = _database.Create.Edge("Lives").From(lpV.ORID).To(uscV.ORID).Run();

            var countryUK = new Country {
                Name = "UK"
            };
            var ukcV = _database.Create.Vertex(countryUK).Run();

            var pl = _database.Select().From <Person>().ToList <Person>().FirstOrDefault(p => p.Name == lukaPerson.Name);

            Assert.IsNotNull(pl);
            Assert.AreEqual(lukaPerson.Name, pl.Name);
            Assert.AreEqual(1, pl.out_Lives.Count);
            Assert.AreEqual(2, pl.out_Owns.Count);
        }
Ejemplo n.º 22
0
        static List<ODocument> Query()
        {
            List<ODocument> documents;

            try
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    documents = database
                        .Select()
                        .From("TestClass")
                        .ToList();
                    using (ODatabase database1 = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                    {
                        List<ODocument> documents2 = database1
                            .Select()
                            .From("TestClass")
                            .ToList();
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                documents = new List<ODocument>();
            }

            return documents;
        }
Ejemplo n.º 23
0
        public void ShouldCreateVerticesWithEdge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    OVertex vertex1 = database
                                      .Create.Vertex <OVertex>()
                                      .Set("Foo", "foo string value1")
                                      .Set("Bar", 12345)
                                      .Run <OVertex>();

                    Assert.True(!string.IsNullOrEmpty(vertex1.ORID.ToString()));
                    Assert.Equal("V", vertex1.OClassName);
                    Assert.Equal("foo string value1", vertex1.GetField <string>("Foo"));
                    Assert.Equal(12345, vertex1.GetField <int>("Bar"));

                    OVertex vertex2 = database
                                      .Create.Vertex <OVertex>()
                                      .Set("Foo", "foo string value2")
                                      .Set("Bar", 54321)
                                      .Run <OVertex>();

                    Assert.True(!string.IsNullOrEmpty(vertex2.ORID.ToString()));
                    Assert.Equal("V", vertex2.OClassName);
                    Assert.Equal("foo string value2", vertex2.GetField <string>("Foo"));
                    Assert.Equal(54321, vertex2.GetField <int>("Bar"));

                    OVertex vertex3 = database
                                      .Create.Vertex <OVertex>()
                                      .Set("Foo", "foo string value3")
                                      .Set("Bar", 347899)
                                      .Run <OVertex>();

                    Assert.True(!string.IsNullOrEmpty(vertex3.ORID.ToString()));
                    Assert.Equal("V", vertex3.OClassName);
                    Assert.Equal("foo string value3", vertex3.GetField <string>("Foo"));
                    Assert.Equal(347899, vertex3.GetField <int>("Bar"));

                    OEdge edge1 = database
                                  .Create.Edge <OEdge>()
                                  .From(vertex1)
                                  .To(vertex2)
                                  .Set("Foo", "foo string value3")
                                  .Set("Bar", 123)
                                  .Run <OEdge>();

                    Assert.True(!string.IsNullOrEmpty(edge1.ORID.ToString()));
                    Assert.Equal("E", edge1.Label);
                    Assert.Equal("E", edge1.OClassName);
                    Assert.Equal(vertex2.ORID, edge1.InV);
                    Assert.Equal(vertex1.ORID, edge1.OutV);
                    Assert.Equal("foo string value3", edge1.GetField <string>("Foo"));
                    Assert.Equal(123, edge1.GetField <int>("Bar"));

                    OEdge edge2 = database
                                  .Create.Edge <OEdge>()
                                  .From(vertex1)
                                  .To(vertex3)
                                  .Set("Foo", "foo string value4")
                                  .Set("Bar", 245)
                                  .Run <OEdge>();

                    Assert.True(!string.IsNullOrEmpty(edge2.ORID.ToString()));
                    Assert.Equal("E", edge2.Label);
                    Assert.Equal("E", edge2.OClassName);
                    Assert.Equal(vertex3.ORID, edge2.InV);
                    Assert.Equal(vertex1.ORID, edge2.OutV);
                    Assert.Equal("foo string value4", edge2.GetField <string>("Foo"));
                    Assert.Equal(245, edge2.GetField <int>("Bar"));

                    OVertex loadedVertex1 = database
                                            .Select()
                                            .From(vertex1)
                                            .ToList <OVertex>().First();

                    Assert.True(!string.IsNullOrEmpty(loadedVertex1.ORID.ToString()));
                    Assert.Equal("V", loadedVertex1.OClassName);
                    Assert.Equal(0, loadedVertex1.InE.Count);
                    Assert.Equal(2, loadedVertex1.OutE.Count);
                    Assert.True(loadedVertex1.OutE.Contains(edge1.ORID));
                    Assert.True(loadedVertex1.OutE.Contains(edge2.ORID));
                    Assert.Equal(vertex1.GetField <string>("Foo"), loadedVertex1.GetField <string>("Foo"));
                    Assert.Equal(vertex1.GetField <int>("Bar"), loadedVertex1.GetField <int>("Bar"));

                    OVertex loadedVertex2 = database
                                            .Select()
                                            .From(vertex2)
                                            .ToList <OVertex>().First();

                    Assert.True(!string.IsNullOrEmpty(loadedVertex2.ORID.ToString()));
                    Assert.Equal("V", loadedVertex2.OClassName);
                    Assert.Equal(0, loadedVertex2.OutE.Count);
                    Assert.Equal(1, loadedVertex2.InE.Count);
                    Assert.True(loadedVertex2.InE.Contains(edge1.ORID));
                    Assert.Equal(vertex2.GetField <string>("Foo"), loadedVertex2.GetField <string>("Foo"));
                    Assert.Equal(vertex2.GetField <int>("Bar"), loadedVertex2.GetField <int>("Bar"));
                }
            }
        }
Ejemplo n.º 24
0
        public void ShouldUpdateClassFromObject()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class<TestProfileClass>()
                        .Run();

                    TestProfileClass profile = new TestProfileClass();
                    profile.Name = "Johny";

                    database
                        .Insert(profile)
                        .Run();

                    database
                        .Insert(profile)
                        .Run();

                    profile.Name = "Julia";
                    profile.Surname = "Bravo";

                    int documentsUpdated = database
                        .Update(profile)
                        .Run();

                    Assert.AreEqual(documentsUpdated, 2);

                    List<TestProfileClass> documents = database
                        .Select()
                        .From<TestProfileClass>()
                        .ToList<TestProfileClass>();

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, typeof(TestProfileClass).Name);
                        Assert.AreEqual(documents[i].Name, profile.Name);
                        Assert.AreEqual(documents[i].Surname, profile.Surname);
                    }
                }
            }
        }
        public void ShouldCreateVerticesWithEdge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    OVertex vertex1 = database
                                      .Create.Vertex <OVertex>()
                                      .Set("Foo", "foo string value1")
                                      .Set("Bar", 12345)
                                      .Run <OVertex>();

                    Assert.IsTrue(!string.IsNullOrEmpty(vertex1.ORID.ToString()));
                    Assert.AreEqual(vertex1.OClassName, "V");
                    Assert.AreEqual(vertex1.GetField <string>("Foo"), "foo string value1");
                    Assert.AreEqual(vertex1.GetField <int>("Bar"), 12345);

                    OVertex vertex2 = database
                                      .Create.Vertex <OVertex>()
                                      .Set("Foo", "foo string value2")
                                      .Set("Bar", 54321)
                                      .Run <OVertex>();

                    Assert.IsTrue(!string.IsNullOrEmpty(vertex2.ORID.ToString()));
                    Assert.AreEqual(vertex2.OClassName, "V");
                    Assert.AreEqual(vertex2.GetField <string>("Foo"), "foo string value2");
                    Assert.AreEqual(vertex2.GetField <int>("Bar"), 54321);

                    OVertex vertex3 = database
                                      .Create.Vertex <OVertex>()
                                      .Set("Foo", "foo string value3")
                                      .Set("Bar", 347899)
                                      .Run <OVertex>();

                    Assert.IsTrue(!string.IsNullOrEmpty(vertex3.ORID.ToString()));
                    Assert.AreEqual(vertex3.OClassName, "V");
                    Assert.AreEqual(vertex3.GetField <string>("Foo"), "foo string value3");
                    Assert.AreEqual(vertex3.GetField <int>("Bar"), 347899);

                    OEdge edge1 = database
                                  .Create.Edge <OEdge>()
                                  .From(vertex1)
                                  .To(vertex2)
                                  .Set("Foo", "foo string value3")
                                  .Set("Bar", 123)
                                  .Run <OEdge>();

                    Assert.IsTrue(!string.IsNullOrEmpty(edge1.ORID.ToString()));
                    Assert.AreEqual(edge1.Label, "E");
                    Assert.AreEqual(edge1.OClassName, "E");
                    Assert.AreEqual(edge1.InV, vertex2.ORID);
                    Assert.AreEqual(edge1.OutV, vertex1.ORID);
                    Assert.AreEqual(edge1.GetField <string>("Foo"), "foo string value3");
                    Assert.AreEqual(edge1.GetField <int>("Bar"), 123);

                    OEdge edge2 = database
                                  .Create.Edge <OEdge>()
                                  .From(vertex1)
                                  .To(vertex3)
                                  .Set("Foo", "foo string value4")
                                  .Set("Bar", 245)
                                  .Run <OEdge>();

                    Assert.IsTrue(!string.IsNullOrEmpty(edge2.ORID.ToString()));
                    Assert.AreEqual(edge2.Label, "E");
                    Assert.AreEqual(edge2.OClassName, "E");
                    Assert.AreEqual(edge2.InV, vertex3.ORID);
                    Assert.AreEqual(edge2.OutV, vertex1.ORID);
                    Assert.AreEqual(edge2.GetField <string>("Foo"), "foo string value4");
                    Assert.AreEqual(edge2.GetField <int>("Bar"), 245);

                    OVertex loadedVertex1 = database
                                            .Select()
                                            .From(vertex1)
                                            .ToList <OVertex>().First();

                    Assert.IsTrue(!string.IsNullOrEmpty(loadedVertex1.ORID.ToString()));
                    Assert.AreEqual(loadedVertex1.OClassName, "V");
                    Assert.AreEqual(loadedVertex1.InE.Count, 0);
                    Assert.AreEqual(loadedVertex1.OutE.Count, 2);
                    Assert.IsTrue(loadedVertex1.OutE.Contains(edge1.ORID));
                    Assert.IsTrue(loadedVertex1.OutE.Contains(edge2.ORID));
                    Assert.AreEqual(loadedVertex1.GetField <string>("Foo"), vertex1.GetField <string>("Foo"));
                    Assert.AreEqual(loadedVertex1.GetField <int>("Bar"), vertex1.GetField <int>("Bar"));

                    OVertex loadedVertex2 = database
                                            .Select()
                                            .From(vertex2)
                                            .ToList <OVertex>().First();

                    Assert.IsTrue(!string.IsNullOrEmpty(loadedVertex2.ORID.ToString()));
                    Assert.AreEqual(loadedVertex2.OClassName, "V");
                    Assert.AreEqual(loadedVertex2.OutE.Count, 0);
                    Assert.AreEqual(loadedVertex2.InE.Count, 1);
                    Assert.IsTrue(loadedVertex2.InE.Contains(edge1.ORID));
                    Assert.AreEqual(loadedVertex2.GetField <string>("Foo"), vertex2.GetField <string>("Foo"));
                    Assert.AreEqual(loadedVertex2.GetField <int>("Bar"), vertex2.GetField <int>("Bar"));
                }
            }
        }
Ejemplo n.º 26
0
        public void ShouldUpdateCluster()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    database
                    .Create.Cluster("TestCluster", OClusterType.Physical)
                    .Run();

                    database.Command("alter class TestClass addcluster TestCluster");

                    ODocument document = new ODocument();
                    document.OClassName = "TestClass";
                    document
                    .SetField("foo", "foo string value")
                    .SetField("bar", 12345);

                    database
                    .Insert(document)
                    .Cluster("TestCluster")
                    .Run();

                    database
                    .Insert(document)
                    .Cluster("TestCluster")
                    .Run();

                    document
                    .SetField("bar", 54321)
                    .SetField("baz", "new baz value");

                    int documentsUpdated = database
                                           .Update(document)
                                           .Cluster("TestCluster")
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 2);

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From("cluster:TestCluster")
                                                 .ToList();

                    Assert.AreEqual(documents.Count, 2);

                    for (int i = 0; i < documents.Count; i++)
                    {
                        Assert.IsTrue(documents[i].ORID != null);
                        Assert.AreEqual(documents[i].OClassName, document.OClassName);
                        Assert.AreEqual(documents[i].GetField <string>("foo"), document.GetField <string>("foo"));
                        Assert.AreEqual(documents[i].GetField <int>("bar"), document.GetField <int>("bar"));
                        Assert.AreEqual(documents[i].GetField <string>("baz"), document.GetField <string>("baz"));
                    }
                }
            }
        }
Ejemplo n.º 27
0
        public void ShouldSelectSkipLimit()
        {
            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 = 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.AreEqual(result.Count, 2);
                    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"), obj4.Foo);
                    Assert.AreEqual(result[1].GetField<int>("CustomBar"), obj4.Bar);
                }
            }
        }
Ejemplo n.º 28
0
        public void ShouldUpdateRemoveCollectionItem()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

                    ODocument document1 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", new List <string>()
                    {
                        "foo1", "foo2"
                    })
                                          .Set("bar", 11111)
                                          .Run();

                    ODocument document2 = database
                                          .Insert()
                                          .Into("TestClass")
                                          .Set("foo", new List <string>()
                    {
                        "foo1", "foo2"
                    })
                                          .Set("bar", 12345)
                                          .Run();

                    int documentsUpdated = database
                                           .Update(document2)
                                           .Remove("foo", "foo2")
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 1);

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From("TestClass")
                                                 .Where("bar").Equals(12345)
                                                 .ToList();

                    Assert.AreEqual(documents.Count, 1);

                    Assert.AreEqual(documents[0].ORID, document2.ORID);
                    Assert.AreEqual(documents[0].OClassName, document2.OClassName);

                    List <string> foos = new List <string>()
                    {
                        "foo1"
                    };

                    Assert.AreEqual(documents[0].GetField <List <string> >("foo").Count, foos.Count);
                    Assert.AreEqual(documents[0].GetField <List <string> >("foo")[0], foos[0]);

                    Assert.AreEqual(documents[0].GetField <int>("bar"), document2.GetField <int>("bar"));
                }
            }
        }
        public void ShouldCreateVerticesWithEdge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    OVertex vertex1 = database
                        .Create.Vertex<OVertex>()
                        .Set("Foo", "foo string value1")
                        .Set("Bar", 12345)
                        .Run<OVertex>();

                    Assert.True(!string.IsNullOrEmpty(vertex1.ORID.ToString()));
                    Assert.Equal("V", vertex1.OClassName);
                    Assert.Equal("foo string value1", vertex1.GetField<string>("Foo"));
                    Assert.Equal(12345, vertex1.GetField<int>("Bar"));

                    OVertex vertex2 = database
                        .Create.Vertex<OVertex>()
                        .Set("Foo", "foo string value2")
                        .Set("Bar", 54321)
                        .Run<OVertex>();

                    Assert.True(!string.IsNullOrEmpty(vertex2.ORID.ToString()));
                    Assert.Equal("V", vertex2.OClassName);
                    Assert.Equal("foo string value2", vertex2.GetField<string>("Foo"));
                    Assert.Equal(54321, vertex2.GetField<int>("Bar"));

                    OVertex vertex3 = database
                        .Create.Vertex<OVertex>()
                        .Set("Foo", "foo string value3")
                        .Set("Bar", 347899)
                        .Run<OVertex>();

                    Assert.True(!string.IsNullOrEmpty(vertex3.ORID.ToString()));
                    Assert.Equal("V", vertex3.OClassName);
                    Assert.Equal("foo string value3", vertex3.GetField<string>("Foo"));
                    Assert.Equal(347899, vertex3.GetField<int>("Bar"));

                    OEdge edge1 = database
                        .Create.Edge<OEdge>()
                        .From(vertex1)
                        .To(vertex2)
                        .Set("Foo", "foo string value3")
                        .Set("Bar", 123)
                        .Run<OEdge>();

                    Assert.True(!string.IsNullOrEmpty(edge1.ORID.ToString()));
                    Assert.Equal("E", edge1.Label);
                    Assert.Equal("E", edge1.OClassName);
                    Assert.Equal(vertex2.ORID, edge1.InV);
                    Assert.Equal(vertex1.ORID, edge1.OutV);
                    Assert.Equal("foo string value3", edge1.GetField<string>("Foo"));
                    Assert.Equal(123, edge1.GetField<int>("Bar"));

                    OEdge edge2 = database
                        .Create.Edge<OEdge>()
                        .From(vertex1)
                        .To(vertex3)
                        .Set("Foo", "foo string value4")
                        .Set("Bar", 245)
                        .Run<OEdge>();

                    Assert.True(!string.IsNullOrEmpty(edge2.ORID.ToString()));
                    Assert.Equal("E", edge2.Label);
                    Assert.Equal("E", edge2.OClassName);
                    Assert.Equal(vertex3.ORID, edge2.InV);
                    Assert.Equal(vertex1.ORID, edge2.OutV);
                    Assert.Equal("foo string value4", edge2.GetField<string>("Foo"));
                    Assert.Equal(245, edge2.GetField<int>("Bar"));

                    OVertex loadedVertex1 = database
                        .Select()
                        .From(vertex1)
                        .ToList<OVertex>().First();

                    Assert.True(!string.IsNullOrEmpty(loadedVertex1.ORID.ToString()));
                    Assert.Equal("V", loadedVertex1.OClassName);
                    Assert.Equal(0, loadedVertex1.InE.Count);
                    Assert.Equal(2, loadedVertex1.OutE.Count);
                    Assert.True(loadedVertex1.OutE.Contains(edge1.ORID));
                    Assert.True(loadedVertex1.OutE.Contains(edge2.ORID));
                    Assert.Equal(vertex1.GetField<string>("Foo"), loadedVertex1.GetField<string>("Foo"));
                    Assert.Equal(vertex1.GetField<int>("Bar"), loadedVertex1.GetField<int>("Bar"));

                    OVertex loadedVertex2 = database
                        .Select()
                        .From(vertex2)
                        .ToList<OVertex>().First();

                    Assert.True(!string.IsNullOrEmpty(loadedVertex2.ORID.ToString()));
                    Assert.Equal("V", loadedVertex2.OClassName);
                    Assert.Equal(0, loadedVertex2.OutE.Count);
                    Assert.Equal(1, loadedVertex2.InE.Count);
                    Assert.True(loadedVertex2.InE.Contains(edge1.ORID));
                    Assert.Equal(vertex2.GetField<string>("Foo"), loadedVertex2.GetField<string>("Foo"));
                    Assert.Equal(vertex2.GetField<int>("Bar"), loadedVertex2.GetField<int>("Bar"));
                }
            }
        }
Ejemplo n.º 30
0
        public void ShouldCreateVerticesWithEdge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    OVertex vertex1 = database
                        .Create.Vertex<OVertex>()
                        .Set("Foo", "foo string value1")
                        .Set("Bar", 12345)
                        .Run<OVertex>();

                    Assert.IsTrue(!string.IsNullOrEmpty(vertex1.ORID.ToString()));
                    Assert.AreEqual(vertex1.OClassName, "V");
                    Assert.AreEqual(vertex1.GetField<string>("Foo"), "foo string value1");
                    Assert.AreEqual(vertex1.GetField<int>("Bar"), 12345);

                    OVertex vertex2 = database
                        .Create.Vertex<OVertex>()
                        .Set("Foo", "foo string value2")
                        .Set("Bar", 54321)
                        .Run<OVertex>();

                    Assert.IsTrue(!string.IsNullOrEmpty(vertex2.ORID.ToString()));
                    Assert.AreEqual(vertex2.OClassName, "V");
                    Assert.AreEqual(vertex2.GetField<string>("Foo"), "foo string value2");
                    Assert.AreEqual(vertex2.GetField<int>("Bar"), 54321);

                    OEdge edge = database
                        .Create.Edge<OEdge>()
                        .From(vertex1)
                        .To(vertex2)
                        .Set("Foo", "foo string value3")
                        .Set("Bar", 123)
                        .Run<OEdge>();

                    Assert.IsTrue(!string.IsNullOrEmpty(edge.ORID.ToString()));
                    Assert.AreEqual(edge.Label, "E");
                    Assert.AreEqual(edge.OClassName, "E");
                    Assert.AreEqual(edge.InV, vertex2.ORID);
                    Assert.AreEqual(edge.OutV, vertex1.ORID);
                    Assert.AreEqual(edge.GetField<string>("Foo"), "foo string value3");
                    Assert.AreEqual(edge.GetField<int>("Bar"), 123);

                    OVertex loadedVertex1 = database
                        .Select()
                        .From(vertex1)
                        .ToList<OVertex>().First();

                    Assert.IsTrue(!string.IsNullOrEmpty(loadedVertex1.ORID.ToString()));
                    Assert.AreEqual(loadedVertex1.OClassName, "V");
                    Assert.AreEqual(loadedVertex1.InE.Count, 0);
                    Assert.AreEqual(loadedVertex1.OutE.Count, 1);
                    Assert.IsTrue(loadedVertex1.OutE.Contains(edge.ORID));
                    Assert.AreEqual(loadedVertex1.GetField<string>("Foo"), vertex1.GetField<string>("Foo"));
                    Assert.AreEqual(loadedVertex1.GetField<int>("Bar"), vertex1.GetField<int>("Bar"));

                    OVertex loadedVertex2 = database
                        .Select()
                        .From(vertex2)
                        .ToList<OVertex>().First();

                    Assert.IsTrue(!string.IsNullOrEmpty(loadedVertex2.ORID.ToString()));
                    Assert.AreEqual(loadedVertex2.OClassName, "V");
                    Assert.AreEqual(loadedVertex2.OutE.Count, 0);
                    Assert.AreEqual(loadedVertex2.InE.Count, 1);
                    Assert.IsTrue(loadedVertex2.InE.Contains(edge.ORID));
                    Assert.AreEqual(loadedVertex2.GetField<string>("Foo"), vertex2.GetField<string>("Foo"));
                    Assert.AreEqual(loadedVertex2.GetField<int>("Bar"), vertex2.GetField<int>("Bar"));
                }
            }
        }
        public void TestCreateVerticesAndHeavyweightEdge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class<TestVertexClass>()
                        .Extends<OVertex>()
                        .Run();
                    database
                        .Create.Class<TestEdgeClass>()
                        .Extends<OEdge>()
                        .Run();

                    var testVertex1 = CreateTestVertex(1);
                    var testVertex2 = CreateTestVertex(2);
                    var testEdge = new TestEdgeClass();
                    testEdge.SetField("item", 1);

                    database.Transaction.Add(testVertex1);
                    database.Transaction.Add(testVertex2);
                    database.Transaction.AddEdge(testEdge, testVertex1, testVertex2);

                    Assert.AreEqual(testVertex1.ORID, testEdge.OutV);
                    Assert.AreEqual(testVertex2.ORID, testEdge.InV);

                    database.Transaction.Commit();

                    var createdVertex1 = database.Select().From("V").Where("bar").Equals(1).ToList<OVertex>().First();
                    var createdVertex2 = database.Select().From("V").Where("bar").Equals(2).ToList<OVertex>().First();

                    var createdEdge = database.Select().From("E").Where("item").Equals(1).ToList<OEdge>().First();
                    Assert.That(createdEdge.OutV, Is.EqualTo(createdVertex1.ORID));
                    Assert.That(createdEdge.InV, Is.EqualTo(createdVertex2.ORID));

                    var testEdge2 = new TestEdgeClass();
                    testEdge2.SetField("item", 2);
                    database.Transaction.AddEdge(testEdge2, createdVertex2, createdVertex1);
                    database.Transaction.Commit();

                    createdVertex1 = database.Select().From("V").Where("bar").Equals(1).ToList<OVertex>().First();
                    createdVertex2 = database.Select().From("V").Where("bar").Equals(2).ToList<OVertex>().First();
                    var createdEdge2 = database.Select().From("E").Where("item").Equals(2).ToList<OEdge>().First();

                    Assert.That(createdEdge2.OutV, Is.EqualTo(createdVertex2.ORID));
                    Assert.That(createdEdge2.InV, Is.EqualTo(createdVertex1.ORID));
                }
            }
        }
        public void TestCreateManyVertices()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestVertexClass")
                        .Extends<OVertex>()
                        .Run();

                    for (int i = 0; i < 1000; i++)
                    {
                        OVertex testVertex = new OVertex();
                        testVertex.OClassName = "TestVertexClass";
                        testVertex.SetField("foo", "foo string value");
                        testVertex.SetField("bar", i);
                        database.Transaction.Add(testVertex);
                    }

                    database.Transaction.Commit();


                    var createdVertices = database.Select().From("V").ToList();
                    Assert.AreEqual(1000, createdVertices.Count);

                    for (int i = 0; i < 1000; i++)
                    {
                        Assert.AreEqual(i, createdVertices[i].GetField<int>("bar"));
                    }

                }
            }
        }
Ejemplo n.º 33
0
        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);
                }
            }
        }
Ejemplo n.º 34
0
        public void ShouldGenerateSelectWhereStrings()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    string sqlWhereEquals = database
                        .Select()
                        .From<TestVertexClass>()
                        .Where("Foo").Equals(123)
                        .ToString();

                    Assert.AreEqual(sqlWhereEquals, "SELECT FROM TestVertexClass WHERE Foo = 123");

                    string sqlWhereNotEquals = database
                        .Select()
                        .From<TestVertexClass>()
                        .Where("Foo").NotEquals("whoa")
                        .ToString();

                    Assert.AreEqual(sqlWhereNotEquals, "SELECT FROM TestVertexClass WHERE Foo != 'whoa'");

                    string sqlWhereLesserGreater = database
                        .Select()
                        .From<TestVertexClass>()
                        .Where("Foo").Lesser(1)
                        .And("Bar").LesserEqual(2)
                        .Or("Baz").Greater(3)
                        .Or("Gar").GreaterEqual(4)
                        .ToString();

                    Assert.AreEqual(sqlWhereLesserGreater, "SELECT FROM TestVertexClass WHERE Foo < 1 AND Bar <= 2 OR Baz > 3 OR Gar >= 4");

                    string sqlWhereLike = database
                        .Select()
                        .From<TestVertexClass>()
                        .Where("Foo").Like("whoa%")
                        .ToString();

                    Assert.AreEqual(sqlWhereLike, "SELECT FROM TestVertexClass WHERE Foo LIKE 'whoa%'");

                    string sqlWhereIsNull = database
                        .Select()
                        .From<TestVertexClass>()
                        .Where("Foo").IsNull()
                        .ToString();

                    Assert.AreEqual(sqlWhereIsNull, "SELECT FROM TestVertexClass WHERE Foo IS NULL");

                    string sqlWhereContains1 = database
                        .Select()
                        .From<TestVertexClass>()
                        .Where("Foo").Contains("Luke")
                        .ToString();

                    Assert.AreEqual(sqlWhereContains1, "SELECT FROM TestVertexClass WHERE Foo CONTAINS 'Luke'");

                    string sqlWhereContains2 = database
                        .Select()
                        .From<TestVertexClass>()
                        .Where("Foo").Contains("name", "Luke")
                        .ToString();

                    Assert.AreEqual(sqlWhereContains2, "SELECT FROM TestVertexClass WHERE Foo CONTAINS (name = 'Luke')");
                }
            }
        }
Ejemplo n.º 35
0
        public void ShouldUpdateRecordSet()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document = new ODocument();
                    document.OClassName = "TestClass";
                    document
                        .SetField("foo", "foo string value")
                        .SetField("bar", 12345);

                    ODocument document1 = database
                        .Insert(document)
                        .Run();

                    ODocument document2 = database
                        .Insert(document)
                        .Run();

                    int documentsUpdated = database
                        .Update(document2.ORID)
                        .Set("bar", 54321)
                        .Set("baz", "new baz value")
                        .Run();

                    Assert.AreEqual(documentsUpdated, 1);

                    List<ODocument> documents = database
                        .Select()
                        .From("TestClass")
                        .Where("bar").Equals(54321)
                        .ToList();

                    Assert.AreEqual(documents.Count, 1);

                    Assert.AreEqual(documents[0].ORID, document2.ORID);
                    Assert.AreEqual(documents[0].OClassName, document2.OClassName);
                    Assert.AreEqual(documents[0].GetField<string>("foo"), document2.GetField<string>("foo"));
                    Assert.AreEqual(documents[0].GetField<int>("bar"), 54321);
                    Assert.AreEqual(documents[0].GetField<string>("baz"), "new baz value");
                }
            }
        }
Ejemplo n.º 36
0
        public void ShouldUpdateRemoveCollectionItem()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document1 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", new List<string>() { "foo1", "foo2" })
                        .Set("bar", 11111)
                        .Run();

                    ODocument document2 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", new List<string>() { "foo1", "foo2" })
                        .Set("bar", 12345)
                        .Run();

                    int documentsUpdated = database
                        .Update(document2)
                        .Remove("foo", "foo2")
                        .Run();

                    Assert.AreEqual(documentsUpdated, 1);

                    List<ODocument> documents = database
                        .Select()
                        .From("TestClass")
                        .Where("bar").Equals(12345)
                        .ToList();

                    Assert.AreEqual(documents.Count, 1);

                    Assert.AreEqual(documents[0].ORID, document2.ORID);
                    Assert.AreEqual(documents[0].OClassName, document2.OClassName);

                    List<string> foos = new List<string>() { "foo1" };

                    Assert.AreEqual(documents[0].GetField<List<string>>("foo").Count, foos.Count);
                    Assert.AreEqual(documents[0].GetField<List<string>>("foo")[0], foos[0]);

                    Assert.AreEqual(documents[0].GetField<int>("bar"), document2.GetField<int>("bar"));
                }
            }
        }
Ejemplo n.º 37
0
        public T Read <T>(long id) where T : BaseModel
        {
            var data = _db.Select().From($"[#{ModelFactory.modelId}:{id}]").ToList <BaseModel>().FirstOrDefault();

            return((T) new BaseModel());
        }
Ejemplo n.º 38
0
        public void ShouldUpdateRemoveFieldQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestClass")
                        .Run();

                    ODocument document1 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", "foo string value1")
                        .Set("bar", 11111)
                        .Run();

                    ODocument document2 = database
                        .Insert()
                        .Into("TestClass")
                        .Set("foo", "foo string value2")
                        .Set("bar", 12345)
                        .Run();

                    int documentsUpdated = database
                        .Update(document2)
                        .Remove("bar")
                        .Run();

                    Assert.AreEqual(documentsUpdated, 1);

                    List<ODocument> documents = database
                        .Select()
                        .From("TestClass")
                        .Where("foo").Equals("foo string value2")
                        .ToList();

                    Assert.AreEqual(documents.Count, 1);

                    Assert.AreEqual(documents[0].ORID, document2.ORID);
                    Assert.AreEqual(documents[0].OClassName, document2.OClassName);
                    Assert.AreEqual(documents[0].GetField<string>("foo"), document2.GetField<string>("foo"));
                    Assert.IsFalse(documents[0].HasField("bar"));
                }
            }
        }
Ejemplo n.º 39
0
        public void ShouldSelectToObjectList()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class<TestProfileClass>()
                        .Run();

                    TestProfileClass document1 = database
                        .Insert()
                        .Into<TestProfileClass>()
                        .Set("Name", "Johny")
                        .Set("Surname", "Bravo")
                        .Run<TestProfileClass>();

                    TestProfileClass document2 = database
                        .Insert()
                        .Into<TestProfileClass>()
                        .Set("Name", "Johny")
                        .Set("Surname", "Bravo")
                        .Run<TestProfileClass>();

                    List<TestProfileClass> documents = database
                        .Select()
                        .From<TestProfileClass>()
                        .ToList<TestProfileClass>();

                    Assert.AreEqual(documents.Count, 2);

                    Assert.AreEqual(documents[0].ORID, document1.ORID);
                    Assert.AreEqual(documents[0].OClassName, document1.OClassName);
                    Assert.AreEqual(documents[0].Name, document1.Name);
                    Assert.AreEqual(documents[0].Surname, document1.Surname);

                    Assert.AreEqual(documents[1].ORID, document2.ORID);
                    Assert.AreEqual(documents[1].OClassName, document2.OClassName);
                    Assert.AreEqual(documents[1].Name, document2.Name);
                    Assert.AreEqual(documents[1].Surname, document2.Surname);
                }
            }
        }
Ejemplo n.º 40
0
        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 TestCreateVerticesAndEdge()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestVertexClass")
                        .Extends<OVertex>()
                        .Run();


                    var testVertex1 = CreateTestVertex(1);
                    var testVertex2 = CreateTestVertex(2);
                    database.Transaction.Add(testVertex1);
                    database.Transaction.Add(testVertex2);
                    testVertex1.OutE.Add(testVertex2.ORID);
                    testVertex2.InE.Add(testVertex1.ORID);


                    database.Transaction.Commit();

                    Assert.AreEqual(testVertex2.ORID, testVertex1.OutE.First());
                    Assert.AreEqual(testVertex1.ORID, testVertex2.InE.First());

                    var createdVertices = database.Select().From("V").ToList<OVertex>();
                    Assert.AreEqual(2, createdVertices.Count);

                    Assert.AreEqual(createdVertices[1].ORID, createdVertices[0].OutE.First());
                    Assert.AreEqual(createdVertices[0].ORID, createdVertices[1].InE.First());

                }
            }
        }
Ejemplo n.º 42
0
        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 TestTypedCreateVerticesAndLinks()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database.Create.Class<Widget>().Extends<OVertex>().Run();


                    var w1 = new Widget() { Foo = "foo", Bar = 1 };
                    var w2 = new Widget() { Foo = "woo", Bar = 2 };

                    database.Transaction.Add(w1);
                    database.Transaction.Add(w2);
                    w1.OtherWidget = w2.ORID;

                    database.Transaction.Commit();

                    Assert.AreEqual(w2.ORID, w1.OtherWidget);

                    var createdVertices = database.Select().From<Widget>().ToList<Widget>();
                    Assert.AreEqual(2, createdVertices.Count);

                    var withLink = createdVertices.First(x => x.OtherWidget != null);
                    var noLink = createdVertices.First(x => x.OtherWidget == null);


                    Assert.AreEqual(noLink.ORID, withLink.OtherWidget);

                }
            }
        }
Ejemplo n.º 44
0
 public List <ODocument> GetAll()
 {
     return(db.Select().From("Resource").ToList());
 }