public void EditableObjectModelBase_EditableObjectTest()
        {
            var person = new EditablePerson();

            person.FirstName = "Albert";
            person.Age = 10;
            person.Boss.Age = 99;
            person.AcceptChanges();

            Assert.IsFalse(person.IsChangedLocal);

            person.BeginEdit();
            Assert.IsFalse(person.IsChangedLocal);
            person.FirstName = "Bob";
            Assert.IsTrue(person.IsChangedLocal);
            Assert.AreEqual("Bob", person.FirstName);
            person.CancelEdit();

            Assert.AreEqual("Albert", person.FirstName);
            Assert.AreEqual(10, person.Age);
            Assert.IsFalse(person.IsChangedLocal);

            person.BeginEdit();
            Assert.IsFalse(person.IsChangedLocal);
            person.FirstName = "Chris";
            Assert.IsTrue(person.IsChangedLocal);
            Assert.AreEqual("Chris", person.FirstName);

            person.EndEdit();
            Assert.IsTrue(person.IsChangedLocal);
            Assert.AreEqual("Chris", person.FirstName);

            person.BeginEdit();
            Assert.IsTrue(person.IsChangedLocal);
            person.FirstName = "David";
            Assert.IsTrue(person.IsChangedLocal);
            Assert.AreEqual("David", person.FirstName);

            person.EndEdit();
            Assert.IsTrue(person.IsChangedLocal);
            Assert.AreEqual("David", person.FirstName);

            person.BeginEdit();
            person.BeginEdit();

            person.EndEdit();
            person.EndEdit();

            person.BeginEdit();
            person.BeginEdit();

            person.CancelEdit();
            person.CancelEdit();
        }
        public void EditableObjectModelBase_SerializationTest1()
        {
            var person = new EditablePerson();
            person.FirstName = "Tom";
            person.LastName = "Jones";
            person.AcceptChanges();

            var stream = new MemoryStream();
            var serializer = new DataContractSerializer(typeof(EditablePerson));
            serializer.WriteObject(stream, person);
            stream.Position = 0;
            var newPerson = (EditablePerson)serializer.ReadObject(stream);

            Assert.AreEqual(person.FirstName, newPerson.FirstName);
            Assert.AreEqual(person.LastName, newPerson.LastName);
            Assert.AreEqual(person.FullName, newPerson.FullName);
            Assert.AreEqual(person.IsChangedLocal, newPerson.IsChangedLocal);
        }
        public void EditableObjectModelBase_ChangeTrackingTest()
        {
            var person = new EditablePerson();
            person.RejectChanges();

            Assert.IsNotNull(person.Boss);
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsFalse(person.IsChanged);

            person.Age = 100;
            Assert.IsTrue(person.IsChangedLocal);
            Assert.IsTrue(person.IsChanged);
            person.RejectChanges();

            Assert.AreEqual(0, person.Age);
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsFalse(person.IsChanged);

            person.FirstName = "Tom";
            Assert.IsTrue(person.IsChangedLocal);
            Assert.IsTrue(person.IsChanged);

            person.AcceptChanges();
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsFalse(person.IsChanged);
            Assert.IsFalse(person.Boss.IsChangedLocal);
            Assert.IsFalse(person.Boss.IsChanged);

            person.Boss.FirstName = "Frank";
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsTrue(person.IsChanged);
            Assert.IsTrue(person.Boss.IsChangedLocal);
            Assert.IsTrue(person.Boss.IsChanged);
            Assert.AreEqual("Tom", person.FirstName);
            Assert.AreEqual("Frank", person.Boss.FirstName);

            person.AcceptChanges();
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsFalse(person.IsChanged);
            Assert.IsFalse(person.Boss.IsChangedLocal);
            Assert.IsFalse(person.Boss.IsChanged);
            Assert.AreEqual("Tom", person.FirstName);
            Assert.AreEqual("Frank", person.Boss.FirstName);

            person.FirstName = "Harry";
            person.Boss.FirstName = "Sam";
            Assert.IsTrue(person.IsChangedLocal);
            Assert.IsTrue(person.IsChanged);
            Assert.IsTrue(person.Boss.IsChangedLocal);
            Assert.IsTrue(person.Boss.IsChanged);
            Assert.AreEqual("Harry", person.FirstName);
            Assert.AreEqual("Sam", person.Boss.FirstName);

            person.RejectChanges();
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsFalse(person.IsChanged);
            Assert.IsFalse(person.Boss.IsChangedLocal);
            Assert.IsFalse(person.Boss.IsChanged);
            Assert.AreEqual("Tom", person.FirstName);
            Assert.AreEqual("Frank", person.Boss.FirstName);

            person.DummyObject.IsChanged = true;
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsTrue(person.IsChanged);

            person.AcceptChanges();
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsFalse(person.IsChanged);

            person.DummyObject.IsChanged = true;
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsTrue(person.IsChanged);

            person.RejectChanges();
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsFalse(person.IsChanged);

            person.DummyObject.IsChanged = true;
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsTrue(person.IsChanged);

            person.AcceptChangesLocal();
            Assert.IsFalse(person.IsChangedLocal);
            Assert.IsTrue(person.IsChanged);
        }