Exemplo n.º 1
0
        public void Refresh_Employee_From_Cache_Populated()
        {
            DB.Prepare();

            using (var repo = Repo.Create())
            {
                var id = DB.Employees[0].Id;

                ConsoleEx.WriteLine("\n\n- Populating cache...");
                var list = repo.Query <Employee>().ToList(); Assert.AreEqual(DB.Employees.Count, list.Count);
                var root = list.FirstOrDefault(x => x.Id == id); Assert.IsNotNull(root);

                ConsoleEx.WriteLine("\n\n- Refreshing a new instance...");
                var obj = new Employee()
                {
                    Id = id
                };
                var temp = repo.RefreshNow(obj);

                var metaObj  = MetaEntity.Locate(obj); ConsoleEx.WriteLine("\n> Implicit: {0}", metaObj);
                var metaTemp = MetaEntity.Locate(temp); ConsoleEx.WriteLine("\n> Returned: {0}", metaTemp);

                Assert.IsNotNull(temp);
                Assert.IsNotNull(metaTemp.Map);
                Assert.IsNotNull(metaObj.Map);

                // Validanting the new one is also refreshed...
                Assert.AreEqual(root.FirstName, obj.FirstName);
                Assert.AreEqual(root.LastName, obj.LastName);
            }
        }
Exemplo n.º 2
0
        public void Find_From_Cache_Clean()
        {
            DB.Prepare();

            using (var repo = Repo.Create())
            {
                var id  = DB.Employees[0].Id;
                var obj = repo.FindNow <Employee>(x => x.Id == id);

                ConsoleEx.WriteLine("\n> Source: {0}", obj);
                Assert.IsNotNull(obj);
                Assert.IsNotNull(MetaEntity.Locate(obj).Map);
            }
        }
Exemplo n.º 3
0
        public void Attach_New_And_Detach()
        {
            using (var repo = Repo.Create())
            {
                var reg = new Region()
                {
                    Id = "000"
                };
                repo.Attach(reg);

                var meta = MetaEntity.Locate(reg);
                Assert.IsNotNull(meta.Map);
                Assert.AreEqual(1, repo.Entities.Count());

                repo.Detach(reg);
                Assert.IsNull(meta.Map);
                Assert.AreEqual(0, repo.Entities.Count());
            }
        }
Exemplo n.º 4
0
        public void Refresh_Employee_From_Cache_Clean()
        {
            DB.Prepare();

            using (var repo = Repo.Create())
            {
                var id  = DB.Employees[0].Id;
                var obj = new Employee()
                {
                    Id = id
                };
                var temp = repo.RefreshNow(obj);

                var metaObj  = MetaEntity.Locate(obj); ConsoleEx.WriteLine("\n> Implicit: {0}", metaObj);
                var metaTemp = MetaEntity.Locate(temp); ConsoleEx.WriteLine("\n> Returned: {0}", metaTemp);

                Assert.IsNotNull(temp);
                Assert.IsNotNull(metaTemp.Map);
                Assert.IsNotNull(metaObj.Map);
            }
        }
Exemplo n.º 5
0
        public void Refresh_Employee_From_Cache_Clean()
        {
            DB.Prepare();

            using (var repo = Repo.Create())
            {
                var id  = DB.Employees[0].Id;
                var obj = new Employee()
                {
                    Id = id
                };
                var temp = repo.RefreshNow(obj);

                ConsoleEx.WriteLine("\n> Source: {0}", obj);
                ConsoleEx.WriteLine("\n> Refreshed: {0}", temp);
                ConsoleEx.WriteLine("\n> Are the same reference: {0}", object.ReferenceEquals(obj, temp));

                Assert.IsNotNull(temp);
                Assert.IsNotNull(MetaEntity.Locate(temp).Map);
                Assert.IsNotNull(MetaEntity.Locate(obj).Map);
            }
        }
Exemplo n.º 6
0
        public void Attach_Duplicate_And_Detach()
        {
            DB.Prepare(); using (var repo = Repo.Create())
            {
                var id  = DB.Regions[0].Id;
                var reg = repo.Where <Region>(x => x.Id == id).First(); Assert.IsNotNull(reg);

                var obj = new Region()
                {
                    Id = id
                };
                repo.Attach(obj);

                var list = repo.Entities.ToList();
                Assert.IsTrue(list.Contains(reg)); var metaReg = MetaEntity.Locate(reg); Assert.IsNotNull(metaReg.Map);
                Assert.IsTrue(list.Contains(obj)); var metaObj = MetaEntity.Locate(obj); Assert.IsNotNull(metaObj.Map);

                repo.Detach(obj);
                list = repo.Entities.ToList();
                Assert.IsFalse(list.Contains(metaObj));
                Assert.IsNull(metaObj.Map);
            }
        }