Beispiel #1
0
        public void Patch()
        {
            var po = ObjectDiff.ToJObject(new
            {
                a = 1,
                b = 2,
                c = new
                {
                    d = 3
                }
            });

            var co = ObjectDiff.ToJObject(new
            {
                a = 1,
                b = 2,
                c = new
                {
                    d = 3
                }
            });

            co["a"] = 2;
            (co["c"] as JObject).Add("e", 4);
            ((JObject)co).Remove("b");

            var diff = new ObjectDiff(po, co);

            var patch = diff.Patch(po) as JObject;

            Assert.AreEqual(((JValue)co["a"]).Value, ((JValue)patch["a"]).Value);
            Assert.IsNull(patch.Property("b"));
            Assert.AreEqual(4, ((JValue)((JObject)patch["c"])["e"]).Value);
        }
Beispiel #2
0
        public ObjectDiff ProcessChanges()
        {
            var diff = new ObjectDiff();

            if (diff.Diff(_prevObject, _object))
            {
                diff.Id = ++_prevId;
                // Store those changes(patch)
                _changes.Add(diff.Id, diff);

                // Update the _objectProps object with new object
                _prevObject = ObjectDiff.ToJObject(_object);
            }

            return(diff);
        }
Beispiel #3
0
        public void Diff()
        {
            GameThread.IgnoreThreadRestrictions = true;
            using (var ge = new GameEngine(null)) {
                ge.EngineInitialized.WaitOne();
                var diff = new ObjectDiff();

                dynamic sobj = new ExpandoObject();
                dynamic eobj = new ExpandoObject();

                eobj.Tim      = new ExpandoObject();
                eobj.Tim.bill = 12;

                diff.Diff(sobj, eobj);
                Assert.AreEqual(diff.Added["Tim"], ObjectDiff.ToJObject(eobj.Tim));
                Assert.IsEmpty(diff.Deleted);
                Assert.IsEmpty(diff.Modified);

                // Equal
                diff = new ObjectDiff();
                sobj = eobj;
                eobj = new ExpandoObject();

                eobj.Tim      = new ExpandoObject();
                eobj.Tim.bill = 12;

                diff.Diff(sobj, eobj);
                Assert.IsEmpty(diff.Added);
                Assert.IsEmpty(diff.Deleted);
                Assert.IsEmpty(diff.Modified);

                // Modify
                diff = new ObjectDiff();
                sobj = eobj;
                eobj = new ExpandoObject();

                eobj.Tim      = new ExpandoObject();
                eobj.Tim.bill = "chicken";

                diff.Diff(sobj, eobj);
                Assert.IsEmpty(diff.Added);
                Assert.IsEmpty(diff.Deleted);
                Assert.AreEqual(((JValue)diff.Modified["Tim.bill"]).Value, "chicken");

                // Delete
                diff = new ObjectDiff();
                sobj = eobj;
                eobj = new ExpandoObject();

                eobj.Tim = new ExpandoObject();

                diff.Diff(sobj, eobj);
                Assert.IsEmpty(diff.Added);
                Assert.IsEmpty(diff.Modified);
                Assert.Contains("Tim.bill", diff.Deleted);

                eobj = new ExpandoObject();

                diff.Diff(sobj, eobj);
                Assert.IsEmpty(diff.Added);
                Assert.IsEmpty(diff.Modified);
                Assert.Contains("Tim", diff.Deleted);
            }
        }