diff --git a/NEW/tests/JdeScoping.Client.Tests/JdeScoping.Client.Tests.csproj b/NEW/tests/JdeScoping.Client.Tests/JdeScoping.Client.Tests.csproj index a297514..ae0028e 100644 --- a/NEW/tests/JdeScoping.Client.Tests/JdeScoping.Client.Tests.csproj +++ b/NEW/tests/JdeScoping.Client.Tests/JdeScoping.Client.Tests.csproj @@ -7,6 +7,10 @@ false + + + + diff --git a/NEW/tests/JdeScoping.Client.Tests/Services/ApiClientBaseTests.cs b/NEW/tests/JdeScoping.Client.Tests/Services/ApiClientBaseTests.cs index a0e8929..de45b2d 100644 --- a/NEW/tests/JdeScoping.Client.Tests/Services/ApiClientBaseTests.cs +++ b/NEW/tests/JdeScoping.Client.Tests/Services/ApiClientBaseTests.cs @@ -36,4 +36,85 @@ public class ApiClientBaseTests result.Value.Id.ShouldBe(42); result.Value.Name.ShouldBe("Test"); } + + [Fact] + public async Task GetAsync_Returns404_MapsToNotFound() + { + // Arrange + _mockHttp.When("/api/test") + .Respond(HttpStatusCode.NotFound); + + // Act + var result = await _client.GetAsync("/api/test"); + + // Assert + result.IsNotFound.ShouldBeTrue(); + } + + [Fact] + public async Task GetAsync_Returns400_WithValidationErrors_MapsToValidationError() + { + // Arrange - use actual ValidationProblemDetails structure to match production + var validationProblem = new Microsoft.AspNetCore.Mvc.ValidationProblemDetails + { + Errors = + { + ["Name"] = new[] { "Name is required" }, + ["Id"] = new[] { "Id must be positive" } + } + }; + _mockHttp.When("/api/test") + .Respond(HttpStatusCode.BadRequest, "application/json", JsonSerializer.Serialize(validationProblem, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); + + // Act + var result = await _client.GetAsync("/api/test"); + + // Assert + result.IsValidationError.ShouldBeTrue(); + result.ValidationError.FieldErrors.ShouldContainKey("Name"); + result.ValidationError.FieldErrors["Name"].ShouldContain("Name is required"); + } + + [Fact] + public async Task GetAsync_Returns401_MapsToUnauthorized() + { + // Arrange + _mockHttp.When("/api/test") + .Respond(HttpStatusCode.Unauthorized); + + // Act + var result = await _client.GetAsync("/api/test"); + + // Assert + result.IsUnauthorized.ShouldBeTrue(); + } + + [Fact] + public async Task GetAsync_Returns403_MapsToForbidden() + { + // Arrange + _mockHttp.When("/api/test") + .Respond(HttpStatusCode.Forbidden); + + // Act + var result = await _client.GetAsync("/api/test"); + + // Assert + result.IsForbidden.ShouldBeTrue(); + } + + [Fact] + public async Task GetAsync_Returns500_MapsToApiError() + { + // Arrange + _mockHttp.When("/api/test") + .Respond(HttpStatusCode.InternalServerError, "text/plain", "Internal Server Error"); + + // Act + var result = await _client.GetAsync("/api/test"); + + // Assert + result.IsError.ShouldBeTrue(); + result.Error.StatusCode.ShouldBe(500); + } }