18 lines
485 B
C#
18 lines
485 B
C#
using System.Text.Json;
|
|
using Shouldly;
|
|
|
|
namespace Solar.Api.Tests.Extensions;
|
|
|
|
public static class HttpClientExtensions
|
|
{
|
|
public static async Task<T> FetchJson<T>(this HttpClient client, string path) where T : class
|
|
{
|
|
var response = await client.GetAsync(path);
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
var result = JsonSerializer.Deserialize<T>(await response.Content.ReadAsStringAsync());
|
|
result.ShouldNotBeNull();
|
|
|
|
return result;
|
|
}
|
|
} |