Beispiel #1
0
        public void If_FieldBackedString_Is_Changed_On_GrandChild_List_Item_After_Root_Is_Deserialized_Then_Root_ChildChanged_Event_Fires()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            var root       = EditableGetSet.GetObject(dataPortal);
            var child      = EditableGetSet.NewChildObject(childDataPortal);
            var grandChild = EditableGetSet.NewChildObject(childDataPortal);

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

            var             applicationContext = _testDIContext.CreateTestApplicationContext();
            MemoryStream    stream             = new MemoryStream();
            MobileFormatter formatter          = new MobileFormatter(applicationContext);

            formatter.Serialize(stream, root);
            stream.Seek(0, SeekOrigin.Begin);
            root = (EditableGetSet)formatter.Deserialize(stream);

            int changed = 0;

            root.ChildChanged += (o, e) => { changed++; };
            root.ManagedChildList[0].ManagedChildList[0].FieldBackedString = "changed";
            Assert.AreEqual(1, changed, "after MobileFormatter");

            changed            = 0;
            root               = root.Clone();
            root.ChildChanged += (o, e) => { changed++; };
            root.ManagedChildList[0].ManagedChildList[0].FieldBackedString = "changed again";
            Assert.AreEqual(1, changed, "after clone");
        }
Beispiel #2
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");
        }
Beispiel #3
0
        public void If_FieldBackedString_Property_Is_Changed_On_Child_After_CancelEdit_Then_ChildChanged_Fires_On_Root()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            var root       = EditableGetSet.GetObject(dataPortal);
            var child      = EditableGetSet.NewChildObject(childDataPortal);
            var grandChild = EditableGetSet.NewChildObject(childDataPortal);

            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);
        }
Beispiel #4
0
        public void If_FieldBackedString_Property_Changes_On_Item_In_ManagedChildList_Then_ChildChanged_Fires_On_Root_And_On_ManagedChildList()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            int rootChanged = 0;
            int listChanged = 0;

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            root.ChildChanged += (o, e) => { rootChanged++; };

            var list = root.ManagedChildList;

            list.ChildChanged += (o, e) => { listChanged++; };

            list.Add(EditableGetSet.NewChildObject(childDataPortal));
            list[0].FieldBackedString = "child change";

            Assert.AreEqual(4, rootChanged);//this event fires 4 times: lazy load of the child list, Item[], Count and property change on item in the list
            Assert.AreEqual(1, listChanged);
        }
Beispiel #5
0
        public void If_FieldBackedString_Changes_On_GrandChild_Then_ChildChanged_Fires_On_GrandChild_Child_and_Root()
        {
            IDataPortal <EditableGetSet>      dataPortal      = _testDIContext.CreateDataPortal <EditableGetSet>();
            IChildDataPortal <EditableGetSet> childDataPortal = _testDIContext.CreateChildDataPortal <EditableGetSet>();

            int rootChanged               = 0;
            int childListChanged          = 0;
            int grandChildListChanged     = 0;
            int childChanged              = 0;
            int grandChildPropertyChanged = 0;

            EditableGetSet root = EditableGetSet.GetObject(dataPortal);

            root.PropertyChanged += (o, e) => { throw new InvalidOperationException(); };
            root.ChildChanged    += (o, e) => { rootChanged++; };
            root.ManagedChildList.ChildChanged += (o, e) => { childListChanged++; };

            var child = EditableGetSet.NewChildObject(childDataPortal);

            child.PropertyChanged += (o, e) => { throw new InvalidOperationException(); };
            child.ChildChanged    += (o, e) => { childChanged++; };
            child.ManagedChildList.ChildChanged += (o, e) => { grandChildListChanged++; };

            var grandChild = EditableGetSet.NewChildObject(childDataPortal);

            grandChild.ChildChanged    += (o, e) => { throw new InvalidOperationException(); }; // ChildChange only fires when child of self changes
            grandChild.PropertyChanged += (o, e) => { grandChildPropertyChanged++; };

            root.ManagedChildList.Add(child);
            child.ManagedChildList.Add(grandChild);
            root.ManagedChildList[0].ManagedChildList[0].FieldBackedString = "child change"; // or c2.FieldBackedString = "child change";

            Assert.AreEqual(7, rootChanged);                                                 //Child, and GrandChild lists lazy loaded + Property changed on GrandChildList Item
            Assert.AreEqual(4, childChanged);                                                //GrandChild lists lazy loaded + Property changed on GrandChildList Item
            Assert.AreEqual(4, childListChanged);                                            //GrandChild lists lazy loaded + Property changed on GrandChildList Item
            Assert.AreEqual(1, grandChildListChanged);                                       //Property changed on GrandChildList Item
            Assert.AreEqual(1, grandChildPropertyChanged);                                   //Property changed on GrandChildList Item
        }
Beispiel #6
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");
        }