public IEnumerable <IJsonCompareError <JToken> > Compare(JObject expected, JObject actual, IJsonComparer jsonComparer, string path = "") { foreach (var actualProperty in actual.Properties()) { var expectedProperty = expected.Property(actualProperty.Name); if (expectedProperty == null) { yield return(new UnexpectedPropertyJsonComparerError(path, expected, actual, actualProperty)); } } foreach (var expectedProperty in expected.Properties()) { var actualProperty = actual.Property(expectedProperty.Name); var expectedJToken = expectedProperty.Value; if (actualProperty == null) { yield return(new MissingPropertyJsonComparerError(path, expected, actual, expectedProperty)); continue; } var elementPath = JsonPathUtils.Combine(path, actualProperty.Name); var errors = jsonComparer.Compare(expectedJToken, actualProperty.Value, elementPath); foreach (var jsonCompareError in errors) { yield return(jsonCompareError); } } }
public IEnumerable <IJsonCompareError <JToken> > Compare(JArray expected, JArray actual, IJsonComparer jsonComparer, string path = "") { if (expected.Count != actual.Count) { yield return(new InvalidSizeJsonCompareError(path, expected, actual)); yield break; } for (var i = 0; i < expected.Count; i++) { var expectedElement = expected[i]; var actualElement = actual[i]; var errors = jsonComparer.Compare(expectedElement, actualElement, JsonPathUtils.Combine(path, $"[{i}]")); foreach (var error in errors) { yield return(error); } } }