using System.Net.Http.Json; using System.Text.Json; using System.Text.Json.Serialization; namespace LudosData.Api.Tests; /// /// JSON helpers configured exactly like the API's own serializer. /// /// Without this the tests would speak a different dialect from the browser: /// System.Text.Json writes enums as ordinals by default, so a test could pass /// while the real client's "condition": "Cib" was rejected with a 400 — /// which is precisely what happened before the API adopted string enums. /// internal static class HttpJson { public static readonly JsonSerializerOptions Options = new(JsonSerializerDefaults.Web) { Converters = { new JsonStringEnumConverter() }, }; public static Task PostJsonAsync(this HttpClient client, string url, T value) => client.PostAsJsonAsync(url, value, Options); public static Task PutJsonAsync(this HttpClient client, string url, T value) => client.PutAsJsonAsync(url, value, Options); public static Task GetJsonAsync(this HttpClient client, string url) => client.GetFromJsonAsync(url, Options); public static Task ReadJsonAsync(this HttpContent content) => content.ReadFromJsonAsync(Options); }