WIP
This commit is contained in:
18
tests/Solar.Api.Tests/Extensions/HttpClientExtensions.cs
Normal file
18
tests/Solar.Api.Tests/Extensions/HttpClientExtensions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user