Пример #1
0
        public void FindById_FromRoot()
        {
            // 1、分类的多态
            //---------------------------------------

            Console.WriteLine("---------- 分类多态 -----------");

            // 也可以直接创建父类
            TCategory category = new TCategory();

            category.Name = "父类的分类之FindById_FromRoot";
            db.insert(category);

            Assert.Greater(category.Id, 0);

            // 多态查询:正确判断具体的结果是父类
            TCategory cat = TCategory.findById(category.Id);

            Assert.AreEqual(category.Name, cat.Name);
            Assert.AreEqual(typeof(TCategory), cat.GetType());

            Console.WriteLine("---------- 多态关联 -----------");


            // 2、 数据上面 关联到 多态的分类
            //---------------------------------------
            TDataRoot root = new TDataRoot();

            root.Title    = "我是父类之一";
            root.Body     = "父类的内容之一";
            root.Category = category;
            db.insert(root);

            Assert.Greater(root.Id, 0);
            TDataRoot data = TDataRoot.findById(root.Id);

            Assert.IsNotNull(data);
            Assert.AreEqual(root.Title, data.Title);
            Assert.AreEqual(category.Id, data.Category.Id);
            Assert.AreEqual(category.Name, data.Category.Name);
        }