mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 09:18:55 +02:00
Add Aspire Extension (#1109)
* WireMock.Net.Aspire * . * xxx * nuget * [CodeFactor] Apply fixes * ut * t * **WireMock.Net.Aspire** * . * t * . * . * . * TESTS * docker utils * Install .NET Aspire workload * 4 * 4! * projects: '**/test/**/*.csproj' * script: 'dotnet workload install aspire' * projects: '**/test/**/*.csproj' * coverage * WithWatchStaticMappings * Admin * typo * port * fix * . * x * ... * wait * readme * x * 2 * async * <Version>0.0.1-preview-03</Version> * ... * fix aspire * admin/pwd * Install .NET Aspire workload * 0.0.1-preview-04 * WaitForHealthAsync * ... * IsHealthyAsync * . * add eps * name: 'Execute Aspire Tests' * name: Install .NET Aspire workload * . * dotnet test * remove duplicate * . * cc * dotnet tool install --global coverlet.console * -* * merge * /d:sonar.pullrequest.provider=github * <Version>0.0.1-preview-05</Version> * // Copyright © WireMock.Net * . --------- Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
75
test/WireMock.Net.Aspire.Tests/IntegrationTests.cs
Normal file
75
test/WireMock.Net.Aspire.Tests/IntegrationTests.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Net.Http.Json;
|
||||
using FluentAssertions;
|
||||
using Projects;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace WireMock.Net.Aspire.Tests;
|
||||
|
||||
public class IntegrationTests(ITestOutputHelper output)
|
||||
{
|
||||
private record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary);
|
||||
|
||||
[Fact]
|
||||
public async Task StartAppHostWithWireMockAndCreateHttpClientToCallTheMockedWeatherForecastEndpoint()
|
||||
{
|
||||
if (!DockerUtils.IsDockerRunningLinuxContainerMode())
|
||||
{
|
||||
output.WriteLine("Docker is not running in Linux container mode. Skipping test.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Arrange
|
||||
var appHostBuilder = await DistributedApplicationTestingBuilder.CreateAsync<WireMock_Net_Aspire_TestAppHost>();
|
||||
await using var app = await appHostBuilder.BuildAsync();
|
||||
await app.StartAsync();
|
||||
|
||||
using var httpClient = app.CreateHttpClient("wiremock-service");
|
||||
|
||||
// Act 1
|
||||
var weatherForecasts1 = await httpClient.GetFromJsonAsync<WeatherForecast[]>("/weatherforecast");
|
||||
|
||||
// Assert 1
|
||||
weatherForecasts1.Should().BeEquivalentTo(new[]
|
||||
{
|
||||
new WeatherForecast(new DateOnly(2024, 5, 24), -10, "Freezing"),
|
||||
new WeatherForecast(new DateOnly(2024, 5, 25), +33, "Hot")
|
||||
});
|
||||
|
||||
// Act 2
|
||||
var weatherForecasts2 = await httpClient.GetFromJsonAsync<WeatherForecast[]>("/weatherforecast2");
|
||||
|
||||
// Assert 2
|
||||
weatherForecasts2.Should().HaveCount(5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartAppHostWithWireMockAndCreateWireMockAdminClientToCallTheAdminEndpoint()
|
||||
{
|
||||
if (!DockerUtils.IsDockerRunningLinuxContainerMode())
|
||||
{
|
||||
output.WriteLine("Docker is not running in Linux container mode. Skipping test.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Arrange
|
||||
var appHostBuilder = await DistributedApplicationTestingBuilder.CreateAsync<WireMock_Net_Aspire_TestAppHost>();
|
||||
await using var app = await appHostBuilder.BuildAsync();
|
||||
await app.StartAsync();
|
||||
|
||||
var adminClient = app.CreateWireMockAdminClient("wiremock-service");
|
||||
|
||||
// Act 1
|
||||
var settings = await adminClient.GetSettingsAsync();
|
||||
|
||||
// Assert 1
|
||||
settings.Should().NotBeNull();
|
||||
|
||||
// Act 2
|
||||
var mappings = await adminClient.GetMappingsAsync();
|
||||
|
||||
// Assert 2
|
||||
mappings.Should().HaveCount(2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user