Ejemplo n.º 1
0
        public void GetEntityTest()
        {
            using (var db = new TestDataConnection())
                using (var map = new IdentityMap(db))
                {
                    var p1 = db.Person.First(p => p.ID == 1);
                    var p2 = map.GetEntity <Person>(1);
                    var p3 = map.GetEntity <Person>(new { ID = 1 });

                    Assert.AreSame(p1, p2);
                    Assert.AreSame(p1, p3);

                    var p4 = map.GetEntity <Person>(2) !;
                    var p5 = map.GetEntity <Person>(new { ID = 3L }) !;

                    Assert.That(
                        map.GetEntityEntries <Person>().Select(ee => new { ee.Entity, StoreCount = ee.DBCount, ee.CacheCount }),
                        Is.EquivalentTo(new[]
                    {
                        new { Entity = p1, StoreCount = 1, CacheCount = 2 },
                        new { Entity = p4, StoreCount = 1, CacheCount = 0 },
                        new { Entity = p5, StoreCount = 1, CacheCount = 0 },
                    }));

                    var c1 = map.GetEntity <Child>(new { ParentID = 1, ChildID = 11 });

                    Assert.That(
                        map.GetEntityMap <Child>().Entities?.Values.Select(ee => new { ee.Entity, StoreCount = ee.DBCount, ee.CacheCount }),
                        Is.EquivalentTo(new[]
                    {
                        new { Entity = c1, StoreCount = 1, CacheCount = 0 },
                    }));
                }
        }
Ejemplo n.º 2
0
 public void NegativeTest()
 {
     using (var db = new TestDataConnection())
         using (var map = new IdentityMap(db))
         {
             Assert.Throws <LinqToDBConvertException>(() => map.GetEntity <Person>(new { ID1 = 1 }));
         }
 }