1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
namespace Cepis.Tests;
/// <summary>The health endpoint, which reports rather than throws.</summary>
public sealed class HealthTests : HttpTestBase
{
[Fact]
public async Task ReadsAHealthyApi()
{
Server.Respond("/health", Reply.Of(200, Fixtures.Healthy));
var health = await Client.HealthAsync();
Assert.True(health.Ok);
Assert.Equal("ok", health.Status);
Assert.Equal("26071", health.Dne);
Assert.Equal(1596168, health.Ceps);
Assert.Equal(894489, health.Geo);
Assert.Equal("2026-07-24T03:48:28Z", health.BaseGeradaEm);
}
[Fact]
public async Task ADegradedApiReportsRatherThanThrows()
{
Server.Respond("/health", Reply.Of(503,
"""{"status":"degradado","dne":"26071","ceps":0,"geo":0,"base_gerada_em":""}"""));
var health = await Client.HealthAsync();
Assert.False(health.Ok);
Assert.Equal("degradado", health.Status);
Assert.Equal(1, Server.Count("/health"));
}
[Fact]
public async Task AnUnreachableApiStillThrows()
{
using var unreachable = new CepisClient(new CepisClientOptions
{
BaseUrl = "http://127.0.0.1:1",
MaxAttempts = 1,
Timeout = TimeSpan.FromSeconds(30),
});
await Assert.ThrowsAsync<NetworkException>(() => unreachable.HealthAsync());
}
}
|