Ejemplo n.º 1
0
        public void Slim_SerializeTable_DynamicRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));
            
            for(var i=0; i<1000; i++)
            {
                var row = new DynamicRow( tbl.Schema );

                row["ID"] = "POP{0}".Args(i);
                row["FirstName"] = "Oleg";
                row["LastName"] = "Popov-{0}".Args(i);
                row["DOB"] = new DateTime(1953, 12, 10);
                row["YearsInSpace"] = 12;
            
                tbl.Insert( row );
            }

            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 ) );
            }
        }
Ejemplo n.º 2
0
        public void BuildUsingAdHockSchema()
        {
            var schema = new Schema("TEZT",
                           new Schema.FieldDef("ID", typeof(int), new List<FieldAttribute>{ new FieldAttribute(required: true, key: true)}),
                           new Schema.FieldDef("Description", typeof(string), new List<FieldAttribute>{ new FieldAttribute(required: true)})
            );

            var tbl = new Table(schema);

            for(var i=0; i<1000; i++)
            {
                 var row =  new DynamicRow(tbl.Schema);

                 row["ID"] = i;
                 row["Description"] = "Item-{0}".Args(i);

                 tbl.Insert( row );
            }

            Assert.AreEqual(1000, tbl.Count);

            var match = tbl.FindByKey(178);
            Assert.IsNotNull( match );
            Assert.AreEqual("Item-178", match["Description"]);
        }
Ejemplo n.º 3
0
        public void TypedRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));

             tbl.Insert( new Person{
                                    ID = "POP1",
                                    FirstName = "Oleg",
                                    LastName = "Popov-1",
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });

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

                ms.Position = 0;

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

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

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

                Assert.IsTrue( tbl.Schema.IsEquivalentTo(tbl2.Schema));
            }
        }
Ejemplo n.º 4
0
        public void DynamicRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));

                var row = new DynamicRow( tbl.Schema );

                row["ID"] = "POP1";
                row["FirstName"] = "Oleg";
                row["LastName"] = "Popov-1";
                row["DOB"] = new DateTime(1953, 12, 10);
                row["YearsInSpace"] = 12;

                tbl.Insert( row );

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

                ms.Position = 0;

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

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

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

                Assert.IsTrue( tbl.Schema.IsEquivalentTo(tbl2.Schema));
            }
        }
Ejemplo n.º 5
0
        public void LogChanges_Delete()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));

            tbl.Insert( new Person{
                                    ID = "POP1",
                                    FirstName = "Oleg",
                                    LastName = "Popov",
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });
            tbl.LogChanges = true;

            tbl.Delete( tbl[0] );

            Assert.AreEqual(1, tbl.ChangeCount);
            Assert.AreEqual(0, tbl.Count);

            Assert.AreEqual(RowChangeType.Delete, tbl.GetChangeAt(0).Value.ChangeType);
        }
Ejemplo n.º 6
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 ) );
            }
        }
Ejemplo n.º 7
0
        public void PopulateAndUpsertNonExisting()
        {
            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 update =  new Person{
                                    ID = "GOODMAN17",
                                    FirstName = "John",
                                    LastName = "Jeffer",
                                    DOB = new DateTime(1952, 12, 10),
                                    YearsInSpace = 14
                                   };

            var existed = tbl.Upsert(update);//<-------------!!!!!!

            Assert.IsFalse( existed );

            Assert.AreEqual(1001, tbl.Count);

            var match = tbl.FindByKey("POP17") as Person;
            Assert.IsNotNull( match );
            Assert.AreEqual("Oleg", match.FirstName);
            Assert.AreEqual("Popov-17", match.LastName);

            match = tbl.FindByKey("GOODMAN17") as Person;
            Assert.IsNotNull( match );
            Assert.AreEqual("John", match.FirstName);
            Assert.AreEqual("Jeffer", match.LastName);
        }
Ejemplo n.º 8
0
        public void PopulateAndUpdateNonExisting()
        {
            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 update =  new Person{
                                    ID = "NONE17",
                                    FirstName = "Yaroslav",
                                    LastName = "Suzkever",
                                    DOB = new DateTime(1952, 12, 10),
                                    YearsInSpace = 14
                                   };

            var idx = tbl.Update(update);//<-------------!!!!!!

            Assert.IsTrue( idx==-1 );

            var match = tbl.FindByKey("NONE17") as Person;
            Assert.IsNull( match );
        }
Ejemplo n.º 9
0
        public void PopulateAndFindKey_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
                                   });

            Assert.AreEqual(1000, tbl.Count);

            var match1 = tbl.FindByKey("POP35");
            Assert.IsNotNull( match1 );
            Assert.AreEqual("Popov-35", match1["LastName"]); //example of dynamic row access

            var match2 = tbl.FindByKey("POP36") as Person;
            Assert.IsNotNull( match2 );
            Assert.AreEqual("Popov-36", match2.LastName);//example of typed row access

            var match3 = tbl.FindByKey("DoesNotExist");
            Assert.IsNull( match3 );
        }
Ejemplo n.º 10
0
        public void PopulateAndFindKey_MixedRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));

            for(var i=0; i<1000; i++)
            {
                 var row =  new DynamicRow(tbl.Schema);

                 row["ID"] = "DYN{0}".Args(i);
                 row["FirstName"] = "Oleg";
                 row["LastName"] = "DynamicPopov-{0}".Args(i);
                 row["DOB"] = new DateTime(1953, 12, 10);
                 row["YearsInSpace"] = 12;

                 tbl.Insert( row );

                 tbl.Insert( new Person{
                                    ID = "TYPED{0}".Args(i),
                                    FirstName = "Oleg",
                                    LastName = "TypedPopov-{0}".Args(i),
                                    DOB = new DateTime(1953, 12, 10),
                                    YearsInSpace = 12
                                   });
            }

            Assert.AreEqual(2000, tbl.Count);

            var match1 = tbl.FindByKey("DYN35");
            Assert.IsNotNull( match1 );
            Assert.IsTrue( match1 is DynamicRow );
            Assert.AreEqual("DynamicPopov-35", match1["LastName"]);

            var match2 = tbl.FindByKey("TYPED36") as Person;
            Assert.IsNotNull( match2 );
            Assert.AreEqual("TypedPopov-36", match2["LastName"]);

            var match3 = tbl.FindByKey("DoesNotExist");
            Assert.IsNull( match3 );
        }
Ejemplo n.º 11
0
        public void PopulateAndFindKey_DynamicRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));

            for(var i=0; i<1000; i++)
            {
                 var row =  new DynamicRow(tbl.Schema);

                 row["ID"] = "POP{0}".Args(i);
                 row["FirstName"] = "Oleg";
                 row["LastName"] = "Popov-{0}".Args(i);
                 row["DOB"] = new DateTime(1953, 12, 10);
                 row["YearsInSpace"] = 12;

                 tbl.Insert( row );
            }

            Assert.AreEqual(1000, tbl.Count);

            var match1 = tbl.FindByKey("POP35");
            Assert.IsNotNull( match1 );
            Assert.AreEqual("Popov-35", match1["LastName"]);

            var match2 = tbl.FindByKey("POP36") as DynamicRow;
            Assert.IsNotNull( match2 );
            Assert.AreEqual("Popov-36", match2["LastName"]);

            var match3 = tbl.FindByKey("DoesNotExist");
            Assert.IsNull( match3 );
        }
Ejemplo n.º 12
0
        public void PopulateAndFindCompositeKey_TypedRows()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(WithCompositeKey)));

            for(var i=0; i<1000; i++)
             tbl.Insert( new WithCompositeKey{
                                    ID = "ID{0}".Args(i),
                                    StartDate = new DateTime(1953, 12, 10),
                                    Description = "Descr{0}".Args(i)
                                   });

            Assert.AreEqual(1000, tbl.Count);

            var match1 = tbl.FindByKey("ID35", new DateTime(1953, 12, 10));
            Assert.IsNotNull( match1 );
            Assert.AreEqual("Descr35", match1["Description"]);

            var match2 = tbl.FindByKey("ID35", new DateTime(1953, 07, 10));
            Assert.IsNull( match2 );
        }
Ejemplo n.º 13
0
        public void PopulateAndDeleteNonExisting()
        {
            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 delete =  new Person{
                                    ID = "NONE17"
                                   };

            var idx = tbl.Delete( delete );//<-------------!!!!!!

            Assert.IsTrue( idx==-1 );
            Assert.AreEqual(1000, tbl.Count);

            var match = tbl.FindByKey("POP17") as Person;
            Assert.IsNotNull( match );
        }