diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/RecordMatcher.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/RecordMatcher.cs index e9704e35f16..bec41ef8e63 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/RecordMatcher.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/RecordMatcher.cs @@ -157,46 +157,50 @@ public virtual int CompareBodies(byte[] requestBody, byte[] recordBody, string c return 1; } - if (!string.IsNullOrWhiteSpace(contentType) && contentType.Contains("json")) - { - var jsonDifferences = JsonComparer.CompareJson(requestBody, recordBody); - if (jsonDifferences.Count > 0) + if (!requestBody.SequenceEqual(recordBody)) + { + // we just failed sequence equality, before erroring, lets check if we're a json body and check for property equality + if (!string.IsNullOrWhiteSpace(contentType) && contentType.Contains("json")) { + var jsonDifferences = JsonComparer.CompareJson(requestBody, recordBody); - if (descriptionBuilder != null) + if (jsonDifferences.Count > 0) { - descriptionBuilder.AppendLine($"There are differences between request and recordentry bodies:"); - foreach (var jsonDifference in jsonDifferences) + + if (descriptionBuilder != null) { - descriptionBuilder.AppendLine(jsonDifference); + descriptionBuilder.AppendLine($"There are differences between request and recordentry bodies:"); + foreach (var jsonDifference in jsonDifferences) + { + descriptionBuilder.AppendLine(jsonDifference); + } } - } - return 1; - } - } - else if (!requestBody.SequenceEqual(recordBody)) - { - if (descriptionBuilder != null) - { - var minLength = Math.Min(requestBody.Length, recordBody.Length); - int i; - for (i = 0; i < minLength - 1; i++) + return 1; + } + } + else { + if (descriptionBuilder != null) { - if (requestBody[i] != recordBody[i]) + var minLength = Math.Min(requestBody.Length, recordBody.Length); + int i; + for (i = 0; i < minLength - 1; i++) { - break; + if (requestBody[i] != recordBody[i]) + { + break; + } } + descriptionBuilder.AppendLine($"Request and record bodies do not match at index {i}:"); + var before = Math.Max(0, i - 10); + var afterRequest = Math.Min(i + 20, requestBody.Length); + var afterResponse = Math.Min(i + 20, recordBody.Length); + descriptionBuilder.AppendLine($" request: \"{Encoding.UTF8.GetString(requestBody, before, afterRequest - before)}\""); + descriptionBuilder.AppendLine($" record: \"{Encoding.UTF8.GetString(recordBody, before, afterResponse - before)}\""); } - descriptionBuilder.AppendLine($"Request and record bodies do not match at index {i}:"); - var before = Math.Max(0, i - 10); - var afterRequest = Math.Min(i + 20, requestBody.Length); - var afterResponse = Math.Min(i + 20, recordBody.Length); - descriptionBuilder.AppendLine($" request: \"{Encoding.UTF8.GetString(requestBody, before, afterRequest - before)}\""); - descriptionBuilder.AppendLine($" record: \"{Encoding.UTF8.GetString(recordBody, before, afterResponse - before)}\""); + return 1; } - return 1; } return 0;