Пример #1
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);
        }
Пример #2
0
        public void LogChanges_Upsert()
        {
            var tbl = new Table(Schema.GetForTypedRow(typeof(Person)));

            tbl.LogChanges = true;

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

            Assert.AreEqual(1, tbl.ChangeCount);

            Assert.AreEqual(RowChangeType.Upsert, tbl.GetChangeAt(0).Value.ChangeType);
        }