Exemplo n.º 1
0
        public void RootChildListUndoCancel()
        {
            EditableGetSet root = new EditableGetSet();

            Assert.AreEqual(0, root.EditLevel, "Root edit level before BeginEdit");
            root.BeginEdit();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after BeginEdit");

            ChildList list = root.ManagedChildList;

            Assert.AreEqual(1, list.EditLevel, "List edit level after being created");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty");
            Assert.IsFalse(list.IsDirty, "List should not be dirty");

            list.Add(new EditableGetSet(true));
            Assert.AreEqual(1, list.Count, "List count should be 1");

            root.CancelEdit();
            Assert.AreEqual(0, root.EditLevel, "Root edit level after CancelEdit");
            ChildList secondList = root.ManagedChildList;

            Assert.AreEqual(0, secondList.EditLevel, "Second list edit level after CancelEdit");
            Assert.IsFalse(ReferenceEquals(list, secondList), "List objects should not be the same");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after CancelEdit");
            Assert.IsFalse(secondList.IsDirty, "Second list should not be dirty");
        }
Exemplo n.º 2
0
        public void RootChildListUndoApply()
        {
            var root = new EditableGetSet();

            Assert.AreEqual(0, root.EditLevel, "Root edit level before BeginEdit");
            root.BeginEdit();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after BeginEdit");

            var childList = root.ManagedChildList;

            Assert.AreEqual(1, childList.EditLevel, "List edit level after being created");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty");
            Assert.IsFalse(childList.IsDirty, "List should not be dirty");

            childList.Add(new EditableGetSet(true));
            Assert.AreEqual(1, childList.Count, "List count should be 1");

            root.ApplyEdit();
            Assert.AreEqual(0, root.EditLevel, "Root edit level after ApplyEdit");
            var secondChildList = root.ManagedChildList;

            Assert.AreEqual(0, secondChildList.EditLevel, "Second list edit level after ApplyEdit");
            Assert.IsTrue(ReferenceEquals(childList, secondChildList), "List objects should be the same");

            Assert.IsTrue(root.IsDirty, "Root should be dirty after ApplyEdit");
            Assert.IsTrue(secondChildList.IsDirty, "Second list should be dirty");

            root = root.Save();

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after Save");
            Assert.IsFalse(root.ManagedChildList.IsDirty, "List should not be dirty after Save");
        }
Exemplo n.º 3
0
        public void RootUndoApply()
        {
            EditableGetSet root = new EditableGetSet();

            Assert.IsFalse(root.IsDirty, "Root should not start dirty");

            Assert.AreEqual("", root.FieldBackedString, "Explicit String should default to string.Empty");
            Assert.AreEqual("", root.ManagedStringField, "Managed String should default to string.Empty");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after defaults load");

            root.BeginEdit();
            root.FieldBackedString  = "fieldBackedString";
            root.ManagedStringField = "ManagedStringField";
            Assert.AreEqual("fieldBackedString", root.FieldBackedString, "String should be fieldBackedString");
            Assert.AreEqual("ManagedStringField", root.ManagedStringField, "String should be ManagedStringField");

            Assert.IsTrue(root.IsDirty, "Root should be dirty");

            root.ApplyEdit();
            Assert.AreEqual("fieldBackedString", root.FieldBackedString, "String should be fieldBackedString after apply");
            Assert.AreEqual("ManagedStringField", root.ManagedStringField, "String should be ManagedStringField after apply");

            Assert.IsTrue(root.IsDirty, "Root should be dirty after ApplyEdit");
            Assert.IsTrue(root.IsValid, "Root should be valid (no validation rules exist)");

            root = root.Save();

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after Save");
        }
Exemplo n.º 4
0
        public void RootChildUndoApply()
        {
            EditableGetSet root = new EditableGetSet();

            Assert.AreEqual(0, root.EditLevel, "Root edit level before BeginEdit");
            root.BeginEdit();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after BeginEdit");

            EditableGetSet initialChild = root.ManagedChild;

            Assert.AreEqual(1, initialChild.EditLevel, "Child edit level after being created");

            Assert.IsTrue(root.IsDirty, "Root should be dirty");

            root.ApplyEdit();
            Assert.AreEqual(0, root.EditLevel, "Root edit level after ApplyEdit");
            EditableGetSet secondChild = root.ManagedChild;

            Assert.AreEqual(0, secondChild.EditLevel, "Second child edit level after ApplyEdit");
            Assert.IsTrue(ReferenceEquals(initialChild, secondChild), "Child objects should be the same");

            Assert.IsTrue(root.IsDirty, "Root should be dirty after ApplyEdit");

            root = root.Save();

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after Save");
        }
Exemplo n.º 5
0
        public void RootChildListUndoCancel()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            Assert.AreEqual(0, root.EditLevel, "Root edit level before BeginEdit");
            root.BeginEdit();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after BeginEdit");

            ChildList list = root.ManagedChildList;

            Assert.AreEqual(1, list.EditLevel, "List edit level after being created");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty");
            Assert.IsFalse(list.IsDirty, "List should not be dirty");

            list.Add(EditableGetSet.NewChildObject(childDataPortal));
            Assert.AreEqual(1, list.Count, "List count should be 1");

            root.CancelEdit();
            Assert.AreEqual(0, root.EditLevel, "Root edit level after CancelEdit");
            ChildList secondList = root.ManagedChildList;

            Assert.AreEqual(0, secondList.EditLevel, "Second list edit level after CancelEdit");
            Assert.IsFalse(ReferenceEquals(list, secondList), "List objects should not be the same");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after CancelEdit");
            Assert.IsFalse(secondList.IsDirty, "Second list should not be dirty");
        }
Exemplo n.º 6
0
        public void RootUndoCancel()
        {
            EditableGetSet root = new EditableGetSet();

            Assert.IsFalse(root.IsDirty, "Root should not start dirty");

            Assert.AreEqual("", root.FieldBackedString, "Explicit String should default to string.Empty");
            Assert.AreEqual("", root.ManagedStringField, "Managed String should default to string.Empty");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after defaults load");

            root.BeginEdit();
            root.FieldBackedString  = "fieldBackedString";
            root.ManagedStringField = "ManagedStringField";
            Assert.AreEqual("fieldBackedString", root.FieldBackedString, "String should be fieldBackedString");
            Assert.AreEqual("ManagedStringField", root.ManagedStringField, "String should be ManagedStringField");

            Assert.IsTrue(root.IsDirty, "Root should be dirty");

            root.CancelEdit();
            Assert.AreEqual("", root.FieldBackedString, "Explicit String should revert to string.Empty");
            Assert.AreEqual("", root.ManagedStringField, "Managed String should revert to string.Empty");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty");
        }
Exemplo n.º 7
0
        public void RootChildUndoCancel()
        {
            IDataPortal <EditableGetSet> dataPortal = _testDIContext.CreateDataPortal <EditableGetSet>();

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            Assert.AreEqual(0, root.EditLevel, "Root edit level before BeginEdit");
            root.BeginEdit();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after BeginEdit");

            EditableGetSet initialChild = root.ManagedChild;

            Assert.AreEqual(1, initialChild.EditLevel, "Child edit level after being created");

            Assert.IsTrue(root.IsDirty, "Root should be dirty");

            root.CancelEdit();
            Assert.AreEqual(0, root.EditLevel, "Root edit level after CancelEdit");
            EditableGetSet secondChild = root.ManagedChild;

            Assert.AreEqual(0, secondChild.EditLevel, "Second child edit level after being created");
            Assert.IsFalse(ReferenceEquals(initialChild, secondChild), "Child objects should be different");

            Assert.IsTrue(root.IsDirty, "Root should be dirty after second child created");
        }
Exemplo n.º 8
0
        public void RootUndoCancel()
        {
            IDataPortal <EditableGetSet> dataPortal = _testDIContext.CreateDataPortal <EditableGetSet>();

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            Assert.IsFalse(root.IsDirty, "Root should not start dirty");

            Assert.AreEqual("", root.FieldBackedString, "Explicit String should default to string.Empty");
            Assert.AreEqual("", root.ManagedStringField, "Managed String should default to string.Empty");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty after defaults load");

            root.BeginEdit();
            root.FieldBackedString  = "fieldBackedString";
            root.ManagedStringField = "ManagedStringField";
            Assert.AreEqual("fieldBackedString", root.FieldBackedString, "String should be fieldBackedString");
            Assert.AreEqual("ManagedStringField", root.ManagedStringField, "String should be ManagedStringField");

            Assert.IsTrue(root.IsDirty, "Root should be dirty");

            root.CancelEdit();
            Assert.AreEqual("", root.FieldBackedString, "Explicit String should revert to string.Empty");
            Assert.AreEqual("", root.ManagedStringField, "Managed String should revert to string.Empty");

            Assert.IsFalse(root.IsDirty, "Root should not be dirty");
        }
Exemplo n.º 9
0
        public void RootChildUndoCancel()
        {
            EditableGetSet root = new EditableGetSet();

            Assert.AreEqual(0, root.EditLevel, "Root edit level before BeginEdit");
            root.BeginEdit();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after BeginEdit");

            EditableGetSet initialChild = root.ManagedChild;

            Assert.AreEqual(1, initialChild.EditLevel, "Child edit level after being created");

            Assert.IsTrue(root.IsDirty, "Root should be dirty");

            root.CancelEdit();
            Assert.AreEqual(0, root.EditLevel, "Root edit level after CancelEdit");
            EditableGetSet secondChild = root.ManagedChild;

            Assert.AreEqual(0, secondChild.EditLevel, "Second child edit level after being created");
#if !SILVERLIGHT
            Assert.IsFalse(ReferenceEquals(initialChild, secondChild), "Child objects should be different");
#endif

            Assert.IsTrue(root.IsDirty, "Root should be dirty after second child created");
        }
Exemplo n.º 10
0
        public void If_FieldBackedString_Property_Is_Changed_On_Child_After_CancelEdit_Then_ChildChanged_Fires_On_Root()
        {
            var root       = new EditableGetSet();
            var child      = new EditableGetSet(true);
            var grandChild = new EditableGetSet(true);

            root.ManagedChildList.Add(child);
            child.ManagedChildList.Add(grandChild);

            root.BeginEdit();
            root.CancelEdit();

            int changed = 0;

            root.ChildChanged      += (o, e) => { changed++; };
            child.FieldBackedString = "changed";

            Assert.AreEqual(1, changed);
        }
Exemplo n.º 11
0
        public void RootChildUndoCancelIsDirty()
        {
            EditableGetSet root = new EditableGetSet();

            root.BeginEdit();

            EditableGetSet initialChild = root.ManagedChild;

            Assert.IsTrue(root.IsDirty, "Root should be dirty");
            Assert.IsTrue(initialChild.IsDirty, "Child should be dirty");

            root.CancelEdit();

            // root.ManagedChild should be reset to null thus IsDirty should be false again.
            Assert.IsFalse(root.IsDirty, "Root should not be dirty");

            Assert.IsTrue(root.ManagedChild.IsDirty, "Child should be dirty after lazy loading");
            Assert.IsTrue(root.IsDirty, "Root should now be dirty since it lazy loaded ManagedChild");
        }
Exemplo n.º 12
0
        public void SerializedEditLevel()
        {
            EditableGetSet root = new EditableGetSet();

            Assert.AreEqual(0, root.EditLevel, "Root edit level before BeginEdit");
            root.BeginEdit();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after BeginEdit");
            Assert.AreEqual(1, root.ManagedChild.EditLevel, "Child edit level after BeginEdit");
            Assert.AreEqual(1, root.ManagedChildList.EditLevel, "List edit level after BeginEdit");
            root.ManagedChildList.Add(new EditableGetSet(true));
            Assert.AreEqual(1, root.ManagedChildList[0].EditLevel, "List child edit level after BeginEdit");

            root = root.Clone();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after Clone");
            Assert.AreEqual(1, root.ManagedChild.EditLevel, "Child edit level after Clone");
            Assert.AreEqual(1, root.ManagedChildList.EditLevel, "List edit level after Clone");
            Assert.AreEqual(1, root.ManagedChildList[0].EditLevel, "List child edit level after Clone");

            Assert.IsTrue(root.IsDirty, "Root should be dirty");
        }
Exemplo n.º 13
0
        public void RootChildUndoCancelIsDirty()
        {
            IDataPortal <EditableGetSet> dataPortal = _testDIContext.CreateDataPortal <EditableGetSet>();

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            root.BeginEdit();

            EditableGetSet initialChild = root.ManagedChild;

            Assert.IsTrue(root.IsDirty, "Root should be dirty");
            Assert.IsTrue(initialChild.IsDirty, "Child should be dirty");

            root.CancelEdit();

            // root.ManagedChild should be reset to null thus IsDirty should be false again.
            Assert.IsFalse(root.IsDirty, "Root should not be dirty");

            Assert.IsTrue(root.ManagedChild.IsDirty, "Child should be dirty after lazy loading");
            Assert.IsTrue(root.IsDirty, "Root should now be dirty since it lazy loaded ManagedChild");
        }
Exemplo n.º 14
0
        public void SerializedEditLevel()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            Assert.AreEqual(0, root.EditLevel, "Root edit level before BeginEdit");
            root.BeginEdit();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after BeginEdit");
            Assert.AreEqual(1, root.ManagedChild.EditLevel, "Child edit level after BeginEdit");
            Assert.AreEqual(1, root.ManagedChildList.EditLevel, "List edit level after BeginEdit");
            root.ManagedChildList.Add(EditableGetSet.NewChildObject(childDataPortal));
            Assert.AreEqual(1, root.ManagedChildList[0].EditLevel, "List child edit level after BeginEdit");

            root = root.Clone();
            Assert.AreEqual(1, root.EditLevel, "Root edit level after Clone");
            Assert.AreEqual(1, root.ManagedChild.EditLevel, "Child edit level after Clone");
            Assert.AreEqual(1, root.ManagedChildList.EditLevel, "List edit level after Clone");
            Assert.AreEqual(1, root.ManagedChildList[0].EditLevel, "List child edit level after Clone");

            Assert.IsTrue(root.IsDirty, "Root should be dirty");
        }