Ejemplo n.º 1
0
        public void CopyFrom_SubEntityCollClone()
        {
            var pf = new PersonDetail {
                History = new WorkHistoryCollection {
                    new WorkHistory {
                        Name = "Blah"
                    }
                }
            };
            var pt = new PersonDetail {
                History = new WorkHistoryCollection {
                    new WorkHistory {
                        Name = "Blah"
                    }
                }
            };

            pf.AcceptChanges();
            pt.AcceptChanges();
            pt.CopyFrom(pf);
            Assert.IsFalse(pt.IsChanged); // Although copied, data is the same - not changed.
            Assert.AreNotSame(pf.History, pt.History);

            pf.History[0].Name = "Blah, blah";
            pf.AcceptChanges();

            pt.CopyFrom(pf);
            Assert.IsTrue(pt.IsChanged); // Copied, and data was changed.
            Assert.AreNotSame(pf.History, pt.History);
            Assert.AreEqual(pf.History, pt.History);
        }
Ejemplo n.º 2
0
        public void ChangeTracking_EntitySubCollectionTracking()
        {
            var wh = new WorkHistory {
                Name = "Avanade"
            };
            var pd = new PersonDetail {
                History = new WorkHistoryCollection {
                    wh
                }
            };

            pd.AcceptChanges();
            Assert.IsFalse(pd.IsChanged);
            Assert.IsFalse(pd.History.IsChanged);
            Assert.IsFalse(wh.IsChanged);

            pd.TrackChanges();
            wh.Name = "Accenture";
            Assert.IsTrue(wh.IsChanged);
            Assert.AreEqual(new System.Collections.Specialized.StringCollection {
                "Name"
            }, wh.ChangeTracking);
            Assert.IsTrue(pd.History.IsChanged);
            Assert.IsNull(pd.History.ChangeTracking); // Collections always return null.
            Assert.IsTrue(pd.IsChanged);
            Assert.AreEqual(new System.Collections.Specialized.StringCollection {
                "History"
            }, pd.ChangeTracking);
        }
Ejemplo n.º 3
0
        public void CopyFrom_SubEntityCopy()
        {
            var pf = new PersonDetail {
                Address = new Address {
                    City = "Bardon"
                }
            };
            var pt = new PersonDetail {
                Address = new Address {
                    City = "Bardon"
                }
            };

            pf.AcceptChanges();
            pt.AcceptChanges();
            pt.CopyFrom(pf);
            Assert.IsFalse(pt.IsChanged);
            Assert.AreNotSame(pf.Address, pt.Address);

            // Should result in a copyfrom.
            pf.Address = new Address {
                City = "Ashgrove"
            };
            pt.CopyFrom(pf);
            Assert.IsTrue(pt.IsChanged);
            Assert.AreNotSame(pf.Address, pt.Address);
            Assert.AreEqual("Ashgrove", pt.Address.City);

            // Should result in a clone.
            pt.Address = null;
            pf.AcceptChanges();
            pt.AcceptChanges();
            pt.CopyFrom(pf);
            Assert.IsTrue(pt.IsChanged);
            Assert.AreNotSame(pf.Address, pt.Address);
            Assert.AreEqual("Ashgrove", pt.Address.City);
        }
Ejemplo n.º 4
0
        public void CopyFrom_SubEntityCollClone()
        {
            var pf = new PersonDetail {
                History = new WorkHistoryCollection {
                    new WorkHistory {
                        Name = "Blah"
                    }
                }
            };
            var pt = new PersonDetail {
                History = new WorkHistoryCollection {
                    new WorkHistory {
                        Name = "Blah"
                    }
                }
            };

            pf.AcceptChanges();
            pt.AcceptChanges();
            pt.CopyFrom(pf);
            Assert.IsTrue(pt.IsChanged); // Collections always cloned - therefore changed.
            Assert.AreNotSame(pf.History, pt.History);
        }