コード例 #1
0
ファイル: CacheTest_Server.cs プロジェクト: yungtau/oea
        public void CTS_EntityContext()
        {
            var repo = RF.Concrete <PBSTypeRepository>();

            using (RF.TransactionScope(repo))
            {
                var pbsType = new PBSType
                {
                    Name    = "PBSType1",
                    PBSList =
                    {
                        new PBS {
                            Name = "PBS1"
                        },
                        new PBS {
                            Name = "PBS2"
                        },
                        new PBS {
                            Name = "PBS3"
                        },
                        new PBS {
                            Name = "PBS4"
                        },
                        new PBS {
                            Name = "PBS5"
                        },
                    }
                };
                repo.Save(pbsType);
                var id = pbsType.Id;

                using (RF.EnterEntityContext())
                {
                    var type1 = repo.CacheById(id) as PBSType;

                    var count = Logger.DbAccessedCount;
                    var type2 = repo.CacheById(id) as PBSType;
                    Assert.IsTrue(Logger.DbAccessedCount == count, "GetById 内存缓存应该命中,不会发生数据层访问。");

                    Assert.IsTrue(type1 == type2, "由于使用了 EntityContext,从缓存中读取的对象,也应该是同一个。");

                    var list1 = type1.PBSList;
                    Assert.IsTrue(list1.Count == 5);

                    count = Logger.DbAccessedCount;
                    var list2 = type2.PBSList;
                    Assert.IsTrue(Logger.DbAccessedCount == count, "GetByParentId 内存缓存应该命中,不会发生数据层访问。");

                    foreach (var pbs1 in list1)
                    {
                        var pbs2 = list2.Find(pbs1.Id);
                        Assert.IsTrue(pbs1 == pbs2, "由于使用了 EntityContext,从缓存中读取的对象,也应该是同一个。");
                    }
                }
            }
        }
コード例 #2
0
        public void CT_CTC_CacheByParentId()
        {
            var repo = RF.ResolveInstance <PBSTypeRepository>();

            using (RF.TransactionScope(repo))
            {
                var pbsType = new PBSType
                {
                    Name    = "PBSType1",
                    PBSList =
                    {
                        new PBS {
                            Name = "PBS1"
                        },
                        new PBS {
                            Name = "PBS2"
                        },
                        new PBS {
                            Name = "PBS3"
                        },
                        new PBS {
                            Name = "PBS4"
                        },
                        new PBS {
                            Name = "PBS5"
                        },
                    }
                };
                repo.Save(pbsType);
                var id = pbsType.Id;

                var type1 = repo.CacheById(id) as PBSType;
                var list1 = type1.PBSList;
                Assert.IsTrue(list1.Count == 5);

                DbAccessedCount = 0;
                var type2 = repo.CacheById(id) as PBSType;
                var list2 = type2.PBSList;
                Assert.IsTrue(DbAccessedCount == 0, "GetByParentId 内存缓存应该命中,不会发生数据层访问。");

                Assert.IsTrue(list2.Count == 5);
            }
        }
コード例 #3
0
ファイル: CacheTest_Server.cs プロジェクト: yungtau/oea
        public void CTS_CacheByParentId()
        {
            var repo = RF.Concrete <PBSTypeRepository>();

            using (RF.TransactionScope(repo))
            {
                var pbsType = new PBSType
                {
                    Name    = "PBSType1",
                    PBSList =
                    {
                        new PBS {
                            Name = "PBS1"
                        },
                        new PBS {
                            Name = "PBS2"
                        },
                        new PBS {
                            Name = "PBS3"
                        },
                        new PBS {
                            Name = "PBS4"
                        },
                        new PBS {
                            Name = "PBS5"
                        },
                    }
                };
                repo.Save(pbsType);
                var id = pbsType.Id;

                var type1 = repo.CacheById(id) as PBSType;
                var list1 = type1.PBSList;
                Assert.IsTrue(list1.Count == 5);

                var count = Logger.DbAccessedCount;
                var type2 = repo.CacheById(id) as PBSType;//Cache By Parent Id
                var list2 = type2.PBSList;
                Assert.IsTrue(Logger.DbAccessedCount == count, "CacheByParentId 内存缓存应该命中,不会发生数据层访问。");

                Assert.IsTrue(list2.Count == 5);
            }
        }
コード例 #4
0
        public void CT_CTC_CacheById()
        {
            var repo = RF.ResolveInstance <PBSTypeRepository>();

            using (RF.TransactionScope(repo))
            {
                var pbsType = new PBSType
                {
                    Name = "PBSType1"
                };
                repo.Save(pbsType);
                var id = pbsType.Id;

                var type1 = repo.CacheById(id) as PBSType;

                DbAccessedCount = 0;
                var type2 = repo.CacheById(id) as PBSType;
                Assert.IsTrue(DbAccessedCount == 0, "GetById 内存缓存应该命中,不会发生数据层访问。");

                Assert.IsTrue(type1 != type2, "虽然是从缓存中获取,但是只缓存数据,所以对象不应该是同一个。");
            }
        }
コード例 #5
0
ファイル: CacheTest_Server.cs プロジェクト: yungtau/oea
        public void CTS_CacheById()
        {
            var repo = RF.Concrete <PBSTypeRepository>();

            using (RF.TransactionScope(repo))
            {
                var pbsType = new PBSType
                {
                    Name = "PBSType1"
                };
                repo.Save(pbsType);
                var id = pbsType.Id;

                var type1 = repo.CacheById(id) as PBSType;

                var count = Logger.DbAccessedCount;
                var type2 = repo.CacheById(id) as PBSType;
                Assert.IsTrue(Logger.DbAccessedCount == count, "GetById 内存缓存应该命中,不会发生数据层访问。");

                Assert.IsTrue(type1 != type2, "虽然是从缓存中获取,但是只缓存数据,所以对象不应该是同一个。");
            }
        }
コード例 #6
0
ファイル: EntityTest.cs プロジェクト: yungtau/oea
        public void ET_Repository_Submit_ChildrenOnly()
        {
            var repo = RF.Concrete <PBSTypeRepository>();

            using (RF.TransactionScope(repo))
            {
                var root = new PBSType();
                var pbs  = new PBS();
                root.PBSList.Add(pbs);
                repo.Save(root);

                Assert.IsTrue(root.PersistenceStatus == PersistenceStatus.Unchanged);
                Assert.IsTrue(pbs.PersistenceStatus == PersistenceStatus.Unchanged);

                int count = 0;
                EventHandler <Rafy.Logger.DbAccessedEventArgs> handler = (o, e) =>
                {
                    if (e.ConnectionSchema == repo.RdbDataProvider.DbSetting)
                    {
                        count++;
                    }
                };
                Logger.DbAccessed += handler;

                pbs.Name = "DDDDDDDDDD";
                Assert.IsTrue(root.PersistenceStatus == PersistenceStatus.Unchanged);
                Assert.IsTrue(pbs.PersistenceStatus == PersistenceStatus.Modified);

                var c = count;
                repo.Save(root);
                Assert.IsTrue(root.PersistenceStatus == PersistenceStatus.Unchanged);
                Assert.IsTrue(pbs.PersistenceStatus == PersistenceStatus.Unchanged);
                Assert.IsTrue(count == c + 1, "只进行了一次数据访问,即子对象的保存。");

                Logger.DbAccessed -= handler;
            }
        }
コード例 #7
0
ファイル: PBSType.g.cs プロジェクト: 569550384/Rafy
 public int IndexOf(PBSType entity)
 {
     return base.IndexOf(entity);
 }
コード例 #8
0
ファイル: PBSType.g.cs プロジェクト: 569550384/Rafy
 public bool Contains(PBSType entity)
 {
     return base.Contains(entity);
 }
コード例 #9
0
ファイル: PBSType.g.cs プロジェクト: 569550384/Rafy
 public void Add(PBSType entity)
 {
     base.Add(entity);
 }
コード例 #10
0
ファイル: PBSType.g.cs プロジェクト: 569550384/Rafy
 public bool Remove(PBSType entity)
 {
     return base.Remove(entity);
 }
コード例 #11
0
ファイル: PBSType.g.cs プロジェクト: 569550384/Rafy
 public void Insert(int index, PBSType entity)
 {
     base.Insert(index, entity);
 }
コード例 #12
0
ファイル: EntityTest.cs プロジェクト: hardCTE/Rafy
        public void ET_Repository_Submit_ChildrenOnly()
        {
            var repo = RF.Concrete<PBSTypeRepository>();
            using (RF.TransactionScope(repo))
            {
                var root = new PBSType();
                var pbs = new PBS();
                root.PBSList.Add(pbs);
                repo.Save(root);

                Assert.IsTrue(root.PersistenceStatus == PersistenceStatus.Unchanged);
                Assert.IsTrue(pbs.PersistenceStatus == PersistenceStatus.Unchanged);

                int count = 0;
                EventHandler<Rafy.Logger.DbAccessedEventArgs> handler = (o, e) =>
                {
                    if (e.ConnectionSchema == RdbDataProvider.Get(repo).DbSetting) count++;
                };
                Logger.DbAccessed += handler;

                pbs.Name = "DDDDDDDDDD";
                Assert.IsTrue(root.PersistenceStatus == PersistenceStatus.Unchanged);
                Assert.IsTrue(pbs.PersistenceStatus == PersistenceStatus.Modified);

                var c = count;
                repo.Save(root);
                Assert.IsTrue(root.PersistenceStatus == PersistenceStatus.Unchanged);
                Assert.IsTrue(pbs.PersistenceStatus == PersistenceStatus.Unchanged);
                Assert.IsTrue(count == c + 1, "只进行了一次数据访问,即子对象的保存。");

                Logger.DbAccessed -= handler;
            }
        }
コード例 #13
0
ファイル: CacheTest_Server.cs プロジェクト: 569550384/Rafy
        public void CTS_CacheById()
        {
            var repo = RF.Concrete<PBSTypeRepository>();
            using (RF.TransactionScope(repo))
            {
                var pbsType = new PBSType
                {
                    Name = "PBSType1"
                };
                repo.Save(pbsType);
                var id = pbsType.Id;

                var type1 = repo.CacheById(id) as PBSType;

                var count = Logger.DbAccessedCount;
                var type2 = repo.CacheById(id) as PBSType;
                Assert.IsTrue(Logger.DbAccessedCount == count, "GetById 内存缓存应该命中,不会发生数据层访问。");

                Assert.IsTrue(type1 != type2, "虽然是从缓存中获取,但是只缓存数据,所以对象不应该是同一个。");
            }
        }
コード例 #14
0
ファイル: CacheTest_Server.cs プロジェクト: 569550384/Rafy
        public void CTS_EntityContext()
        {
            var repo = RF.Concrete<PBSTypeRepository>();
            using (RF.TransactionScope(repo))
            {
                var pbsType = new PBSType
                {
                    Name = "PBSType1",
                    PBSList =
                    {
                        new PBS { Name = "PBS1" },
                        new PBS { Name = "PBS2" },
                        new PBS { Name = "PBS3" },
                        new PBS { Name = "PBS4" },
                        new PBS { Name = "PBS5" },
                    }
                };
                repo.Save(pbsType);
                var id = pbsType.Id;

                using (RF.EnterEntityContext())
                {
                    var type1 = repo.CacheById(id) as PBSType;

                    var count = Logger.DbAccessedCount;
                    var type2 = repo.CacheById(id) as PBSType;
                    Assert.IsTrue(Logger.DbAccessedCount == count, "GetById 内存缓存应该命中,不会发生数据层访问。");

                    Assert.IsTrue(type1 == type2, "由于使用了 EntityContext,从缓存中读取的对象,也应该是同一个。");

                    var list1 = type1.PBSList;
                    Assert.IsTrue(list1.Count == 5);

                    count = Logger.DbAccessedCount;
                    var list2 = type2.PBSList;
                    Assert.IsTrue(Logger.DbAccessedCount == count, "GetByParentId 内存缓存应该命中,不会发生数据层访问。");

                    foreach (var pbs1 in list1)
                    {
                        var pbs2 = list2.Find(pbs1.Id);
                        Assert.IsTrue(pbs1 == pbs2, "由于使用了 EntityContext,从缓存中读取的对象,也应该是同一个。");
                    }
                }
            }
        }
コード例 #15
0
ファイル: CacheTest_Server.cs プロジェクト: 569550384/Rafy
        public void CTS_CacheByParentId()
        {
            var repo = RF.Concrete<PBSTypeRepository>();
            using (RF.TransactionScope(repo))
            {
                var pbsType = new PBSType
                {
                    Name = "PBSType1",
                    PBSList =
                    {
                        new PBS { Name = "PBS1" },
                        new PBS { Name = "PBS2" },
                        new PBS { Name = "PBS3" },
                        new PBS { Name = "PBS4" },
                        new PBS { Name = "PBS5" },
                    }
                };
                repo.Save(pbsType);
                var id = pbsType.Id;

                var type1 = repo.CacheById(id) as PBSType;
                var list1 = type1.PBSList;
                Assert.IsTrue(list1.Count == 5);

                var count = Logger.DbAccessedCount;
                var type2 = repo.CacheById(id) as PBSType;//Cache By Parent Id
                var list2 = type2.PBSList;
                Assert.IsTrue(Logger.DbAccessedCount == count, "CacheByParentId 内存缓存应该命中,不会发生数据层访问。");

                Assert.IsTrue(list2.Count == 5);
            }
        }