using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; namespace PnvPanel.IntegrationTests.TestSupport; public static class HttpClientJsonExtensions { public static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web); public static void UseBearerToken(this HttpClient client, string accessToken) => client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Bearer", accessToken ); public static async Task ReadAsAsync(this HttpResponseMessage response) => await response.Content.ReadFromJsonAsync(JsonOptions); public static Task PostJsonAsync( this HttpClient client, string url, object body ) => client.PostAsJsonAsync(url, body, JsonOptions); public static Task SendPutJsonAsync( this HttpClient client, string url, object body ) => client.PutAsJsonAsync(url, body, JsonOptions); }