summaryrefslogtreecommitdiffstats
path: root/tests/Cepis.Tests/HealthTests.cs
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 12:42:38 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 13:10:34 -0300
commita2b10fd494fb389e556e40134031eb86e56e11e7 (patch)
tree08b6df8a06f2c7c15488b90d57a6d8286cd57a22 /tests/Cepis.Tests/HealthTests.cs
downloadcsharp-a2b10fd494fb389e556e40134031eb86e56e11e7.tar.gz
Initial importv0.1.0
Diffstat (limited to 'tests/Cepis.Tests/HealthTests.cs')
-rw-r--r--tests/Cepis.Tests/HealthTests.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/Cepis.Tests/HealthTests.cs b/tests/Cepis.Tests/HealthTests.cs
new file mode 100644
index 0000000..2855d72
--- /dev/null
+++ b/tests/Cepis.Tests/HealthTests.cs
@@ -0,0 +1,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());
+ }
+}