public void TestThatCallingDeleteOnAnEdgeUpdatesTheInAndOutReferencesToo()
        {
            using (TestDatabaseContext testContext = new TestDatabaseContext())
            {
                // Arrange
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    database
                    .Create.Class <TestVertexClass>()
                    .Extends <OVertex>()
                    .Run();
                    database
                    .Create.Class <TestEdgeClass>()
                    .Extends <OEdge>()
                    .Run();

                    var vOut = CreateTestVertex(1);
                    var vIn  = CreateTestVertex(2);
                    var edge = new TestEdgeClass();
                    edge.SetField("item", 1);

                    database.Transaction.Add(vOut);
                    database.Transaction.Add(vIn);
                    database.Transaction.AddEdge(edge, vOut, vIn);

                    database.Transaction.Commit();

                    // Validate arrange
                    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.Equal(createdEdge.OutV, createdVertex1.ORID);
                    Assert.Equal(createdEdge.InV, createdVertex2.ORID);
                }

                // Act
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    var createdEdge = database.Select().From("E").Where("item").Equals(1).ToList <OEdge>().First();

                    database.Transaction.Delete(createdEdge);
                    database.Transaction.Commit();
                }

                // Assert
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    var vOut = database.Select().From("V").Where("bar").Equals(1).ToList <OVertex>().First();
                    var vIn  = database.Select().From("V").Where("bar").Equals(2).ToList <OVertex>().First();

                    var deletedEdge = database.Select().From("E").Where("item").Equals(1).ToList <OEdge>().FirstOrDefault();

                    Assert.Null(deletedEdge);
                    Assert.Equal(vOut.GetField <HashSet <object> >("out_TestEdgeClass").Count, 0);
                    Assert.Equal(vIn.GetField <HashSet <object> >("in_TestEdgeClass").Count, 0);
                }
            }
        }
        public void TestAddEdgeToVerticlaWhichAlreadyHasEdges()
        {
            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 fromV     = CreateTestVertex(1);
                    var toV       = CreateTestVertex(2);
                    var firstEdge = new TestEdgeClass();
                    firstEdge.SetField("item", 1);

                    database.Transaction.Add(fromV);
                    database.Transaction.Add(toV);
                    database.Transaction.AddEdge(firstEdge, fromV, toV);

                    Assert.Equal(fromV.ORID, firstEdge.OutV);
                    Assert.Equal(toV.ORID, firstEdge.InV);

                    database.Transaction.Commit();
                }
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    var fromV = database.Select().From("V").Where("bar").Equals(1).ToList <OVertex>().First();
                    var toV   = database.Select().From("V").Where("bar").Equals(2).ToList <OVertex>().First();

                    var secondEdge = new TestEdgeClass();
                    secondEdge.SetField("item", 2);
                    database.Transaction.AddEdge(secondEdge, fromV, toV);
                    database.Transaction.Commit();
                }
                using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
                {
                    var fromV      = database.Select().From("V").Where("bar").Equals(1).ToList <OVertex>().First();
                    var toV        = database.Select().From("V").Where("bar").Equals(2).ToList <OVertex>().First();
                    var secondEdge = database.Select().From("E").Where("item").Equals(2).ToList <OEdge>().First();

                    Assert.Equal(secondEdge.OutV, fromV.ORID);
                    Assert.Equal(secondEdge.InV, toV.ORID);
                    Assert.Equal(fromV.GetField <HashSet <object> >("out_TestEdgeClass").Count, 2);
                    Assert.Equal(toV.GetField <HashSet <object> >("in_TestEdgeClass").Count, 2);
                }
            }
        }
Ejemplo n.º 3
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));
                }
            }
        }
        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));
                }
            }
        }