public Request Request(int sessionID) { Request request = new Request(); if (_document.ORID != null) { throw new InvalidOperationException(); } CorrectClassName(); var clusterId = _database.GetClusterIdFor(_document.OClassName); _document.ORID = new ORID(clusterId, -1); // standard request fields request.DataItems.Add(new RequestDataItem() { Type = "byte", Data = BinarySerializer.ToArray((byte)OperationType.RECORD_CREATE) }); request.DataItems.Add(new RequestDataItem() { Type = "int", Data = BinarySerializer.ToArray(sessionID) }); if (OClient.ProtocolVersion < 24) { request.DataItems.Add(new RequestDataItem() { Type = "int", Data = BinarySerializer.ToArray((int)-1) }); // data segment id } request.DataItems.Add(new RequestDataItem() { Type = "short", Data = BinarySerializer.ToArray((short)-1) }); request.DataItems.Add(new RequestDataItem() { Type = "string", Data = BinarySerializer.ToArray(_document.Serialize()) }); request.DataItems.Add(new RequestDataItem() { Type = "byte", Data = BinarySerializer.ToArray((byte)'d') }); request.DataItems.Add(new RequestDataItem() { Type = "byte", Data = BinarySerializer.ToArray((byte)0) }); return(request); }
public void TestCreateVertex() { using (TestDatabaseContext testContext = new TestDatabaseContext()) { using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias)) { // prerequisites database .Create.Class("TestVertexClass") .Extends<OVertex>() .Run(); OVertex testVertex = new OVertex(); testVertex.OClassName = "TestVertexClass"; testVertex.SetField("foo", "foo string value"); testVertex.SetField("bar", 12345); Assert.AreEqual(null, testVertex.ORID); database.Transaction.Add(testVertex); Assert.IsNotNull(testVertex.ORID); Assert.IsTrue(testVertex.ORID.ClusterPosition < 0); Assert.AreEqual(-2, testVertex.ORID.ClusterPosition); database.Transaction.Commit(); Assert.IsNotNull(testVertex.ORID); Assert.AreEqual(database.GetClusterIdFor("TestVertexClass"), testVertex.ORID.ClusterId); var createdVertex = database.Load.ORID(testVertex.ORID).Run().To<OVertex>(); Assert.IsTrue(createdVertex.ORID != null); Assert.AreEqual("TestVertexClass", createdVertex.OClassName); Assert.AreEqual("foo string value", createdVertex.GetField<string>("foo")); Assert.AreEqual(12345, createdVertex.GetField<int>("bar")); } using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias)) { OVertex testVertex = new OVertex(); testVertex.OClassName = "TestVertexClass"; testVertex.SetField("foo", "foo string value"); testVertex.SetField("bar", 12345); Assert.AreEqual(null, testVertex.ORID); database.Transaction.Add(testVertex); Assert.IsNotNull(testVertex.ORID); Assert.IsTrue(testVertex.ORID.ClusterPosition < 0); Assert.AreEqual(-2, testVertex.ORID.ClusterPosition); database.Transaction.Commit(); Assert.IsNotNull(testVertex.ORID); Assert.AreEqual(database.GetClusterIdFor("TestVertexClass"), testVertex.ORID.ClusterId); Assert.AreNotEqual(-2, testVertex.ORID.ClusterPosition); var createdVertex = database.Load.ORID(testVertex.ORID).Run().To<OVertex>(); Assert.IsTrue(createdVertex.ORID != null); Assert.AreEqual(createdVertex.OClassName, "TestVertexClass"); Assert.AreEqual(createdVertex.GetField<string>("foo"), "foo string value"); Assert.AreEqual(createdVertex.GetField<int>("bar"), 12345); } } }
public void TestCreateVertex() { using (TestDatabaseContext testContext = new TestDatabaseContext()) { using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias)) { // prerequisites database .Create.Class("TestVertexClass") .Extends <OVertex>() .Run(); OVertex testVertex = new OVertex(); testVertex.OClassName = "TestVertexClass"; testVertex.SetField("foo", "foo string value"); testVertex.SetField("bar", 12345); Assert.AreEqual(null, testVertex.ORID); database.Transaction.Add(testVertex); Assert.IsNotNull(testVertex.ORID); Assert.IsTrue(testVertex.ORID.ClusterPosition < 0); Assert.AreEqual(-2, testVertex.ORID.ClusterPosition); database.Transaction.Commit(); Assert.IsNotNull(testVertex.ORID); Assert.AreEqual(database.GetClusterIdFor("TestVertexClass"), testVertex.ORID.ClusterId); var createdVertex = database.Load.ORID(testVertex.ORID).Run().To <OVertex>(); Assert.IsTrue(createdVertex.ORID != null); Assert.AreEqual("TestVertexClass", createdVertex.OClassName); Assert.AreEqual("foo string value", createdVertex.GetField <string>("foo")); Assert.AreEqual(12345, createdVertex.GetField <int>("bar")); } using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias)) { OVertex testVertex = new OVertex(); testVertex.OClassName = "TestVertexClass"; testVertex.SetField("foo", "foo string value"); testVertex.SetField("bar", 12345); Assert.AreEqual(null, testVertex.ORID); database.Transaction.Add(testVertex); Assert.IsNotNull(testVertex.ORID); Assert.IsTrue(testVertex.ORID.ClusterPosition < 0); Assert.AreEqual(-2, testVertex.ORID.ClusterPosition); database.Transaction.Commit(); Assert.IsNotNull(testVertex.ORID); Assert.AreEqual(database.GetClusterIdFor("TestVertexClass"), testVertex.ORID.ClusterId); Assert.AreNotEqual(-2, testVertex.ORID.ClusterPosition); var createdVertex = database.Load.ORID(testVertex.ORID).Run().To <OVertex>(); Assert.IsTrue(createdVertex.ORID != null); Assert.AreEqual(createdVertex.OClassName, "TestVertexClass"); Assert.AreEqual(createdVertex.GetField <string>("foo"), "foo string value"); Assert.AreEqual(createdVertex.GetField <int>("bar"), 12345); } } }