Skip to content

Commit

Permalink
test: use FluentAssertions.Web
Browse files Browse the repository at this point in the history
  • Loading branch information
mu88 committed Jan 24, 2025
1 parent cb68075 commit ab5122e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ItemGroup>
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
<PackageVersion Include="FluentAssertions" Version="8.0.0" />
<PackageVersion Include="FluentAssertions.Web.v8" Version="1.8.0"/>
<PackageVersion Include="IDisposableAnalyzers" Version="4.0.8" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.186" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.1" />
Expand Down
6 changes: 3 additions & 3 deletions tests/Tests/Integration/HealthCheckerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task HealthChecker_ShouldIndicateSuccess_WhenAppIsHealthy()
var healthCheckerResult = await healthChecker.CheckHealthAsync(["healthz"]);

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

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

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

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

// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Should().Be200Ok();
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
Expand Up @@ -20,7 +20,7 @@ public async Task WebApp_ShouldExposeMetrics()
using var httpClient = customWebApplicationFactory.CreateClient();

// Act
(await httpClient.GetAsync("hello")).StatusCode.Should().Be(HttpStatusCode.OK);; // trigger metrics creation
(await httpClient.GetAsync("hello")).Should().Be200Ok(); // 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
4 changes: 2 additions & 2 deletions tests/Tests/System/SystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public async Task AppRunningInDocker_ShouldBeHealthy()

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

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

Expand Down
1 change: 1 addition & 0 deletions tests/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions"/>
<PackageReference Include="FluentAssertions.Web.v8"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
Expand Down

0 comments on commit ab5122e

Please sign in to comment.