Exemplo n.º 1
0
        public void FindById_ContextCache()
        {
            ConsoleTitleUtil.ShowTestTitle("FindById_ContextCache");

            //复杂关联find
            TArticle art = TArticle.findById(1);

            Console.WriteLine("article 1 title is : " + art.Title);
            Assert.AreEqual("狂人日记", art.Title);

            //一级缓存
            TMember member = TMember.findById(13);

            Console.WriteLine("member 13 name is : " + member.Name);
            Assert.AreEqual("袁世凯", member.Name);

            TCat cat = TCat.findById(8);

            Console.WriteLine("cat 8 name is " + cat.Name);
            Assert.AreEqual("武侠小说", cat.Name);

            TBoard board = TBoard.findById(9);

            Console.WriteLine("board 9 name is : " + board.Name);
            Assert.AreEqual("board_互联网络", board.Name);
        }
Exemplo n.º 2
0
        public void UpdateCat()
        {
            ConsoleTitleUtil.ShowTestTitle("UpdateCat");

            TCat cat = TCat.findById(10);

            Console.WriteLine("\n读取 TCat{{Id:{0},Name:{1}}} code:{2} \n", cat.Id, cat.Name, cat.GetHashCode());
            Assert.AreEqual("国内新闻10", cat.Name);

            cat.Name = "糊播新闻10";
            db.update(cat);
            Console.WriteLine("\n更新 TCat{{Id:{0},Name:{1}}} code:{2} \n", cat.Id, cat.Name, cat.GetHashCode());

            cat = TCat.findById(10);
            Console.WriteLine("\n重新读取 TCat{{Id:{0},Name:{1}}} code:{2} \n", cat.Id, cat.Name, cat.GetHashCode());
            Assert.AreEqual("糊播新闻10", cat.Name);

            // Id 不可以修改
            //------------------------------------------------
            cat.Id = 101;
            cat.update();

            TCat newCat = TCat.findById(101);

            Assert.IsNull(newCat);
        }
Exemplo n.º 3
0
        public void FindCondition_WithEqual()
        {
            TArticle art = new TArticle();

            art.Member     = TMember.findById(8);
            art.Cat        = TCat.findById(7);
            art.Board      = TBoard.findById(3);
            art.Author     = "163羽化";
            art.Title      = "myurl=www.163.com";
            art.CreateTime = DateTime.Now;
            art.ChannelId  = 4;
            art.IsDelete   = 0;
            art.OrderId    = 15;

            art.insert();

            IList <TArticle> articles = TArticle.find("Title=:t").set("t", art.Title).list();

            Assert.AreEqual(1, articles.Count);

            logger.Info("===========================================================================");
            IList <TArticle> articles2 = TArticle.find("Title='" + art.Title + "'").list();

            Assert.AreEqual(1, articles2.Count);
        }
Exemplo n.º 4
0
        //------------------------- Insert -------------------------

        public void InsertArticle()
        {
            ConsoleTitleUtil.ShowTestTitle("InsertArticle");

            TArticle art = new TArticle();

            art.Member     = TMember.findById(13);
            art.Cat        = TCat.findById(8);
            art.Board      = TBoard.findById(9);
            art.Author     = "54鲁迅";
            art.Title      = "狂人日记";
            art.CreateTime = DateTime.Now;
            art.ChannelId  = 18;
            art.IsDelete   = 0;
            art.OrderId    = 5;
            art.insert();
            int id = art.Id;

            art.Member     = TMember.findById(2);
            art.Cat        = TCat.findById(10);
            art.Board      = TBoard.findById(11);
            art.Author     = "周做人";
            art.Title      = "论雷锋大的倒掉";
            art.CreateTime = DateTime.Now;
            art.ChannelId  = 12;
            art.IsDelete   = 0;
            art.OrderId    = 8;
            art.insert();
            id = id + 1;
            Assert.AreEqual(id, art.Id);

            art.Member     = TMember.findById(7);
            art.Cat        = TCat.findById(4);
            art.Board      = TBoard.findById(4);
            art.Author     = "嵇康";
            art.Title      = "与善举员绝交数";
            art.CreateTime = DateTime.Now;
            art.ChannelId  = 4;
            art.IsDelete   = 0;
            art.OrderId    = 9;
            art.insert();
            id = id + 1;
            Assert.AreEqual(id, art.Id);

            art.Member     = TMember.findById(8);
            art.Cat        = TCat.findById(7);
            art.Board      = TBoard.findById(3);
            art.Author     = "羽化";
            art.Title      = "许三管买血迹";
            art.CreateTime = DateTime.Now;
            art.ChannelId  = 4;
            art.IsDelete   = 0;
            art.OrderId    = 15;
            art.insert();
            id = id + 1;
            Assert.AreEqual(id, art.Id);

            Console.WriteLine("添加 article 成功!");
        }
Exemplo n.º 5
0
        public void GetCat()
        {
            ConsoleTitleUtil.ShowTestTitle("GetCat");

            TCat cat = TCat.findById(20);

            Assert.AreEqual("国际新闻20", cat.Name);

            Console.WriteLine("\n读取 TCat{{Id:{0},Name:{1}}} code:{2} \n", cat.Id, cat.Name, cat.GetHashCode());
        }
Exemplo n.º 6
0
        public void DeleteCat()
        {
            ConsoleTitleUtil.ShowTestTitle("DeleteCat");

            int retval = TCat.delete(30);

            Assert.AreEqual(1, retval);   // 删除了一条记录
            Console.WriteLine("\n删除 {0} 条记录 \n", retval);

            TCat mycat = TCat.findById(30);

            Assert.IsNull(mycat);
        }
Exemplo n.º 7
0
        public void UpdateACat()
        {
            ConsoleTitleUtil.ShowTestTitle("UpdateCat");

            TCat cat = TCat.findById(2);

            Assert.AreEqual("国际新闻", cat.Name);
            cat.Name = "这里不是新闻";
            cat.update();

            TCat newcat = TCat.findById(cat.Id);

            Assert.AreEqual("这里不是新闻", newcat.Name);
        }
Exemplo n.º 8
0
        public void FindById_Simply()
        {
            ConsoleTitleUtil.ShowTestTitle("FindById_Simply");

            //简易find
            TCat cat = TCat.findById(3);

            Console.WriteLine("cat name is : " + cat.Name);
            Assert.AreEqual("娱乐电影", cat.Name);

            TCat nullCat = TCat.findById(99999999);

            Assert.IsNull(nullCat);
        }