Exemplo n.º 1
0
        public void ShouldFetchLinkedDocumentsFromSimpleQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
            {
                database.Create.Class("Owner").Extends("V").Run();
                database.Create.Class("Computer").Extends("V").Run();
                var owner = new ODocument { OClassName = "Owner" };

                owner.SetField<String>("name", "Shawn");

                owner = database.Create.Vertex(owner).Run();

                var computer = new ODocument { OClassName = "Computer" };

                computer.SetField<ORID>("owner", owner.ORID);
                database.Create.Vertex(computer).Run();

                computer = database.Query("SELECT FROM Computer", "*:-1").FirstOrDefault();

                Assert.That(database.ClientCache.ContainsKey(computer.GetField<ORID>("owner")));

                var document = database.ClientCache[computer.GetField<ORID>("owner")];
                Assert.That(document.GetField<string>("name"), Is.EqualTo("Shawn"));
            }
        }
Exemplo n.º 2
0
        public void ShouldSerializeSingleAndSetOfOrids()
        {
            string recordString = "Something@single:#10:12345,set:<#11:123,#22:1234,#33:1234567>,singleSet:<#44:44>";

            var       rawRecord = Encoding.UTF8.GetBytes(recordString);
            ODocument document  = serializer.Deserialize(rawRecord, new ODocument());

            // check for fields existence
            Assert.Equal(document.HasField("single"), true);
            Assert.Equal(document.HasField("set"), true);

            // check for fields values
            Assert.Equal(document.GetField <ORID>("single"), new ORID(10, 12345));
            HashSet <ORID> collection = document.GetField <HashSet <ORID> >("set");

            Assert.Equal(collection.Count, 3);
            Assert.True(collection.Contains(new ORID(11, 123)));
            Assert.True(collection.Contains(new ORID(22, 1234)));
            Assert.True(collection.Contains(new ORID(33, 1234567)));

            HashSet <ORID> singleSet = document.GetField <HashSet <ORID> >("singleSet");

            Assert.Equal(singleSet.Count, 1);
            Assert.True(singleSet.Contains(new ORID(44, 44)));

            var serialized = Encoding.UTF8.GetString(serializer.Serialize(document));

            Assert.Equal(recordString, serialized);
        }
        public void ShouldCreateVertexFromDocument()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                    .Create.Class("TestVertexClass")
                    .Extends <OVertex>()
                    .Run();

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

                    OVertex createdVertex = database
                                            .Create.Vertex(document)
                                            .Run();

                    Assert.IsTrue(createdVertex.ORID != null);
                    Assert.AreEqual(createdVertex.OClassName, "TestVertexClass");
                    Assert.AreEqual(createdVertex.GetField <string>("foo"), document.GetField <string>("foo"));
                    Assert.AreEqual(createdVertex.GetField <int>("bar"), document.GetField <int>("bar"));
                }
            }
        }
        public void ShouldCreateVertexFromDocument()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                        .Create.Class("TestVertexClass")
                        .Extends<OVertex>()
                        .Run();

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

                    OVertex createdVertex = database
                        .Create.Vertex(document)
                        .Run();

                    Assert.IsNotNull(createdVertex.ORID);
                    Assert.AreEqual("TestVertexClass", createdVertex.OClassName);
                    Assert.AreEqual(document.GetField<string>("foo"), createdVertex.GetField<string>("foo"));
                    Assert.AreEqual(document.GetField<int>("bar"), createdVertex.GetField<int>("bar"));
                }
            }
        }
        public void ShouldFetchLinkedDocumentsFromSimpleQuery()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    database.Create.Class("Owner").Extends("V").Run();
                    database.Create.Class("Computer").Extends("V").Run();
                    var owner = new ODocument {
                        OClassName = "Owner"
                    };

                    owner.SetField <String>("name", "Shawn");

                    owner = database.Create.Vertex(owner).Run();

                    var computer = new ODocument {
                        OClassName = "Computer"
                    };

                    computer.SetField <ORID>("owner", owner.ORID);
                    database.Create.Vertex(computer).Run();

                    computer = database.Query("SELECT FROM Computer", "*:-1").FirstOrDefault();

                    Assert.True(database.ClientCache.ContainsKey(computer.GetField <ORID>("owner")));

                    var document = database.ClientCache[computer.GetField <ORID>("owner")];
                    Assert.Equal(document.GetField <string>("name"), "Shawn");
                }
        }
        private void checkUpdateContentAssertions(ODocument document)
        {
            Assert.IsNotNull(document);

            Assert.IsNotNull(document.ORID);
            Assert.AreEqual(document.OClassName, "TestClass");

            Assert.AreEqual("TestStringUpdated", document.GetField <string>("simpleString"));

            Assert.IsFalse(document.HasField("embeddedObject"));

            ODocument embeddedObject = document.GetField <ODocument>("embeddedObjectUpdated");

            Assert.IsNotNull(embeddedObject);

            Assert.IsTrue(embeddedObject.HasField("embeddedArrayOfObjects"));

            List <ODocument> arrayOfObjects = embeddedObject.GetField <List <ODocument> >("embeddedArrayOfObjects");

            Assert.AreEqual(3, arrayOfObjects.Count);

            Assert.AreEqual("ValueA1Updated", arrayOfObjects[0].GetField <string>("stringPropertyUpdated"));
            Assert.AreEqual(2, arrayOfObjects[1].GetField <int>("numericPropertyUpdated"));
            Assert.AreEqual(true, arrayOfObjects[2].GetField <bool>("booleanPropertyUpdated"));
        }
        public void ShouldInsertDocument()
        {
            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 insertedDocument = database
                        .Insert(document)
                        .Run();

                    Assert.IsTrue(insertedDocument.ORID != null);
                    Assert.AreEqual(insertedDocument.OClassName, "TestClass");
                    Assert.AreEqual(insertedDocument.GetField<string>("foo"), document.GetField<string>("foo"));
                    Assert.AreEqual(insertedDocument.GetField<int>("bar"), document.GetField<int>("bar"));
                }
            }
        }
        public void ShouldInsertObjectIntoUsingContentKeyword()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.ConnectionOptions))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    ODocument insertedDocument = database
                                                 .Insert()
                                                 .Into("TestClass")
                                                 .Content("{\"bar\": 12345, \"foo\":\"foo string value\"}")
                                                 .Run();

                    Assert.IsTrue(insertedDocument.ORID != null);
                    Assert.AreEqual(insertedDocument.OClassName, "TestClass");
                    Assert.AreEqual(insertedDocument.GetField <string>("foo"), document.GetField <string>("foo"));
                    Assert.AreEqual(insertedDocument.GetField <int>("bar"), document.GetField <int>("bar"));
                }
            }
        }
        public void ShouldCreateDocumentClassSet()
        {
            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 createdDocument = database
                                                .Create.Document("TestClass")
                                                .Set(document)
                                                .Run();

                    Assert.IsNotNull(createdDocument.ORID);
                    Assert.AreEqual("TestClass", createdDocument.OClassName);
                    Assert.AreEqual(document.GetField <string>("foo"), createdDocument.GetField <string>("foo"));
                    Assert.AreEqual(document.GetField <int>("bar"), createdDocument.GetField <int>("bar"));
                }
            }
        }
Exemplo n.º 10
0
        public void ShouldUpdateCluster()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    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"));
                    }
                }
            }
        }
Exemplo n.º 11
0
        public void ShouldInsertDocumentInto()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    ODocument insertedDocument = database
                                                 .Insert(document)
                                                 .Into("TestClass")
                                                 .Run();

                    Assert.IsTrue(insertedDocument.ORID != null);
                    Assert.AreEqual(insertedDocument.OClassName, "TestClass");
                    Assert.AreEqual(insertedDocument.GetField <string>("foo"), document.GetField <string>("foo"));
                    Assert.AreEqual(insertedDocument.GetField <int>("bar"), document.GetField <int>("bar"));
                }
            }
        }
Exemplo n.º 12
0
        public void ShouldDeserializeDateTime()
        {
            string recordString = "datetime:1296279468000t,date:1306281600000a,embedded:(datetime:1296279468000t,date:1306281600000a),array:[1296279468000t,1306281600000a]";

            ODocument document = ODocument.Deserialize(recordString);

            // check for fields existence
            Assert.AreEqual(document.HasField("datetime"), true);
            Assert.AreEqual(document.HasField("date"), true);
            Assert.AreEqual(document.HasField("embedded.datetime"), true);
            Assert.AreEqual(document.HasField("embedded.date"), true);
            Assert.AreEqual(document.HasField("array"), true);

            // check for fields values
            Assert.AreEqual(document.GetField <DateTime>("datetime"), new DateTime(2011, 1, 29, 5, 37, 48));
            Assert.AreEqual(document.GetField <DateTime>("date"), new DateTime(2011, 5, 25, 0, 0, 0));
            Assert.AreEqual(document.GetField <DateTime>("embedded.datetime"), new DateTime(2011, 1, 29, 5, 37, 48));
            Assert.AreEqual(document.GetField <DateTime>("embedded.date"), new DateTime(2011, 5, 25, 0, 0, 0));

            List <DateTime> array = document.GetField <List <DateTime> >("array");

            Assert.AreEqual(array.Count, 2);
            Assert.AreEqual(array[0], new DateTime(2011, 1, 29, 5, 37, 48));
            Assert.AreEqual(array[1], new DateTime(2011, 5, 25, 0, 0, 0));
        }
Exemplo n.º 13
0
        public void TestLoadWithFetchPlanNoLinks()
        {
            using (var testContext = new TestDatabaseContext())
            using (var database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
            {
                // prerequisites
                database
                    .Create.Class("TestClass")
                    .Run();

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

                ODocument insertedDocument = database
                    .Insert(document)
                    .Into("TestClass")
                    .Run();
                var loaded = database.Load.ORID(insertedDocument.ORID).FetchPlan("*:1").Run();
                Assert.AreEqual("TestClass", loaded.OClassName);
                Assert.AreEqual(document.GetField<string>("foo"), loaded.GetField<string>("foo"));
                Assert.AreEqual(document.GetField<int>("bar"), loaded.GetField<int>("bar"));
                Assert.AreEqual(insertedDocument.ORID, loaded.ORID);

            }
        }
Exemplo n.º 14
0
        public void ShouldDeserializeSingleAndSetOfOrids()
        {
            string recordString = "single:#10:12345,set:<#11:123,#22:1234,#33:1234567>,singleSet:<#44:44>";

            ODocument document = ODocument.Deserialize(recordString);


            // check for fields existence
            Assert.AreEqual(document.HasField("single"), true);
            Assert.AreEqual(document.HasField("set"), true);

            // check for fields values
            Assert.AreEqual(document.GetField <ORID>("single"), new ORID(10, 12345));
            HashSet <ORID> collection = document.GetField <HashSet <ORID> >("set");

            Assert.AreEqual(collection.Count, 3);
            Assert.IsTrue(collection.Contains(new ORID(11, 123)));
            Assert.IsTrue(collection.Contains(new ORID(22, 1234)));
            Assert.IsTrue(collection.Contains(new ORID(33, 1234567)));

            HashSet <ORID> singleSet = document.GetField <HashSet <ORID> >("singleSet");

            Assert.AreEqual(singleSet.Count, 1);
            Assert.IsTrue(singleSet.Contains(new ORID(44, 44)));
        }
Exemplo n.º 15
0
        public void ShouldDeserializeBoolean()
        {
            string recordString = "singleT:true,singleF:false,embedded:(singleT:true,singleF:false),array:[true,false]";

            ODocument document = ODocument.Deserialize(recordString);

            // check for fields existence
            Assert.AreEqual(document.HasField("singleT"), true);
            Assert.AreEqual(document.HasField("singleF"), true);
            Assert.AreEqual(document.HasField("embedded.singleT"), true);
            Assert.AreEqual(document.HasField("embedded.singleF"), true);
            Assert.AreEqual(document.HasField("array"), true);

            // check for fields values
            Assert.AreEqual(document.GetField <bool>("singleT"), true);
            Assert.AreEqual(document.GetField <bool>("singleF"), false);
            Assert.AreEqual(document.GetField <bool>("embedded.singleT"), true);
            Assert.AreEqual(document.GetField <bool>("embedded.singleF"), false);

            List <bool> array = document.GetField <List <bool> >("array");

            Assert.AreEqual(array.Count, 2);
            Assert.AreEqual(array[0], true);
            Assert.AreEqual(array[1], false);
        }
Exemplo n.º 16
0
        public void TestLoadNoFetchPlan()
        {
            using (var testContext = new TestDatabaseContext())
            {
                using (var database = new ODatabase(TestConnection.ConnectionOptions))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    ODocument insertedDocument = database
                                                 .Insert(document)
                                                 .Into("TestClass")
                                                 .Run();
                    var loaded = database.Load.ORID(insertedDocument.ORID).Run();
                    Assert.AreEqual(loaded.OClassName, "TestClass");
                    Assert.AreEqual(loaded.GetField <string>("foo"), document.GetField <string>("foo"));
                    Assert.AreEqual(loaded.GetField <int>("bar"), document.GetField <int>("bar"));
                    Assert.AreEqual(insertedDocument.ORID, loaded.ORID);
                }
            }
        }
Exemplo n.º 17
0
        public void ShouldCreateDocumentFromDocument()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.ConnectionOptions))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    ODocument createdDocument = database
                                                .Create.Document(document)
                                                .Run();

                    Assert.IsTrue(createdDocument.ORID != null);
                    Assert.AreEqual(createdDocument.OClassName, "TestClass");
                    Assert.AreEqual(createdDocument.GetField <string>("foo"), document.GetField <string>("foo"));
                    Assert.AreEqual(createdDocument.GetField <int>("bar"), document.GetField <int>("bar"));
                }
            }
        }
Exemplo n.º 18
0
        public void ShouldInsertDocumentIntoCluster()
        {
            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();

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

                    ODocument insertedDocument = database
                                                 .Insert(document)
                                                 .Into("TestClass")
                                                 .Cluster("TestCluster")
                                                 .Run();

                    Assert.IsTrue(insertedDocument.ORID != null);
                    Assert.AreEqual(insertedDocument.OClassName, "TestClass");
                    Assert.AreEqual(insertedDocument.GetField <string>("foo"), document.GetField <string>("foo"));
                    Assert.AreEqual(insertedDocument.GetField <int>("bar"), document.GetField <int>("bar"));
                }
            }
        }
        public void TestLoadWithFetchPlanNoLinks()
        {
            using (var testContext = new TestDatabaseContext())
                using (var database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    ODocument insertedDocument = database
                                                 .Insert(document)
                                                 .Into("TestClass")
                                                 .Run();
                    var loaded = database.Load.ORID(insertedDocument.ORID).FetchPlan("*:1").Run();
                    Assert.Equal("TestClass", loaded.OClassName);
                    Assert.Equal(document.GetField <string>("foo"), loaded.GetField <string>("foo"));
                    Assert.Equal(document.GetField <int>("bar"), loaded.GetField <int>("bar"));
                    Assert.Equal(insertedDocument.ORID, loaded.ORID);
                }
        }
        public void CreateVertexWithHeavyEdgeTX()
        {
            var v1 = new ODocument {
                OClassName = "TestVertex"
            };

            v1.SetField("Name", "First");
            v1.SetField("Bar", 1);

            var v2 = new ODocument {
                OClassName = "TestVertex"
            };

            v2.SetField("Name", "Second");
            v2.SetField("Bar", 2);

            var e1 = new ODocument {
                OClassName = "TestEdge"
            };

            e1.SetField("Weight", 1.3f);

            // Add records to the transaction
            _database.Transaction.Add(v1);
            _database.Transaction.Add(v2);
            _database.Transaction.Add(e1);

            // link records
            v1.SetField("in_TestEdge", e1.ORID);
            v2.SetField("out_TestEdge", e1.ORID);
            e1.SetField("in", v1.ORID);
            e1.SetField("out", v2.ORID);

            _database.Transaction.Commit();

            Assert.NotNull(v1.ORID);
            Assert.NotNull(v2.ORID);
            Assert.NotNull(e1.ORID);

            var lv1 = _database.Load.ORID(v1.ORID).Run();
            var lv2 = _database.Load.ORID(v2.ORID).Run();
            var le1 = _database.Load.ORID(e1.ORID).Run();

            Assert.Equal(v1.GetField <string>("Name"), lv1.GetField <string>("Name"));
            Assert.Equal(v1.GetField <int>("Bar"), lv1.GetField <int>("Bar"));

            Assert.Equal(v2.GetField <string>("Name"), lv2.GetField <string>("Name"));
            Assert.Equal(v2.GetField <int>("Bar"), lv2.GetField <int>("Bar"));

            Assert.Equal(e1.GetField <float>("Weight"), le1.GetField <float>("Weight"));

            Assert.Equal(e1.ORID, lv1.GetField <ORID>("in_TestEdge"));
            Assert.Equal(e1.ORID, lv2.GetField <ORID>("out_TestEdge"));

            Assert.Equal(v1.ORID, le1.GetField <ORID>("in"));
            Assert.Equal(v2.ORID, le1.GetField <ORID>("out"));
        }
Exemplo n.º 21
0
        public void ShouldUpdateOridSet()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GLOBAL_TEST_DATABASE_ALIAS))
                {
                    // 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();

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

                    int documentsUpdated = database
                                           .Update(document2.ORID)
                                           .Set(document2)
                                           .Run();

                    Assert.AreEqual(documentsUpdated, 1);

                    List <ODocument> documents = database
                                                 .Select()
                                                 .From("TestClass")
                                                 .Where("bar").Equals(54321)
                                                 .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"));
                        Assert.AreEqual(documents[i].GetField <string>("baz"), document2.GetField <string>("baz"));
                    }
                }
            }
        }
Exemplo n.º 22
0
        public void ShouldUpdateClass()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    // prerequisites
                    database
                    .Create.Class("TestClass")
                    .Run();

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

                    database
                    .Insert(document)
                    .Into("TestClass")
                    .Run();

                    database
                    .Insert(document)
                    .Into("TestClass")
                    .Run();

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

                    int documentsUpdated = database
                                           .Update(document)
                                           .Class("TestClass")
                                           .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, "TestClass");
                        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"));
                    }
                }
            }
        }
Exemplo n.º 23
0
        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"));
                    }
                }
            }
        }
Exemplo n.º 24
0
        public void ShouldUpdateRecord()
        {
            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();

                    ODocument docToUpdate = new ODocument()
                                            .SetField("bar", 54321)
                                            .SetField("baz", "new baz value");

                    int documentsUpdated = database
                                           .Update(docToUpdate)
                                           .Record(document2.ORID)
                                           .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"), docToUpdate.GetField <int>("bar"));
                    Assert.AreEqual(documents[0].GetField <string>("baz"), docToUpdate.GetField <string>("baz"));
                }
            }
        }
Exemplo n.º 25
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"));
                }
            }
        }
Exemplo n.º 26
0
        public void CreateVertexWithHeavyEdgeTX()
        {
            var v1 = new ODocument { OClassName = "TestVertex" };
            v1.SetField("Name", "First");
            v1.SetField("Bar", 1);

            var v2 = new ODocument { OClassName = "TestVertex" };
            v2.SetField("Name", "Second");
            v2.SetField("Bar", 2);

            var e1 = new ODocument { OClassName = "TestEdge" };
            e1.SetField("Weight", 1.3f);

            // Add records to the transaction
            _database.Transaction.Add(v1);
            _database.Transaction.Add(v2);
            _database.Transaction.Add(e1);

            // link records
            v1.SetField("in_TestEdge", e1.ORID);
            v2.SetField("out_TestEdge", e1.ORID);
            e1.SetField("in", v1.ORID);
            e1.SetField("out", v2.ORID);

            _database.Transaction.Commit();

            Assert.NotNull(v1.ORID);
            Assert.NotNull(v2.ORID);
            Assert.NotNull(e1.ORID);

            var lv1 = _database.Load.ORID(v1.ORID).Run();
            var lv2 = _database.Load.ORID(v2.ORID).Run();
            var le1 = _database.Load.ORID(e1.ORID).Run();

            Assert.Equal(v1.GetField<string>("Name"), lv1.GetField<string>("Name"));
            Assert.Equal(v1.GetField<int>("Bar"), lv1.GetField<int>("Bar"));

            Assert.Equal(v2.GetField<string>("Name"), lv2.GetField<string>("Name"));
            Assert.Equal(v2.GetField<int>("Bar"), lv2.GetField<int>("Bar"));

            Assert.Equal(e1.GetField<float>("Weight"), le1.GetField<float>("Weight"));

            Assert.Equal(e1.ORID, lv1.GetField<ORID>("in_TestEdge"));
            Assert.Equal(e1.ORID, lv2.GetField<ORID>("out_TestEdge"));

            Assert.Equal(v1.ORID, le1.GetField<ORID>("in"));
            Assert.Equal(v2.ORID, le1.GetField<ORID>("out"));

        }
Exemplo n.º 27
0
        private void InitializeDatabaseConnection(string databaseName, ODatabaseType databaseType, string userName, string userPassword)
        {
            _readBuffer = new byte[OClient.BufferLenght];

            // initiate socket connection
            try
            {
                _socket = new TcpClient(Hostname, Port);
                _socket.ReceiveTimeout = RECIVE_TIMEOUT;
            }
            catch (SocketException ex)
            {
                throw new OException(OExceptionType.Connection, ex.Message, ex.InnerException);
            }

            _networkStream = new BufferedStream(_socket.GetStream());
            _networkStream.Read(_readBuffer, 0, 2);

            OClient.ProtocolVersion = ProtocolVersion = BinarySerializer.ToShort(_readBuffer.Take(2).ToArray());

            // execute db_open operation
            DbOpen operation = new DbOpen(null);

            operation.DatabaseName = databaseName;
            operation.DatabaseType = databaseType;
            operation.UserName     = userName;
            operation.UserPassword = userPassword;

            Document  = ExecuteOperation(operation);
            SessionId = Document.GetField <int>("SessionId");
        }
        //[Fact]
        public void ShouldDeserializeWholeStructure()
        {
            /*
                The whole record is structured in three main segments
                +---------------+------------------+---------------+-------------+
                | version:byte   | className:string | header:byte[] | data:byte[]  |
                +---------------+------------------+---------------+-------------+
             */


            //byte version = 0;
            byte[] className = Encoding.UTF8.GetBytes("TestClass");
            byte[] header = new byte[0];
            byte[] data = new byte[0];

            //string serString = "ABJUZXN0Q2xhc3MpAAAAEQDI/wE=";
            string serString1 = "AAxQZXJzb24EaWQAAABEBwhuYW1lAAAAaQcOc3VybmFtZQAAAHAHEGJpcnRoZGF5AAAAdwYQY2hpbGRyZW4AAAB9AQBIZjk1M2VjNmMtNGYyMC00NDlhLWE2ODQtYjQ2ODkxNmU4NmM3DEJpbGx5MQxNYXllczGUlfWVo1IC/wE=";

            var document = new ODocument();
            document.OClassName = "TestClass";
            document.SetField<DateTime>("_date", DateTime.Now);

            var createdDocument = database
                .Create
                .Document(document)
                .Run();

            Assert.Equal(document.GetField<DateTime>("_date").Date, createdDocument.GetField<DateTime>("eeee"));
            var serBytes1 = Convert.FromBase64String(serString1);
            var doc = serializer.Deserialize(serBytes1, new ODocument());
        }
        public void TestGermanFloatCulture()
        {
            var   floatValue = "108,4";
            float @float;

#if DNX451
            float.TryParse(floatValue, NumberStyles.Any, CultureInfo.GetCultureInfo("de-DE"), out @float);
#elif DNXCORE50
            CultureInfo germanCulture = new CultureInfo("de-DE");
            float.TryParse(floatValue, NumberStyles.Any, germanCulture, out @float);
#else
            float = 0f;
#error No implementation for the target DNX
#endif


            var doc = new ODocument {
                OClassName = "TestVertex"
            }
            .SetField("floatField", @float);

            var insertedDoc = _database.Insert(doc).Run();

            Assert.NotNull(insertedDoc.ORID);
            Assert.Equal(doc.GetField <float>("@float"), insertedDoc.GetField <float>("@float"));
        }
Exemplo n.º 30
0
        private void InitializeServerConnection(string userName, string userPassword)
        {
            _readBuffer = new byte[OClient.BufferLenght];

            // initiate socket connection
            try
            {
                _socket = new TcpClient(Hostname, Port);
            }
            catch (SocketException ex)
            {
                throw new OException(OExceptionType.Connection, ex.Message, ex.InnerException);
            }

            _networkStream = _socket.GetStream();
            _networkStream.Read(_readBuffer, 0, 2);

            ProtocolVersion = BinarySerializer.ToShort(_readBuffer.Take(2).ToArray());

            // execute connect operation
            Connect operation = new Connect();

            operation.UserName     = userName;
            operation.UserPassword = userPassword;

            Document  = ExecuteOperation <Connect>(operation);
            SessionId = Document.GetField <int>("SessionId");
        }
Exemplo n.º 31
0
        public void ShouldDeserializeComplexEmbeddedrecordsArray()
        {
            string recordString = "array:[(zak1:(nick:[(joe1:\"js1\"),(joe2:\"js2\"),(joe3:\"js3\")])),(zak2:(nick:[(joe4:\"js4\"),(joe5:\"js5\"),(joe6:\"js6\")]))]";

            ODocument document = ODocument.Deserialize(recordString);

            // check for fields existence
            Assert.AreEqual(document.HasField("array"), true);

            // check for fields values
            List <ODocument> arrayOfZaks = document.GetField <List <ODocument> >("array");

            Assert.AreEqual(arrayOfZaks.Count, 2);

            List <ODocument> arrayOfJoes1 = arrayOfZaks[0].GetField <List <ODocument> >("zak1.nick");

            Assert.AreEqual(arrayOfJoes1.Count, 3);
            Assert.AreEqual(arrayOfJoes1[0].GetField <string>("joe1"), "js1");
            Assert.AreEqual(arrayOfJoes1[1].GetField <string>("joe2"), "js2");
            Assert.AreEqual(arrayOfJoes1[2].GetField <string>("joe3"), "js3");

            List <ODocument> arrayOfJoes2 = arrayOfZaks[1].GetField <List <ODocument> >("zak2.nick");

            Assert.AreEqual(arrayOfJoes2.Count, 3);
            Assert.AreEqual(arrayOfJoes2[0].GetField <string>("joe4"), "js4");
            Assert.AreEqual(arrayOfJoes2[1].GetField <string>("joe5"), "js5");
            Assert.AreEqual(arrayOfJoes2[2].GetField <string>("joe6"), "js6");
        }
        //[Fact]
        public void ShouldDeserializeWholeStructure()
        {
            /*
             *  The whole record is structured in three main segments
             +---------------+------------------+---------------+-------------+
             | version:byte   | className:string | header:byte[] | data:byte[]  |
             +---------------+------------------+---------------+-------------+
             */


            //byte version = 0;
            byte[] className = Encoding.UTF8.GetBytes("TestClass");
            byte[] header    = new byte[0];
            byte[] data      = new byte[0];

            //string serString = "ABJUZXN0Q2xhc3MpAAAAEQDI/wE=";
            string serString1 = "AAxQZXJzb24EaWQAAABEBwhuYW1lAAAAaQcOc3VybmFtZQAAAHAHEGJpcnRoZGF5AAAAdwYQY2hpbGRyZW4AAAB9AQBIZjk1M2VjNmMtNGYyMC00NDlhLWE2ODQtYjQ2ODkxNmU4NmM3DEJpbGx5MQxNYXllczGUlfWVo1IC/wE=";

            var document = new ODocument();

            document.OClassName = "TestClass";
            document.SetField <DateTime>("_date", DateTime.Now);

            var createdDocument = database
                                  .Create
                                  .Document(document)
                                  .Run();

            Assert.Equal(document.GetField <DateTime>("_date").Date, createdDocument.GetField <DateTime>("eeee"));
            var serBytes1 = Convert.FromBase64String(serString1);
            var doc       = serializer.Deserialize(serBytes1, new ODocument());
        }
        protected override void MapToNamedField(ODocument document, TTarget typedObject)
        {
            object sourcePropertyValue = document.GetField <object>(_fieldPath);

            IList collection = sourcePropertyValue as IList;

            if (collection == null) // if we only have one item currently stored (but scope for more) we create a temporary list and put our single item in it.
            {
                collection = new ArrayList();
                if (sourcePropertyValue != null)
                {
                    collection.Add(sourcePropertyValue);
                }
            }

            // create instance of property type
            IList collectionInstance = CreateListInstance(collection.Count);

            for (int i = 0; i < collection.Count; i++)
            {
                var    t       = collection[i];
                object oMapped = t;
                if (_needsMapping)
                {
                    object element = _elementFactory();
                    _mapper.ToObject((ODocument)t, element);
                    oMapped = element;
                }

                AddItemToList(collectionInstance, i, oMapped);
            }

            SetPropertyValue(typedObject, collectionInstance);
        }
        public override void MapToObject(ODocument document, TTarget typedObject)
        {
            TProperty result = new TProperty();

            TypeMapper <TProperty> .Instance.ToObject(document.GetField <ODocument>(_fieldPath), result);

            SetPropertyValue(typedObject, result);
        }
        internal static string Serialize(ODocument document)
        {
            if (!document.HasField("@ClassName"))
            {
                throw new OException(OExceptionType.Serialization, "Document doesn't contain @ClassName field which is required for serialization.");
            }

            return document.GetField<string>("@ClassName") + "@" + SerializeDocument(document);
        }
Exemplo n.º 36
0
        public void ShouldDeserializeString()
        {
            string recordString = "simple:\"whoa this is awesome\",singleQuoted:\"a" + "\\" + "\"\",doubleQuoted:\"" + "\\" + "\"adsf" + "\\" + "\"\",twoBackslashes:\"" + "\\a" + "\\a" + "\"";

            ODocument document = ODocument.Deserialize(recordString);

            // check for fields existence
            Assert.AreEqual(document.HasField("simple"), true);
            Assert.AreEqual(document.HasField("singleQuoted"), true);
            Assert.AreEqual(document.HasField("doubleQuoted"), true);
            Assert.AreEqual(document.HasField("twoBackslashes"), true);

            // check for fields values
            Assert.AreEqual(document.GetField <string>("simple"), "whoa this is awesome");
            Assert.AreEqual(document.GetField <string>("singleQuoted"), "a\"");
            Assert.AreEqual(document.GetField <string>("doubleQuoted"), "\"adsf\"");
            Assert.AreEqual(document.GetField <string>("twoBackslashes"), "\\a\\a");
        }
Exemplo n.º 37
0
        internal static string Serialize(ODocument document)
        {
            if (!document.HasField("@ClassName"))
            {
                throw new OException(OExceptionType.Serialization, "Document doesn't contain @ClassName field which is required for serialization.");
            }

            return(document.GetField <string>("@ClassName") + "@" + SerializeDocument(document));
        }
        public byte[] Serialize(ODocument document)
        {
            if (!document.HasField("@OClassName"))
            {
                throw new OException(OExceptionType.Serialization, "Document doesn't contain @OClassName field which is required for serialization.");
            }

            return Encoding.UTF8.GetBytes(document.GetField<string>("@OClassName") + "@" + SerializeDocument(document));
        }
        public byte[] Serialize(ODocument document)
        {
            if (!document.HasField("@OClassName"))
            {
                throw new OException(OExceptionType.Serialization, "Document doesn't contain @OClassName field which is required for serialization.");
            }

            return(Encoding.UTF8.GetBytes(document.GetField <string>("@OClassName") + "@" + SerializeDocument(document)));
        }
        protected override void MapToNamedField(ODocument document, TTarget typedObject)
        {
            ODocument sourcePropertyValue = document.GetField <ODocument>(_fieldPath);
            var       collection          = CreateCollectionInstance(sourcePropertyValue.Count);

            AddItemToCollection(collection, 0, sourcePropertyValue);

            SetPropertyValue(typedObject, collection);
        }
Exemplo n.º 41
0
        public void ShouldInsertValuesWithNewLines()
        {
            _database
                         .Create.Class("TestClass")
                         .Run();

            ODocument document = new ODocument();
            document.OClassName = "TestClass";
            document
                .SetField("foo", "foo string value \r\n test te5435ttrtr")
                .SetField("bar", 12345);

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

            Assert.IsTrue(insertedDocument.ORID != null);
            Assert.AreEqual(insertedDocument.OClassName, "TestClass");
            Assert.AreEqual(insertedDocument.GetField<string>("foo"), document.GetField<string>("foo"));
            Assert.AreEqual(insertedDocument.GetField<int>("bar"), document.GetField<int>("bar"));
        }
Exemplo n.º 42
0
        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.IsTrue(insertedDocument.ORID != null);
            Assert.AreEqual(insertedDocument.OClassName, "TestClass");
            Assert.AreEqual(insertedDocument.GetField<string>("foo"), document.GetField<string>("foo"));
            Assert.AreEqual(insertedDocument.GetField<int>("bar"), document.GetField<int>("bar"));


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

            Assert.AreEqual(documents.Count, 1);

            for (int i = 0; i < documents.Count; i++)
            {
                Assert.AreEqual(documents[i].ORID, insertedDocument.ORID);
                Assert.AreEqual(documents[i].OClassName, insertedDocument.OClassName);
                Assert.AreEqual(documents[i].GetField<string>("foo"), insertedDocument.GetField<string>("foo"));
                Assert.AreEqual(documents[i].GetField<int>("bar"), insertedDocument.GetField<int>("bar"));
            }
        }
Exemplo n.º 43
0
        public void TestGermanFloatCulture()
        {
            var floatValue = "108,4";

            float @float;
            float.TryParse(floatValue, NumberStyles.Any, CultureInfo.GetCultureInfo("de-DE"), out @float);

            var doc = new ODocument { OClassName = "TestVertex" }
                .SetField("floatField", @float);

            var insertedDoc = _database.Insert(doc).Run();

            Assert.NotNull(insertedDoc.ORID);
            Assert.Equal(doc.GetField<float>("@float"), insertedDoc.GetField<float>("@float"));
        }
Exemplo n.º 44
0
        private void InitializeServerConnection(string userName, string userPassword)
        {
            _readBuffer = new byte[OClient.BufferLenght];

            // initiate socket connection
            try
            {
                _socket = new TcpClient(Hostname, Port);
            }
            catch (SocketException ex)
            {
                throw new OException(OExceptionType.Connection, ex.Message, ex.InnerException);
            }

            _networkStream = new BufferedStream(_socket.GetStream());
            _networkStream.Read(_readBuffer, 0, 2);

            OClient.ProtocolVersion = ProtocolVersion = BinarySerializer.ToShort(_readBuffer.Take(2).ToArray());

            // execute connect operation
            Connect operation = new Connect();
            operation.UserName = userName;
            operation.UserPassword = userPassword;

            Document = ExecuteOperation(operation);
            SessionId = Document.GetField<int>("SessionId");
        }
 private void validateMetadata(ODocument metadata, OType expectedType)
 {
     Assert.IsNotNull(metadata);
     Assert.AreEqual(expectedType, (OType)metadata.GetField<int>("type"));
 }
Exemplo n.º 46
0
        public void ShouldCreateEdgeUntyped()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    ODocument document = new ODocument();
                    document.SetField("foo", "foo string value");
                    document.SetField("bar", 12345);

                    // create test class for edges
                    database
                        .Create.Class("TestEdgeClass")
                        .Extends("OGraphEdge")
                        .Run();

                    // create test vertices which will be connected by edge
                    ORecord vertex1 = database
                        .Create.Vertex("OGraphVertex")
                        .Set(document)
                        .Run();
                    ORecord vertex2 = database
                        .Create.Vertex("OGraphVertex")
                        .Set(document)
                        .Run();

                    // connect previous vertices with edge
                    ORecord edge1 = database
                        .Create.Edge("TestEdgeClass")
                        .From(vertex1.ORID)
                        .To(vertex2.ORID)
                        .Set(document)
                        .Run();

                    Assert.AreEqual(edge1.HasField("in"), true);
                    Assert.AreEqual(edge1.HasField("out"), true);
                    Assert.AreEqual(edge1.HasField("foo"), true);
                    Assert.AreEqual(edge1.HasField("bar"), true);

                    Assert.AreEqual(edge1.GetField<ORID>("out"), vertex1.ORID);
                    Assert.AreEqual(edge1.GetField<ORID>("in"), vertex2.ORID);
                    Assert.AreEqual(edge1.GetField<string>("foo"), document.GetField<string>("foo"));
                    Assert.AreEqual(edge1.GetField<int>("bar"), document.GetField<int>("bar"));

                    // connect previous vertices with another edge using multiple set statements
                    ORecord edge2 = database
                        .Create.Edge("TestEdgeClass")
                        .From(vertex2.ORID)
                        .To(vertex1.ORID)
                        .Set("foo", "foo string value2")
                        .Also("bar", 54321)
                        .Run();

                    Assert.AreEqual(edge2.HasField("in"), true);
                    Assert.AreEqual(edge2.HasField("out"), true);
                    Assert.AreEqual(edge2.HasField("foo"), true);
                    Assert.AreEqual(edge2.HasField("bar"), true);

                    Assert.AreEqual(edge2.GetField<ORID>("out"), vertex2.ORID);
                    Assert.AreEqual(edge2.GetField<ORID>("in"), vertex1.ORID);
                    Assert.AreEqual(edge2.GetField<string>("foo"), "foo string value2");
                    Assert.AreEqual(edge2.GetField<int>("bar"), 54321);
                }
            }
        }
Exemplo n.º 47
0
        public void ShouldCreateVertexUntyped()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    ODocument document = new ODocument();
                    document.SetField("foo", "foo string value");
                    document.SetField("bar", 12345);

                    List<string> options = new List<string>();
                    options.Add("option1");
                    options.Add("option2");

                    document.SetField("options", options);

                    // 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(document)
                        .Run();

                    Assert.AreEqual(loadedVertex1.HasField("foo"), true);
                    Assert.AreEqual(loadedVertex1.HasField("bar"), true);
                    Assert.AreEqual(loadedVertex1.HasField("options"), true);

                    Assert.AreEqual(loadedVertex1.GetField<string>("foo"), document.GetField<string>("foo"));
                    Assert.AreEqual(loadedVertex1.GetField<int>("bar"), document.GetField<int>("bar"));

                    List<string> loadedOptions = loadedVertex1.GetField<List<string>>("options");
                    Assert.AreEqual(loadedOptions.Count, options.Count);
                    Assert.AreEqual(loadedOptions[0], options[0]);
                    Assert.AreEqual(loadedOptions[1], options[1]);

                    // create test vertex using multiple set statements
                    ORecord loadedVertex2 = database
                        .Create.Vertex("TestVertexClass")
                        .Set("foo", "foo string value2")
                        .Also("bar", 54321)
                        .Run();

                    Assert.AreEqual(loadedVertex2.HasField("foo"), true);
                    Assert.AreEqual(loadedVertex2.HasField("bar"), true);

                    Assert.AreEqual(loadedVertex2.GetField<string>("foo"), "foo string value2");
                    Assert.AreEqual(loadedVertex2.GetField<int>("bar"), 54321);
                }
            }
        }
        public void ShouldCreateDocumentClassSet()
        {
            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 createdDocument = database
                        .Create.Document("TestClass")
                        .Set(document)
                        .Run();

                    Assert.NotNull(createdDocument.ORID);
                    Assert.Equal("TestClass", createdDocument.OClassName);
                    Assert.Equal(document.GetField<string>("foo"), createdDocument.GetField<string>("foo"));
                    Assert.Equal(document.GetField<int>("bar"), createdDocument.GetField<int>("bar"));
                }
            }
        }
        private void readOType(BinaryReader reader, string fieldName, ODocument document, OType type)
        {
            switch (type)
            {
                case OType.Integer:
                    document.SetField<int>(fieldName, readAsInteger(reader));
                    break;
                case OType.Long:
                    document.SetField<long>(fieldName, readAsLong(reader));
                    break;
                case OType.Short:
                    document.SetField<short>(fieldName, readAsShort(reader));
                    break;
                case OType.String:
                    document.SetField<string>(fieldName, readString(reader));
                    break;
                case OType.Double:
                    document.SetField<double>(fieldName, BitConverter.Int64BitsToDouble(readLong(reader)));
                    break;
                case OType.Float:
                    document.SetField<float>(fieldName, readFloat(reader));
                    break;
                case OType.Decimal:
                    var scale = reader.ReadInt32EndianAware();

                    var valueSize = reader.ReadInt32EndianAware();

                    // read Fine the value
                    var valuex = reader.ReadBytesRequired(valueSize);

                    Int64 x1 = 0;

                    if ((valuex[0] & 0x80) == 0x80)
                        x1 = (sbyte)valuex[0];
                    else
                        x1 = valuex[0];

                    for (int i = 1; i < valuex.Length; i++)
                    {
                        x1 = (x1 << 8) | valuex[i];
                    }

                    try
                    {
                        document.SetField(fieldName, new Decimal(x1 * Math.Pow(10, (-1) * scale)));
                    }
                    catch (OverflowException)
                    {
                        document.SetField(fieldName, x1 * Math.Pow(10, (-1) * scale));
                    }
                    break;
                case OType.Byte:
                    document.SetField<byte>(fieldName, reader.ReadByte());
                    break;
                case OType.Boolean:
                    document.SetField<bool>(fieldName, reader.ReadByte() == 1 ? true : false);
                    break;
                case OType.DateTime:
                    document.SetField<DateTime>(fieldName, readDateTime(reader));
                    break;
                case OType.Date:
                    document.SetField<DateTime>(fieldName, readDate(reader));
                    break;
                case OType.EmbeddedList:
                    var listLength = readAsInteger(reader);
                    OType embeddedListRecorType = (OType)reader.ReadByte();
                    List<Object> embeddedList = new List<Object>();
                    for (int i = 0; i < listLength; i++)
                    {
                        var d = new ODocument();
                        OType dataType = (OType)reader.ReadByte();
                        readOType(reader, i.ToString(), d, dataType);
                        embeddedList.AddRange(d.Values);
                    }
                    document.SetField(fieldName, embeddedList);
                    break;
                case OType.EmbeddedSet:
                    var embeddedSetLen = readAsInteger(reader);
                    OType embeddedSetRecorType = (OType)reader.ReadByte();
                    HashSet<ODocument> embeddedSet = new HashSet<ODocument>();
                    for (int i = 0; i < embeddedSetLen; i++)
                    {
                        var d = new ODocument();
                        OType dataType = (OType)reader.ReadByte();
                        readOType(reader, "", d, dataType);
                        embeddedSet.Add(d);
                    }
                    document.SetField(fieldName, embeddedSet);
                    break;
                case OType.EmbeddedMap:
                    /* 
                     * header:headerStructure | values:valueStructure
                     * headerStructure
                     * ===============
                     * keyType:byte | keyValue:byte[]
                     * 
                     * valueStructure
                     * ==============
                     * valueType:byte | value:byte[]
                    */
                    var size = readAsInteger(reader);

                    var fd = new FieldDefinition[size];
                    Dictionary<string, Object> map = new Dictionary<string, object>();
                    for (int i = 0; i < size; i++)
                    {
                        fd[i] = new FieldDefinition();

                        var d = new ODocument();
                        var keyType = (OType)reader.ReadByte();
                        if (keyType != OType.String)
                            throw new NotImplementedException("key type " + keyType + " not implemented for EmbededMap");
                        readOType(reader, "key", d, keyType);

                        fd[i].FieldName = d.GetField<string>("key");
                        fd[i].Pointer = reader.ReadInt32EndianAware();
                        fd[i].DataType = (OType)reader.ReadByte();
                    }
                    for (int i = 0; i < size; i++)
                    {
                        var d = new ODocument();
                        if (fd[i].Pointer > 0)
                        {
                            readOType(reader, "value", d, fd[i].DataType);
                            map.Add(fd[i].FieldName, d.GetField<object>("value"));
                        }
                        else
                        {
                            map.Add(fd[i].FieldName, null);
                        }
                    }
                    document.SetField<Dictionary<string, Object>>(fieldName, map);
                    break;
                case OType.Embedded:
                    var version = reader.ReadByte();
                    parseDocument(reader, document);
                    break;
                case OType.Link:
                    var claster = readAsLong(reader);
                    var record = readAsLong(reader);
                    document.SetField(fieldName, new ORID((short)claster, record));
                    break;
                case OType.LinkBag:
                    var rids = new HashSet<ORID>();
                    var config = reader.ReadByte();
                    if ((config & 2) == 2)
                    {
                        // uuid parsing is not implemented
                        config += 16;
                    }

                    if ((config & 1) == 1) // 1 - embedded,0 - tree-based 
                    {
                        var entriesSize = reader.ReadInt32EndianAware();
                        for (int j = 0; j < entriesSize; j++)
                        {
                            var clusterid = reader.ReadInt16EndianAware();
                            var clusterposition = reader.ReadInt64EndianAware();
                            rids.Add(new ORID(clusterid, clusterposition));
                        }
                    }
                    else
                    {
                        throw new NotImplementedException("tree based ridbag");
                    }
                    document.SetField(fieldName, rids);
                    break;
                case OType.LinkList:
                    var linkList = readLinkCollection(reader);
                    document.SetField(fieldName, linkList);
                    break;
                case OType.LinkSet:
                    var linkSet = new HashSet<ORID>(readLinkCollection(reader));
                    document.SetField(fieldName, linkSet);
                    break;
                case OType.Any:
                    break;
                default:
                    throw new OException(OExceptionType.Deserialization, "The field type: " + type.ToString() + "not implemented");
            }
        }
Exemplo n.º 50
0
        public void TestLoadWithFetchPlanWithLinks()
        {
            using (var testContext = new TestDatabaseContext())
            using (var database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
            {
                // prerequisites
                database
                    .Create.Class("TestClass")
                    .Extends("V")
                    .Run();

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

                ODocument insertedDocument = database
                    .Insert(document)
                    .Into("TestClass")
                    .Run();

                for (int i = 0; i < 2; i++)
                {

                    ODocument document2 = new ODocument()
                        .SetField("foo", "bar string value")
                        .SetField("bar", 23456);

                    ODocument insertedDocument2 = database
                        .Insert(document2)
                        .Into("TestClass")
                        .Run();
                    database.Create.Edge("E").From(insertedDocument).To(insertedDocument2).Run();
                }


                var loaded = database.Load.ORID(insertedDocument.ORID).FetchPlan("*:1").Run();
                Assert.Equal("TestClass", loaded.OClassName);
                Assert.Equal(document.GetField<string>("foo"), loaded.GetField<string>("foo"));
                Assert.Equal(document.GetField<int>("bar"), loaded.GetField<int>("bar"));
                Assert.Equal(insertedDocument.ORID, loaded.ORID);

            }
        }
        public byte[] Serialize(ODocument document)
        {
            var buffer = new BinaryBuffer();
            ODocument schema = null; // Until Implementing schema this is null class

            // Version
            buffer.Add((byte)SERIALIZER_VERSION);

            // Class Name
            if (!String.IsNullOrEmpty(document.OClassName))
            {
                buffer.WriteVariant(document.OClassName.Length);
                var className = BinarySerializer.ToArray(document.OClassName);
                buffer.AddRange(className);
            }
            else
            {
                var length = BinarySerializer.ToArray((int)0);
                buffer.AddRange(length);
            }

            // Header
            var propNames = document.Keys.Where(k => !k.StartsWith("@")).ToArray();
            var pos = new int[propNames.Length];
            var val = new KeyValuePair<string, Object>[propNames.Length];
            for (var i = 0; i < propNames.Length; i++)
            {
                var prop = propNames[i];
                if (schema != null)
                {

                }
                else
                {
                    buffer.WriteVariant(prop.Length);
                    var propName = BinarySerializer.ToArray(prop);
                    buffer.AddRange(propName);
                    pos[i] = buffer.Allocate(sizeof(int) + 1);
                }
                val[i] = new KeyValuePair<string, object>(prop, document.GetField<object>(prop));
            }

            buffer.WriteVariant(0); // Header stop byte

            // Data
            for (int i = 0; i < val.Length; i++)
            {
                int pointer = 0;
                var value = val[i].Value;
                if (value != null)
                {
                    var valueType = TypeConverter.TypeToDbName(value.GetType());
                    pointer = writeOType(buffer, value, valueType, getLinkedType(valueType, val[i].Key));
                    buffer.Write(pos[i], pointer);
                    if (schema == null)
                    {
                        buffer.Write((pos[i] + sizeof(int)), (byte)valueType);
                    }
                }
            }
            return buffer.ToArray();

        }
Exemplo n.º 52
0
        public void ShouldInsertDocumentIntoCluster()
        {
            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()
                        .SetField("foo", "foo string value")
                        .SetField("bar", 12345);

                    ODocument insertedDocument = database
                        .Insert(document)
                        .Into("TestClass")
                        .Cluster("TestCluster")
                        .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"));
                }
            }
        }
Exemplo n.º 53
0
        public void ShouldUpdateRecord()
        {
            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();

                    ODocument docToUpdate = new ODocument()
                        .SetField("bar", 54321)
                        .SetField("baz", "new baz value");

                    int documentsUpdated = database
                        .Update(docToUpdate)
                        .Record(document2.ORID)
                        .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"), docToUpdate.GetField<int>("bar"));
                    Assert.AreEqual(documents[0].GetField<string>("baz"), docToUpdate.GetField<string>("baz"));
                }
            }
        }