コード例 #1
0
ファイル: JsonEqualsConstraint.cs プロジェクト: dotJEM/nunit3
 private IJsonSimpleDiff Diff(IJsonSimpleDiff result, JObject actual, JObject expected, string path = "")
 {
     foreach (string key in UnionKeys(actual, expected))
     {
         string propertyPath = string.IsNullOrEmpty(path) ? key : path + "." + key;
         Diff(result, actual[key], expected[key], propertyPath);
     }
     return(result);
 }
コード例 #2
0
ファイル: JsonEqualsConstraint.cs プロジェクト: dotJEM/nunit3
        public override IJsonSimpleDiff Diff(IJsonSimpleDiff result, JArray actual, JArray expected, string path)
        {
            if (actual.Count != expected.Count)
            {
                result.Push(path, $"JArray with {expected.Count} items", $"JArray with {actual.Count} items");
                return(result);
            }

            for (int i = 0; i < expected.Count; i++)
            {
                result = DiffToken(result, actual[i], expected[i], $"{path}[{i}]");
            }
            return(result);
        }
コード例 #3
0
ファイル: JsonEqualsConstraint.cs プロジェクト: dotJEM/nunit3
        public override IJsonSimpleDiff Diff(IJsonSimpleDiff result, JArray actual, JArray expected, string path)
        {
            if (actual.Count != expected.Count)
            {
                result.Push(path, $"JArray with {expected.Count} items", $"JArray with {actual.Count} items");
                return(result);
            }

            int count = expected.Count;

            Table <IJsonSimpleDiff> table = new Table <IJsonSimpleDiff>(count, count);

            for (int x = 0; x < count; x++)
            {
                for (int y = 0; y < count; y++)
                {
                    IJsonSimpleDiff diff = DiffToken(new JsonSimpleDiff(), actual[y], expected[x], $"{path}[{x}]");
                    table[x, y] = diff;
                }
            }

            if (table.Columns.All(col => col.Any(diff => diff.Empty)) && table.Rows.All(col => col.Any(diff => diff.Empty)))
            {
                return(result);
            }

            IEnumerable <int> missing = table.Columns
                                        .Select((col, i) => col.All(diff => !diff.Empty) ? i : -1)
                                        .Where(index => index >= 0);

            IEnumerable <int> extra = table.Rows
                                      .Select((row, i) => row.All(diff => !diff.Empty) ? i : -1)
                                      .Where(index => index >= 0);

            foreach (int i in missing)
            {
                result.Push(path, expected[i], "<missing>");
            }

            foreach (int i in extra)
            {
                result.Push(path, "<extra>", actual[i]);
            }

            return(result);
        }
コード例 #4
0
ファイル: JsonEqualsConstraint.cs プロジェクト: dotJEM/nunit3
        private IJsonSimpleDiff Diff(IJsonSimpleDiff result, JToken actual, JToken expected, string path = "")
        {
            if (actual == null && expected == null)
            {
                return(result);
            }

            if (actual == null)
            {
                return(result.Push(path, "<null>", expected.ToString()));
            }

            if (expected == null)
            {
                return(result.Push(path, actual.ToString(), "<null>"));
            }

            if (actual.Type != expected.Type)
            {
                return(result.Push(path, $"JToken of type '{actual.Type}'", $"JToken of type '{expected.Type}'"));
            }

            if (expected is JObject obj)
            {
                return(Diff(result, obj, (JObject)actual, path));
            }

            if (expected is JArray array)
            {
                return(arrayStrategy.Diff(result, (JArray)actual, array, path));
            }

            if (expected is JValue value && !value.Equals((JValue)actual))
            {
                return(result.Push(path, actual.ToString(), expected.ToString()));
            }

            return(result);
        }
コード例 #5
0
ファイル: JsonEqualsConstraint.cs プロジェクト: dotJEM/nunit3
 protected IJsonSimpleDiff DiffToken(IJsonSimpleDiff result, JToken actual, JToken expected, string path) => tokenDiffer(result, actual, expected, path);
コード例 #6
0
ファイル: JsonEqualsConstraint.cs プロジェクト: dotJEM/nunit3
 public abstract IJsonSimpleDiff Diff(IJsonSimpleDiff result, JArray actual, JArray expected, string path);
コード例 #7
0
ファイル: JsonEqualsConstraint.cs プロジェクト: dotJEM/nunit3
 public JsonEqualsConstraintMatchResult(IJsonSimpleDiff diff)
 {
     this.diff = diff;
 }