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));
        }
Beispiel #3
0
        public void ShouldDeserializeNumbers()
        {
            string recordString = "byte:123b,short:23456s,int:1543345,long:13243432455l,float:1234.432f,double:123123.4324d,bigdecimal:300.5c,embedded:(byte:123b,short:23456s,int:1543345,long:13243432455l,float:1234.432f,double:123123.4324d,bigdecimal:300.5c),array:[123b,23456s,1543345,13243432455l,1234.432f,123123.4324d,300.5c]";

            ODocument document = ODocument.Deserialize(recordString);

            // check for fields existence
            Assert.AreEqual(document.HasField("byte"), true);
            Assert.AreEqual(document.HasField("short"), true);
            Assert.AreEqual(document.HasField("int"), true);
            Assert.AreEqual(document.HasField("long"), true);
            Assert.AreEqual(document.HasField("float"), true);
            Assert.AreEqual(document.HasField("double"), true);
            Assert.AreEqual(document.HasField("bigdecimal"), true);
            Assert.AreEqual(document.HasField("embedded.byte"), true);
            Assert.AreEqual(document.HasField("embedded.short"), true);
            Assert.AreEqual(document.HasField("embedded.int"), true);
            Assert.AreEqual(document.HasField("embedded.long"), true);
            Assert.AreEqual(document.HasField("embedded.float"), true);
            Assert.AreEqual(document.HasField("embedded.double"), true);
            Assert.AreEqual(document.HasField("embedded.bigdecimal"), true);
            Assert.AreEqual(document.HasField("array"), true);

            // check for fields values
            Assert.AreEqual(document.GetField <byte>("byte"), (byte)123);
            Assert.AreEqual(document.GetField <short>("short"), (short)23456);
            Assert.AreEqual(document.GetField <int>("int"), 1543345);
            Assert.AreEqual(document.GetField <long>("long"), 13243432455);
            Assert.AreEqual(document.GetField <float>("float"), 1234.432f);
            Assert.AreEqual(document.GetField <double>("double"), 123123.4324);
            Assert.AreEqual(document.GetField <decimal>("bigdecimal"), 300.5m);
            Assert.AreEqual(document.GetField <byte>("embedded.byte"), (byte)123);
            Assert.AreEqual(document.GetField <short>("embedded.short"), (short)23456);
            Assert.AreEqual(document.GetField <int>("embedded.int"), 1543345);
            Assert.AreEqual(document.GetField <long>("embedded.long"), 13243432455);
            Assert.AreEqual(document.GetField <float>("embedded.float"), 1234.432f);
            Assert.AreEqual(document.GetField <double>("embedded.double"), 123123.4324);
            Assert.AreEqual(document.GetField <decimal>("embedded.bigdecimal"), 300.5m);

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

            Assert.AreEqual(array.Count, 7);
            Assert.AreEqual(array[0], (byte)123);
            Assert.AreEqual(array[1], (short)23456);
            Assert.AreEqual(array[2], 1543345);
            Assert.AreEqual(array[3], 13243432455);
            Assert.AreEqual(array[4], 1234.432f);
            Assert.AreEqual(array[5], 123123.4324);
            Assert.AreEqual(array[6], 300.5m);
        }