Esempio n. 1
0
        public void ReadIntoAnother()
        {
            var v1r1 = new Ver1Row
            {
                A = "A string",
                B = 156,
                C = null,
                D = true,
                E = new byte[] { 1, 5, 98 },
                F = new DateTime(1980, 02, 12),
                G = new List <Ver1Row> {
                    new Ver1Row {
                        C = -998, D = null
                    }
                }
            };

            var writer = SlimFormat.Instance.GetWritingStreamer();
            var reader = SlimFormat.Instance.GetReadingStreamer();

            using (var ms = new MemoryStream())
            {
                writer.BindStream(ms);
                ArowSerializer.Serialize(v1r1, writer);
                writer.UnbindStream();

                ms.Position = 0;

                var v2r2 = new Ver2Row();
                reader.BindStream(ms);
                ArowSerializer.Deserialize(v2r2, reader);

                v2r2.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap).See();

                Aver.AreEqual("A string", v2r2.A);

                Aver.AreEqual(156, v2r2.AmorphousData["b"].AsInt());
                Aver.IsNull(v2r2.AmorphousData["c"]);
                Aver.IsTrue(v2r2.AmorphousData["e"] is byte[]);
                Aver.IsNotNull(v2r2.AmorphousData["g"]);
                Aver.IsTrue(v2r2.AmorphousData["g"] is Array);
                Aver.AreEqual(-998, ((JsonDataMap)((object[])v2r2.AmorphousData["g"])[0])["c"].AsInt());

                Aver.AreEqual(0, v2r2.B);
                Aver.AreEqual(null, v2r2.C);
                Aver.AreEqual(true, v2r2.D);
                Aver.IsNull(v2r2.E);
                Aver.AreEqual(new DateTime(1980, 02, 12), v2r2.F);
                Aver.IsNull(v2r2.G);
            }
        }
Esempio n. 2
0
        public void OneByOne()
        {
            var writer = SlimFormat.Instance.GetWritingStreamer();
            var reader = SlimFormat.Instance.GetReadingStreamer();
            var fail   = "";

            using (var ms = new MemoryStream())
            {
                for (var i = 0; i < CASES.Length; i++)
                {
                    var row1 = CASES[i];

                    Console.WriteLine("Test #{0}".Args(i));
                    Console.WriteLine("--------------------------------------------------");
                    Console.WriteLine(row1.ToJSON());


                    ms.Position = 0;

                    writer.BindStream(ms);
                    ArowSerializer.Serialize(row1, writer);
                    writer.UnbindStream();

                    ms.Position = 0;

                    var row2 = new AllArowTypesRow();
                    reader.BindStream(ms);
                    ArowSerializer.Deserialize(row2, reader);
                    reader.UnbindStream();

                    if (!row1.AllFieldsEqual(row2))
                    {
                        Console.WriteLine(row2.ToJSON());
                        Console.WriteLine("FAIL");
                        fail = "The test case #{0} has failed.\nJSON:\n{1}".Args(i, row1.ToJSON());
                    }
                    else
                    {
                        Console.WriteLine("PASS");
                    }

                    Console.WriteLine();
                }
                if (fail.IsNotNullOrWhiteSpace())
                {
                    Aver.Fail(fail);
                }
            }
        }
Esempio n. 3
0
        public void ReadIntoSame()
        {
            var v1r1 = new Ver1Row
            {
                A = "A string",
                B = 156,
                C = null,
                D = true,
                E = new byte[] { 1, 5, 98 },
                F = new DateTime(1980, 02, 12),
                G = new List <Ver1Row> {
                    new Ver1Row {
                        C = -998, D = null
                    }
                }
            };

            var writer = SlimFormat.Instance.GetWritingStreamer();
            var reader = SlimFormat.Instance.GetReadingStreamer();

            using (var ms = new MemoryStream())
            {
                writer.BindStream(ms);
                ArowSerializer.Serialize(v1r1, writer);
                writer.UnbindStream();

                ms.Position = 0;

                var v1r2 = new Ver1Row();
                reader.BindStream(ms);
                ArowSerializer.Deserialize(v1r2, reader);

                Aver.AreEqual("A string", v1r2.A);
                Aver.AreEqual(156, v1r2.B);
                Aver.IsNull(v1r2.C);
                Aver.IsTrue(v1r2.D.Value);
                Aver.AreEqual(3, v1r2.E.Length);
                Aver.AreEqual(98, v1r2.E[2]);
                Aver.AreEqual(new DateTime(1980, 02, 12), v1r2.F);
                Aver.IsNotNull(v1r2.G);
                Aver.AreEqual(1, v1r2.G.Count);
                Aver.AreEqual(-998, v1r2.G[0].C);
                Aver.IsNull(v1r2.G[0].D);
            }
        }
Esempio n. 4
0
        public void SerDeser_FamilyRow_2_OneFieldRef()
        {
            var row1 = new FamilyRow
            {
                ID = new GDID(1, 345), Name = "Lalala", RegisteredToVote = true,

                Father = new SimplePersonRow
                {
                    Age = 123, Bool1 = true, ID = new GDID(12, 234), Name = "Jacques Jabakz", Salary = 143098, Str1 = "Tryten", Date = new DateTime(1980, 08, 12, 13, 45, 11)
                }
            };

            var writer = SlimFormat.Instance.GetWritingStreamer();
            var reader = SlimFormat.Instance.GetReadingStreamer();

            using (var ms = new MemoryStream())
            {
                writer.BindStream(ms);
                ArowSerializer.Serialize(row1, writer);
                writer.UnbindStream();

                ms.Position = 0;

                var row2 = new FamilyRow();
                reader.BindStream(ms);
                ArowSerializer.Deserialize(row2, reader);
                reader.UnbindStream();

                Aver.AreNotSameRef(row1, row2);
                Aver.AreEqual(row1.ID, row2.ID);
                Aver.AreEqual(row1.Name, row2.Name);
                Aver.AreEqual(row1.RegisteredToVote, row2.RegisteredToVote);
                Aver.IsNotNull(row2.Father);
                Aver.AreEqual(row1.Father.ID, row2.Father.ID);
                Aver.AreEqual(row1.Father.Age, row2.Father.Age);
                Aver.AreEqual(row1.Father.Str1, row2.Father.Str1);

                Aver.AreEqual(row1.Father.Date, row2.Father.Date);
                Aver.IsNull(row2.Father.Str2);

                Aver.IsNull(row2.Mother);
            }
        }
Esempio n. 5
0
        public void OneAfterAnother()
        {
            var writer = SlimFormat.Instance.GetWritingStreamer();
            var reader = SlimFormat.Instance.GetReadingStreamer();
            var fail   = "";

            using (var ms = new MemoryStream())
            {
                writer.BindStream(ms);
                for (var i = 0; i < CASES.Length; i++)
                {
                    var row1 = CASES[i];
                    ArowSerializer.Serialize(row1, writer);
                }
                writer.UnbindStream();

                ms.Position = 0;
                reader.BindStream(ms);
                for (var i = 0; i < CASES.Length; i++)
                {
                    var row1 = CASES[i];
                    var row2 = new AllArowTypesRow();
                    ArowSerializer.Deserialize(row2, reader);

                    if (!row1.AllFieldsEqual(row2))
                    {
                        row2.ToJson().See();
                        "FAIL".See();
                        fail = "The test case #{0} has failed.\nJSON:\n{1}".Args(i, row1.ToJson());
                    }
                    else
                    {
                        "PASS".See();
                    }
                }
                reader.UnbindStream();
                if (fail.IsNotNullOrWhiteSpace())
                {
                    Aver.Fail(fail);
                }
            }
        }
Esempio n. 6
0
        public void Deserialize_SimplePerson_Arow(int CNT, int tcnt)
        {
            var row = getSimplePerson();


            var tasks = new List <Task>();
            var sw    = Stopwatch.StartNew();

            tasks.Add(Task.Factory.StartNew(() =>
            {
                var writer = SlimFormat.Instance.GetWritingStreamer();
                var reader = SlimFormat.Instance.GetReadingStreamer();

                using (var ms = new MemoryStream())
                {
                    writer.BindStream(ms);
                    ArowSerializer.Serialize(row, writer);
                    writer.UnbindStream();

                    reader.BindStream(ms);

                    for (var i = 0; i < CNT; i++)
                    {
                        ms.Position = 0;
                        var row2    = new SimplePersonRow();
                        ArowSerializer.Deserialize(row2, reader);
                        Aver.AreEqual(row.ID, row2.ID);
                    }
                }
            }));

            Task.WaitAll(tasks.ToArray());
            var el    = sw.ElapsedMilliseconds;
            var total = CNT * tcnt;

            Console.WriteLine("Arow did {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(total, el, total / (el / 1000d)));
        }
Esempio n. 7
0
        public void Test_Arow()
        {
            var msg    = withError();
            var writer = SlimFormat.Instance.MakeWritingStreamer();
            var reader = SlimFormat.Instance.MakeReadingStreamer();

            using (var ms = new MemoryStream())
            {
                writer.BindStream(ms);
                reader.BindStream(ms);

                ArowSerializer.Serialize(msg, writer);
                ms.Position = 0;

                var got = new Message();
                ArowSerializer.Deserialize(got, reader);

                got.ToJson(JsonWritingOptions.PrettyPrintRowsAsMap).See();

                Aver.AreEqual(msg.Gdid, got.Gdid);
                Aver.AreEqual(msg.Guid, got.Guid);
                Aver.AreEqual(msg.RelatedTo, got.RelatedTo);
                Aver.AreEqual(msg.Text, got.Text);
                Aver.AreEqual(msg.App, got.App);
                Aver.AreEqual(msg.Channel, got.Channel);
                Aver.AreEqual(msg.ArchiveDimensions, got.ArchiveDimensions);
                Aver.AreEqual(msg.Topic, got.Topic);
                Aver.AreEqual(msg.From, got.From);
                Aver.AreEqual(msg.Parameters, got.Parameters);

                Aver.IsNotNull(got.ExceptionData);
                Aver.AreSameRef(got.ExceptionData, ((WrappedException)got.Exception).Wrapped);

                Aver.AreEqual("Azos.AzosException", got.ExceptionData.TypeName);
                Aver.AreEqual("System.Exception", got.ExceptionData.InnerException.InnerException.InnerException.TypeName);
            }
        }
Esempio n. 8
0
        public void SerDeser_FamilyRow_7_ArraysAndList()
        {
            var row1 = new FamilyRow
            {
                ID = new GDID(1, 345), Name = "Lalala", RegisteredToVote = true,

                Father = new SimplePersonRow
                {
                    Age = 123, Bool1 = true, ID = new GDID(12, 234), Name = "Jacques Jabakz", Salary = 143098, Str1 = "Tryten", Date = new DateTime(1980, 08, 12, 13, 45, 11)
                },
                Mother = new SimplePersonRow
                {
                    Age = 245, Bool1 = false, ID = new GDID(2, 12), Name = "Katya Zhaba", Salary = 180000, Str1 = "Snake", Str2 = "Borra", Date = new DateTime(1911, 01, 01, 14, 11, 07)
                },
                Brothers = new [] { new SimplePersonRow {
                                        Age = 111
                                    }, new SimplePersonRow {
                                        Age = 222
                                    }, new SimplePersonRow {
                                        Age = 333
                                    } },
                Sisters = new [] { new SimplePersonRow {
                                       Age = 12
                                   }, new SimplePersonRow {
                                       Age = 13
                                   } },
                Advisers = new List <SimplePersonRow> {
                    new SimplePersonRow {
                        Age = 101, Name = "Kaznatchei"
                    }, new SimplePersonRow {
                        Age = 102
                    }
                }
            };

            var writer = SlimFormat.Instance.GetWritingStreamer();
            var reader = SlimFormat.Instance.GetReadingStreamer();

            using (var ms = new MemoryStream())
            {
                writer.BindStream(ms);
                ArowSerializer.Serialize(row1, writer);
                writer.UnbindStream();

                ms.Position = 0;

                var row2 = new FamilyRow();
                reader.BindStream(ms);
                ArowSerializer.Deserialize(row2, reader);
                reader.UnbindStream();

                Aver.AreNotSameRef(row1, row2);
                Aver.AreEqual(row1.ID, row2.ID);
                Aver.AreEqual(row1.Name, row2.Name);
                Aver.AreEqual(row1.RegisteredToVote, row2.RegisteredToVote);
                Aver.IsNotNull(row2.Father);
                Aver.AreEqual(row1.Father.ID, row2.Father.ID);
                Aver.AreEqual(row1.Father.Age, row2.Father.Age);
                Aver.AreEqual(row1.Father.Str1, row2.Father.Str1);

                Aver.AreEqual(row1.Father.Date, row2.Father.Date);
                Aver.IsNull(row2.Father.Str2);

                Aver.IsNotNull(row2.Mother);
                Aver.AreEqual(row1.Mother.ID, row2.Mother.ID);
                Aver.AreEqual(row1.Mother.Age, row2.Mother.Age);
                Aver.AreEqual(row1.Mother.Str1, row2.Mother.Str1);
                Aver.IsNotNull(row2.Mother.Str2);
                Aver.AreEqual(row1.Mother.Str2, row2.Mother.Str2);
                Aver.AreEqual(row1.Mother.Date, row2.Mother.Date);

                Aver.IsNotNull(row2.Brothers);
                Aver.AreEqual(3, row2.Brothers.Length);
                Aver.AreEqual(111, row2.Brothers[0].Age);
                Aver.AreEqual(222, row2.Brothers[1].Age);
                Aver.AreEqual(333, row2.Brothers[2].Age);
                Aver.IsNotNull(row2.Sisters);
                Aver.AreEqual(2, row2.Sisters.Length);
                Aver.AreEqual(12, row2.Sisters[0].Age);
                Aver.AreEqual(13, row2.Sisters[1].Age);
                Aver.IsNotNull(row2.Advisers);

                Aver.AreEqual(2, row2.Advisers.Count);
                Aver.AreEqual(101, row2.Advisers[0].Age);
                Aver.AreEqual("Kaznatchei", row2.Advisers[0].Name);
                Aver.AreEqual(102, row2.Advisers[1].Age);
            }
        }