test: add ApiClientBaseTests with 200 OK mapping test

This commit is contained in:
Joseph Doherty
2026-01-06 11:17:19 -05:00
parent 626b7a63f2
commit e75ebe1ffb
@@ -0,0 +1,39 @@
using System.Net;
using System.Text.Json;
using JdeScoping.Core.ApiContracts.Results;
using RichardSzalay.MockHttp;
using Shouldly;
namespace JdeScoping.Client.Tests.Services;
public class ApiClientBaseTests
{
private readonly MockHttpMessageHandler _mockHttp;
private readonly TestableApiClient _client;
public ApiClientBaseTests()
{
_mockHttp = new MockHttpMessageHandler();
var httpClient = new HttpClient(_mockHttp) { BaseAddress = new Uri("http://localhost/") };
_client = new TestableApiClient(httpClient);
}
public record TestDto(int Id, string Name);
[Fact]
public async Task GetAsync_Returns200_MapsToSuccessValue()
{
// Arrange
var expected = new TestDto(42, "Test");
_mockHttp.When("/api/test")
.Respond("application/json", JsonSerializer.Serialize(expected));
// Act
var result = await _client.GetAsync<TestDto>("/api/test");
// Assert
result.IsSuccess.ShouldBeTrue();
result.Value.Id.ShouldBe(42);
result.Value.Name.ShouldBe("Test");
}
}