Ejemplo n.º 1
0
        public void PopulateAndUpdateExisting()
        {
            var tbl = new Rowset(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           = "POP17",
                FirstName    = "Yaroslav",
                LastName     = "Suzkever",
                DOB          = new DateTime(1952, 12, 10),
                YearsInSpace = 14
            };

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

            Assert.IsTrue(idx >= 0);

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

            Assert.IsNotNull(match);
            Assert.AreEqual("Yaroslav", match.FirstName);
            Assert.AreEqual("Suzkever", match.LastName);
        }
Ejemplo n.º 2
0
        public void PopulateAndUpdateNonExisting()
        {
            var tbl = new Rowset(Schema.GetForTypedDoc(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 res = tbl.Update(update);//<-------------!!!!!!

            Aver.IsTrue(res.Index == -1);

            var match = tbl.FindByKey("NONE17") as Person;

            Aver.IsNull(match);
        }
Ejemplo n.º 3
0
        public void Save()
        {
            var rowset = new Rowset(Schema.GetForTypedDoc(typeof(MyPerzon)));

            rowset.LogChanges = true;

            for (var i = 0; i < 100; i++)
            {
                rowset.Insert(new MyPerzon
                {
                    GDID = new GDID(1, 1, (ulong)i),
                    Name = "Jeka Koshmar",
                    Age  = i
                });
            }

            var qryBetween5060 = new Query("CRUD.LoadPerzonsInAgeSpan", typeof(MyPerzon))
            {
                new Query.Param("fromAge", 50),
                new Query.Param("toAge", 60)
            };

            var rs = m_Store.LoadOneRowset(qryBetween5060);

            Aver.IsNotNull(rs);

            Aver.AreEqual(0, rs.Count);

            m_Store.Save(rowset);
            rowset.PurgeChanges();

            rs = m_Store.LoadOneRowset(qryBetween5060);
            Aver.IsNotNull(rs);

            Aver.AreEqual(9, rs.Count);

            rowset[55]["Age"] = 900;   //falls out of query
            rowset.Update(rowset[55]);
            rowset.Delete(rowset[59]); //physically deleted
            m_Store.Save(rowset);

            rs = m_Store.LoadOneRowset(qryBetween5060);
            Aver.IsNotNull(rs);

            Aver.AreEqual(7, rs.Count);
            Aver.AreObjectsEqual(58, rs.First()["Age"]);
            Aver.AreObjectsEqual(51, rs.Last()["Age"]);
        }
Ejemplo n.º 4
0
        public void LogChanges_Update()
        {
            var tbl = new Rowset(Schema.GetForTypedDoc(typeof(Person)));

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

            tbl.Update(tbl[0]);

            Aver.AreEqual(1, tbl.ChangeCount);

            Aver.IsTrue(DocChangeType.Update == tbl.GetChangeAt(0).Value.ChangeType);
        }