Exemple #1
0
        public void Test1()
        {
            MockMiscProvider.MockNow = (new DateTime(2007, 11, 4, 15, 23, 43));
            var c = ClassHelper.CreateInstance <StaticHashCacheProvider>();

            var p = new SinglePerson {
                Id = 15, Name = "tom"
            };

            string key = KeyGenerator.Instance.GetKey(p.GetType(), p.Id);

            c[key] = ModelContext.CloneObject(p);

            var act = (SinglePerson)c[key];

            Assert.IsNotNull(act);
            Assert.AreEqual(15, act.Id);
            Assert.AreEqual("tom", act.Name);

            p.Name = "jerry";
            c[key] = ModelContext.CloneObject(p);

            act    = (SinglePerson)c[key];
            p.Name = "mike"; // By using ObjectInfo.CloneObject, it doesn't change cached object.

            Assert.IsNotNull(act);
            Assert.AreEqual(15, act.Id);
            Assert.AreEqual("jerry", act.Name);

            MockMiscProvider.MockNow = (new DateTime(2007, 11, 4, 15, 34, 43));

            act = (SinglePerson)c[key];

            Assert.IsNull(act);
        }
Exemple #2
0
        public void Test1()
        {
            var p = new SinglePerson {
                Name = "abc"
            };

            Assert.AreEqual(0, p.Id);

            DbEntry.Save(p);
            Assert.IsTrue(0 != p.Id);
            var p1 = DbEntry.GetObject <SinglePerson>(p.Id);

            Assert.AreEqual(p.Name, p1.Name);

            p.Name = "xyz";
            DbEntry.Save(p);
            Assert.AreEqual(p.Id, p1.Id);

            p1 = DbEntry.GetObject <SinglePerson>(p.Id);
            Assert.AreEqual("xyz", p1.Name);

            long id = p.Id;

            DbEntry.Delete(p);
            Assert.AreEqual(0, p.Id);
            p1 = DbEntry.GetObject <SinglePerson>(id);
            Assert.IsNull(p1);
        }