Пример #1
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");
        }
Пример #2
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");
        }
Пример #3
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");
        }
Пример #4
0
        public void RootChildListUndoApply()
        {
            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");

            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(EditableGetSet.NewChildObject(childDataPortal));
            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");
        }