AddChild() public method

public AddChild ( ) : CircularObject
return CircularObject
Esempio n. 1
0
        public void AbleToHandleCircularReferences_All()
        {
            CircularObject original = new CircularObject();

            original.AddChild();
            original.AddChild();
            original.FirstChild.AddChild();

            var snapshot = ObjectDiffPatch.Snapshot(original).ToString();

            ObjectDiffPatch.DefaultSerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All;
            // see http://www.newtonsoft.com/json/help/html/PreserveReferencesHandlingObject.htm

            var snapshotWithRefs = ObjectDiffPatch.Snapshot(original).ToString();

            Assert.NotEqual(snapshot, snapshotWithRefs);

            var updated = ObjectDiffPatch.PatchObject(new CircularObject(), snapshotWithRefs);

            // they should be equal
            Assert.Equal(Newtonsoft.Json.JsonConvert.SerializeObject(updated, ObjectDiffPatch.DefaultSerializerSettings),
                         Newtonsoft.Json.JsonConvert.SerializeObject(original, ObjectDiffPatch.DefaultSerializerSettings));
            Assert.NotNull(updated.FirstChild);
            Assert.NotNull(updated.FirstChild.Parent);
            Assert.NotNull(updated.FirstChild.FirstChild);

            // revertBack
            var diff = ObjectDiffPatch.GenerateDiff(original, new CircularObject());

            updated = ObjectDiffPatch.PatchObject(original, diff.NewValues);
            //ensure everything is alright
            Assert.Null(updated.FirstChild);
            Assert.Null(updated.Parent);
            Assert.Null(updated.Children);
        }
Esempio n. 2
0
        public void AbleToHandleCircularReferences_Ignore()
        {
            CircularObject original = new CircularObject();

            original.AddChild();
            original.AddChild();
            original.FirstChild.AddChild();

            var snapshot = ObjectDiffPatch.Snapshot(original).ToString();

            ObjectDiffPatch.DefaultSerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All;

            var snapshotWithRefs = ObjectDiffPatch.Snapshot(original).ToString();

            Assert.NotEqual(snapshot, snapshotWithRefs);

            var updated = ObjectDiffPatch.PatchObject(new CircularObject(), snapshotWithRefs);

            // they should be different, since all circular references are ignored!
            Assert.NotEqual(updated, original);
        }
        public void AbleToHandleCircularReferences_All ()
        {
            CircularObject original = new CircularObject ();
            original.AddChild ();
            original.AddChild ();
            original.FirstChild.AddChild ();

            var snapshot = ObjectDiffPatch.Snapshot (original).ToString ();

            ObjectDiffPatch.DefaultSerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All;
            // see http://www.newtonsoft.com/json/help/html/PreserveReferencesHandlingObject.htm

            var snapshotWithRefs = ObjectDiffPatch.Snapshot (original).ToString ();

            Assert.NotEqual (snapshot, snapshotWithRefs);

            var updated = ObjectDiffPatch.PatchObject (new CircularObject (), snapshotWithRefs);
           // they should be equal
            Assert.Equal (Newtonsoft.Json.JsonConvert.SerializeObject (updated, ObjectDiffPatch.DefaultSerializerSettings),
                Newtonsoft.Json.JsonConvert.SerializeObject (original, ObjectDiffPatch.DefaultSerializerSettings));
            Assert.NotNull (updated.FirstChild);
            Assert.NotNull (updated.FirstChild.Parent);
            Assert.NotNull (updated.FirstChild.FirstChild);

            // revertBack
            var diff = ObjectDiffPatch.GenerateDiff (original, new CircularObject ());

            updated = ObjectDiffPatch.PatchObject (original, diff.NewValues);
            //ensure everything is alright
            Assert.Null (updated.FirstChild);
            Assert.Null (updated.Parent);
            Assert.Null (updated.Children);
        }
        public void AbleToHandleCircularReferences_Ignore ()
        {
            CircularObject original = new CircularObject ();
            original.AddChild ();
            original.AddChild ();
            original.FirstChild.AddChild ();

            var snapshot = ObjectDiffPatch.Snapshot (original).ToString ();

            ObjectDiffPatch.DefaultSerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All;

            var snapshotWithRefs = ObjectDiffPatch.Snapshot (original).ToString ();

            Assert.NotEqual (snapshot, snapshotWithRefs);

            var updated = ObjectDiffPatch.PatchObject (new CircularObject (), snapshotWithRefs);
            // they should be different, since all circular references are ignored!
            Assert.NotEqual (updated, original);
        }