Skip to content

Commit

Permalink
refactor(test): avoid using HTTP assertions from FluentAssertions as …
Browse files Browse the repository at this point in the history
…they will be gone with v8
  • Loading branch information
mu88 committed Jan 19, 2025
1 parent eb403f0 commit 36ce52f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions tests/Tests/Integration/HealthCheckerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc.Testing;
using mu88.HealthCheck;
using RichardSzalay.MockHttp;
using System.Net;

namespace Tests.Integration;

Expand All @@ -22,7 +23,7 @@ public async Task HealthChecker_ShouldIndicateSuccess_WhenAppIsHealthy()
var healthCheckerResult = await healthChecker.CheckHealthAsync(["healthz"]);

// Assert
response.Should().BeSuccessful();
response.StatusCode.Should().Be(HttpStatusCode.OK);
healthCheckerResult.Should().Be(0);
}

Expand Down Expand Up @@ -54,7 +55,7 @@ public async Task HealthChecker_ShouldIndicateFailure_WhenWrongHealthCheckEndpoi
var healthCheckerResult = await healthChecker.CheckHealthAsync(["invalidHealthCheckEndpoint"]);

// Assert
response.Should().BeSuccessful();
response.StatusCode.Should().Be(HttpStatusCode.OK);
healthCheckerResult.Should().Be(1);
}

Expand All @@ -71,7 +72,7 @@ public async Task HealthChecker_ShouldThrowArgumentException_WhenUriIsInvalid()
Func<Task> act = async () => await healthChecker.CheckHealthAsync([]);

// Assert
response.Should().BeSuccessful();
response.StatusCode.Should().Be(HttpStatusCode.OK);
await act.Should().ThrowAsync<ArgumentException>().WithMessage("A valid URI must be given as first argument (Parameter 'args')");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Net;
using FluentAssertions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
Expand All @@ -19,7 +20,7 @@ public async Task WebApp_ShouldExposeMetrics()
using var httpClient = customWebApplicationFactory.CreateClient();

// Act
(await httpClient.GetAsync("hello")).Should().BeSuccessful(); // trigger metrics creation
(await httpClient.GetAsync("hello")).StatusCode.Should().Be(HttpStatusCode.OK);; // trigger metrics creation
await customWebApplicationFactory.DisposeAsync(); // must be disposed, otherwise metrics remain empty
await WaitAsync(metrics, TimeSpan.FromSeconds(30)); // wait some time so that the metrics get populated

Expand Down
5 changes: 3 additions & 2 deletions tests/Tests/System/SystemTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Net;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Networks;
Expand Down Expand Up @@ -45,13 +46,13 @@ public async Task AppRunningInDocker_ShouldBeHealthy()

private static async Task AppShouldRunAsync(HttpResponseMessage appResponse, CancellationToken cancellationToken)
{
appResponse.Should().BeSuccessful();
appResponse.StatusCode.Should().Be(HttpStatusCode.OK);
(await appResponse.Content.ReadAsStringAsync(cancellationToken)).Should().Contain("World");
}

private static async Task HealthCheckShouldBeHealthyAsync(HttpResponseMessage healthCheckResponse, CancellationToken cancellationToken)
{
healthCheckResponse.Should().BeSuccessful();
healthCheckResponse.StatusCode.Should().Be(HttpStatusCode.OK);
(await healthCheckResponse.Content.ReadAsStringAsync(cancellationToken)).Should().Be("Healthy");
}

Expand Down

0 comments on commit 36ce52f

Please sign in to comment.