test: add xUnit test coverage for API controllers and client services
Create ChatAgent.Api.Tests and ChatAgent.Client.Tests projects with xUnit and Moq. Test HealthController (200 + valid response), ChatController (SSE streaming with mocked upstream, error handling), and ChatApiClient (delta parsing, error events, health endpoint). 6 tests, all passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
29
tests/ChatAgent.Api.Tests/HealthControllerTests.cs
Normal file
29
tests/ChatAgent.Api.Tests/HealthControllerTests.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using ChatAgent.Shared.Models;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
|
||||
namespace ChatAgent.Api.Tests;
|
||||
|
||||
public class HealthControllerTests : IClassFixture<WebApplicationFactory<Program>>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
|
||||
public HealthControllerTests(WebApplicationFactory<Program> factory)
|
||||
{
|
||||
_client = factory.CreateClient();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetHealth_Returns200_WithValidHealthResponse()
|
||||
{
|
||||
var response = await _client.GetAsync("/api/health");
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var health = await response.Content.ReadFromJsonAsync<HealthResponse>();
|
||||
Assert.NotNull(health);
|
||||
Assert.Equal("healthy", health.Status);
|
||||
Assert.True(health.Timestamp > DateTime.MinValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user