コード例 #1
0
        public void MoveObjectsInList()
        {
            string jsonA = "{\"Dependencies\":[{\"a\":\"valueA\"},{\"b\":\"valueB\"}]}";
            string jsonB = "{\"Dependencies\":[{\"b\":\"valueB\"},{\"a\":\"valueA\"}]}";

            var treeA = JsonTree.BuildTree(jsonA);
            var treeB = JsonTree.BuildTree(jsonB);

            var changeList = JsonTree.DiffTrees(treeA, treeB);

            // The change list must detect either "a" or "b" as having moved positions
            // the current algorithm detects happens to detect "a"
            AssertRemoved("a", changeList);
            AssertAdded("a", changeList);
            var printDiff = JsonTree.PrintTreeChangeList(changeList);

            XAssert.IsTrue(printDiff.Contains("a") && printDiff.Contains("valueA"));
            XAssert.IsFalse(printDiff.Contains("b") || printDiff.Contains("valueB"));
        }