示例#1
0
        public void Slim_SerializeTable_TypedRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));
            
            for(var i=0; i<1000; i++)
             tbl.Insert( new Person{
                                    ID = "POP{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "Popov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12 
                                   });
            
            var ser = new SlimSerializer();
            using(var ms = new MemoryStream())
            {
                ser.Serialize(ms, tbl);
            Console.WriteLine("{0} rows took {1} bytes".Args(tbl.Count, ms.Position));
                ms.Position = 0;

                var tbl2 = ser.Deserialize(ms) as Table;

                Assert.IsNotNull( tbl2 );
                Assert.IsFalse( object.ReferenceEquals(tbl ,tbl2) );

                Assert.AreEqual( 1000, tbl2.Count);

                Assert.IsTrue( tbl.SequenceEqual( tbl2 ) );
            }
        }
示例#2
0
        public void Slim_SerializeTable_ComplexTypedRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(PersonWithNesting)));

            for(var i=0; i<1000; i++)
             tbl.Insert( new PersonWithNesting{
                                    ID = "POP{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "Popov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12,
                                    LatestHistory = new HistoryItem{ ID = "111", StartDate = DateTime.Now, Description="Chaplin" },
                                    History1  = new List<HistoryItem>
                                    {
                                      new HistoryItem{ ID = "789211", StartDate = DateTime.Now, Description="Chaplin with us" },
                                      new HistoryItem{ ID = "234234", StartDate = DateTime.Now, Description="Chaplin with you" }
                                    },
                                    History2  = new HistoryItem[2]
                                   });

            var ser = new SlimSerializer();
            using(var ms = new MemoryStream())
            {
                ser.Serialize(ms, tbl);

             Console.WriteLine("{0} rows took {1} bytes".Args(tbl.Count, ms.Position));

                ms.Position = 0;

                var tbl2 = ser.Deserialize(ms) as Table;

                Assert.IsNotNull( tbl2 );
                Assert.IsFalse( object.ReferenceEquals(tbl ,tbl2) );

                Assert.AreEqual( 1000, tbl2.Count);

                Assert.IsTrue( tbl.SequenceEqual( tbl2 ) );
            }
        }