Exemple #1
0
        public void JSON_SerializeRowset_TypedRows()
        {
            var rowset = new Rowset(Schema.GetForTypedDoc(typeof(Person)));

            for (var i = 0; i < 10; i++)
            {
                rowset.Insert(new Person
                {
                    ID           = "POP{0}".Args(i),
                    FirstName    = "Oleg",
                    LastName     = "Popov-{0}".Args(i),
                    DOB          = new DateTime(1953, 12, 10),
                    YearsInSpace = 12
                });
            }

            // Serialization without schema
            var json = rowset.ToJson(Azos.Serialization.JSON.JsonWritingOptions.PrettyPrint);

            json.See();

            var rowset2 = json.JsonToDynamic();

            Aver.AreEqual("Popov-1", rowset2.Rows[1][2]);

            RowsetBase rowset3 = new Rowset(Schema.GetForTypedDoc(typeof(Person)));
            var        res     = Rowset.FromJSON <Person>(json, ref rowset3);

            Aver.AreEqual(10, res);
            Aver.AreEqual(10, rowset3.Count);
            Aver.AreObjectsEqual("Popov-1", rowset3[1][2]);

            var options = new Azos.Serialization.JSON.JsonWritingOptions
            {
                RowsetMetadata  = true,
                IndentWidth     = 2,
                ObjectLineBreak = true,
                MemberLineBreak = true,
                SpaceSymbols    = true,
                ASCIITarget     = false
            };

            rowset3.Clear();
            var json2 = rowset.ToJson(options);
            var res2  = Rowset.FromJSON <Person>(json2, ref rowset3);

            Aver.AreEqual(10, res);
            Aver.AreEqual(10, rowset3.Count);
            Aver.AreObjectsEqual("Popov-1", rowset3[1][2]);
        }