Пример #1
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"]);
        }
Пример #2
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);
        }
Пример #3
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 );
        }
Пример #4
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 );
        }
Пример #5
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 );
        }
Пример #6
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 );
        }
Пример #7
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 );
        }
Пример #8
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 );
        }