From 1681703eea0c5a28e4f93e08f7acaaba7b2f3ea5 Mon Sep 17 00:00:00 2001 From: Patrick Pimentel Date: Mon, 24 Nov 2025 15:10:46 -0500 Subject: [PATCH] fix(auth-validator): [PM-22975] Client Version Validator - Trying to fix the error occuring in the build process. --- test/Common/Helpers/AssertHelper.cs | 32 ++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/Common/Helpers/AssertHelper.cs b/test/Common/Helpers/AssertHelper.cs index 5e9c3a5aba..1a9ad8ee16 100644 --- a/test/Common/Helpers/AssertHelper.cs +++ b/test/Common/Helpers/AssertHelper.cs @@ -225,7 +225,37 @@ public static class AssertHelper public async static Task AssertResponseTypeIs(HttpContext context) { - return await JsonSerializer.DeserializeAsync(context.Response.Body); + try + { + if (context.Response.Body.CanSeek) + { + context.Response.Body.Position = 0; + } + + return await JsonSerializer.DeserializeAsync(context.Response.Body); + } + catch (JsonException ex) + { + string bodyText = ""; + try + { + if (context.Response.Body.CanSeek) + { + context.Response.Body.Position = 0; + } + + using var sr = new StreamReader(context.Response.Body, leaveOpen: true); + bodyText = await sr.ReadToEndAsync(); + } + catch + { + // ignore read errors + } + + throw new Xunit.Sdk.XunitException( + $"Failed to deserialize response to {typeof(T).Name}. " + + $"StatusCode: {context.Response.StatusCode}. Body:\n{bodyText}\nException: {ex}"); + } } public static TimeSpan AssertRecent(DateTime dateTime, int skewSeconds = 2)