Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to aspire 8.1 & using WireMock.Net.Aspire #15

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>
</Project>
151 changes: 76 additions & 75 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<AspnetVersion>8.0.5</AspnetVersion>
<MicrosoftExtensionsVersion>8.4.0</MicrosoftExtensionsVersion>
<EfVersion>8.0.4</EfVersion>
<AspireVersion>8.0.1</AspireVersion>
<AspirantVersion>0.0.4</AspirantVersion>
<HealthCheckVersion>8.0.1</HealthCheckVersion>
<AspVersioningVersion>8.1.0</AspVersioningVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.AspNet.WebApi.Core" Version="5.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="$(AspnetVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="$(EfVersion)" PrivateAssets="all" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EfVersion)" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.10" />
<PackageVersion Include="Asp.Versioning.Http" Version="$(AspVersioningVersion)" />
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="$(AspVersioningVersion)" />
<PackageVersion Include="Asp.Versioning.Http.Client" Version="$(AspVersioningVersion)" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="MediatR" Version="12.2.0" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="FluentValidation" Version="11.9.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Riok.Mapperly" Version="3.5.1" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageVersion Include="MassTransit" Version="8.1.2" />
<PackageVersion Include="MassTransit.RabbitMQ" Version="8.1.2" />
<PackageVersion Include="Marten.AspNetCore" Version="7.10.1" />
<PackageVersion Include="Marten" Version="7.10.1" />
<PackageVersion Include="Yarp.ReverseProxy" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<!-- Aspire -->
<PackageVersion Include="Aspire.Hosting" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.RabbitMQ" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Redis" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Testing" Version="$(AspireVersion)" />
<PackageVersion Include="Aspirant.Hosting" Version="$(AspirantVersion)" />
<PackageVersion Include="Aspirant.Hosting.Yarp" Version="$(AspirantVersion)" />
<PackageVersion Include="Aspirant.Hosting.Testing" Version="$(AspirantVersion)" />
<PackageVersion Include="Fredi.Aspire.Hosting.WireMock" Version="0.0.1" />
<!-- Aspire Custom Extensions -->
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="$(AspireVersion)" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.8.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.8.0" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0-beta.2" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0-beta.4" />
</ItemGroup>
<ItemGroup>
<!-- Healthchecks -->
<PackageVersion Include="AspNetCore.HealthChecks.Uris" Version="$(HealthCheckVersion)" />
<PackageVersion Include="AspNetCore.HealthChecks.NpgSql" Version="$(HealthCheckVersion)" />
<PackageVersion Include="AspNetCore.HealthChecks.Rabbitmq" Version="$(HealthCheckVersion)" />
<PackageVersion Include="AspNetCore.HealthChecks.Redis" Version="$(HealthCheckVersion)" />
</ItemGroup>
<ItemGroup>
<!-- Testing -->
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="xunit" Version="2.5.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageVersion Include="MSTest" Version="3.2.0" />
<PackageVersion Include="ReportGenerator" Version="5.3.6" />

</ItemGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<AspnetVersion>8.0.5</AspnetVersion>
<MicrosoftExtensionsVersion>8.4.0</MicrosoftExtensionsVersion>
<EfVersion>8.0.4</EfVersion>
<AspireVersion>8.1.0</AspireVersion>
<OpenTelemetryVersion>1.9.0</OpenTelemetryVersion>
<AspirantVersion>0.0.4</AspirantVersion>
<HealthCheckVersion>8.0.1</HealthCheckVersion>
<AspVersioningVersion>8.1.0</AspVersioningVersion>
<MassTransitVersion>8.2.4</MassTransitVersion>
<MartenVersion>7.10.1</MartenVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.AspNet.WebApi.Core" Version="5.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="$(AspnetVersion)" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="$(EfVersion)" PrivateAssets="all" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(EfVersion)" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.10" />
<PackageVersion Include="Asp.Versioning.Http" Version="$(AspVersioningVersion)" />
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="$(AspVersioningVersion)" />
<PackageVersion Include="Asp.Versioning.Http.Client" Version="$(AspVersioningVersion)" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="MediatR" Version="12.4.0" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="FluentValidation" Version="11.9.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Riok.Mapperly" Version="3.5.1" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageVersion Include="MassTransit" Version="$(MassTransitVersion)" />
<PackageVersion Include="MassTransit.RabbitMQ" Version="$(MassTransitVersion)" />
<PackageVersion Include="Marten.AspNetCore" Version="$(MartenVersion)" />
<PackageVersion Include="Marten" Version="$(MartenVersion)" />
<PackageVersion Include="Yarp.ReverseProxy" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<!-- Aspire -->
<PackageVersion Include="Aspire.Hosting" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.RabbitMQ" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Redis" Version="$(AspireVersion)" />
<PackageVersion Include="Aspirant.Hosting" Version="$(AspirantVersion)" />
<PackageVersion Include="Aspirant.Hosting.Yarp" Version="$(AspirantVersion)" />
<PackageVersion Include="Aspirant.Hosting.Testing" Version="$(AspirantVersion)" />
<PackageVersion Include="WireMock.Net.Aspire" Version="0.0.1-preview-05" />
<!-- Aspire Custom Extensions -->
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.7.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="$(AspireVersion)" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="$(OpenTelemetryVersion)" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0-beta.2" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0-beta.4" />
</ItemGroup>
<ItemGroup>
<!-- Healthchecks -->
<PackageVersion Include="AspNetCore.HealthChecks.Uris" Version="$(HealthCheckVersion)" />
<PackageVersion Include="AspNetCore.HealthChecks.NpgSql" Version="$(HealthCheckVersion)" />
<PackageVersion Include="AspNetCore.HealthChecks.Rabbitmq" Version="$(HealthCheckVersion)" />
<PackageVersion Include="AspNetCore.HealthChecks.Redis" Version="$(HealthCheckVersion)" />
</ItemGroup>
<ItemGroup>
<!-- Testing -->
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="xunit" Version="2.5.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageVersion Include="MSTest" Version="3.2.0" />
<PackageVersion Include="ReportGenerator" Version="5.3.6" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions app-host/app1.http
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ content-type: application/json

###
@orderId = 8cf20000-8d12-00ff-acd0-08dc7cc27ccd

###
GET https://{{hostname}}/audit/api/v1/summary?orderId={{orderId}}
content-type: application/json
36 changes: 15 additions & 21 deletions counter-api-tests/CoffeeShop.CounterApi.IntegrationTests.csproj
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPublishable>false</IsPublishable>
<IsPackable>false</IsPackable>
<IsPackable>false</IsPackable>
<IsAspireHost>true</IsAspireHost>
</PropertyGroup>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Fredi.Aspire.Hosting.WireMock" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="WireMock.Net.Aspire" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="ReportGenerator" />
<PackageReference Include="Asp.Versioning.Http.Client" />
<PackageReference Include="MSTest" />
</ItemGroup>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
<PackageReference Include="Aspire.Hosting.Redis" />
<PackageReference Include="Aspire.Hosting.RabbitMQ" />
<PackageReference Include="Aspirant.Hosting" />
<PackageReference Include="Aspirant.Hosting.Testing" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" />
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" />
<PackageReference Include="AspNetCore.HealthChecks.Redis" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" />
</ItemGroup>

<ItemGroup>
Expand Down
54 changes: 23 additions & 31 deletions counter-api-tests/CounterApiFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@

using MassTransit;

using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;

using WireMock.Client.Builders;

using Xunit;

namespace CoffeeShop.CounterApi.IntegrationTests;

public sealed class CounterApiFixture : WebApplicationFactory<Program>, IAsyncLifetime
Expand All @@ -26,17 +20,18 @@ public sealed class CounterApiFixture : WebApplicationFactory<Program>, IAsyncLi
public IResourceBuilder<RabbitMQServerResource> RabbitMq { get; private set; }
private string _rabbitMqConnectionString;

public IResourceBuilder<WireMockNetResource> ProductApi { get; private set; }
public IResourceBuilder<WireMockServerResource> ProductApi { get; private set; }

public CounterApiFixture()
{
var options = new DistributedApplicationOptions { AssemblyName = typeof(CounterApiFixture).Assembly.FullName, DisableDashboard = true };
var appBuilder = DistributedApplication.CreateBuilder(options);

Postgres = appBuilder.AddPostgres("postgresQL");
RabbitMq = appBuilder.AddRabbitMQ("rabbitmq").WithHealthCheck();
ProductApi = appBuilder.AddWireMockNet("product-api")
.WithApiMappingBuilder(ProductApiMock.Build);
RabbitMq = appBuilder.AddRabbitMQ("rabbitmq");

ProductApi = appBuilder.AddWireMock("product-api", WireMockServerArguments.DefaultPort)
.WithApiMappingBuilder(ProductApiMock.BuildAsync);

_app = appBuilder.Build();
}
Expand Down Expand Up @@ -72,16 +67,13 @@ protected override IHost CreateHost(IHostBuilder builder)
return base.CreateHost(builder);
}

public async Task InitializeAsync()
{
await _app.StartAsync();

_postgresConnectionString = await Postgres.Resource.GetConnectionStringAsync();
_rabbitMqConnectionString = await RabbitMq.Resource.ConnectionStringExpression.GetValueAsync(default);
public async Task InitializeAsync()
{
await _app.StartAsync();

// if don't waiting then WireMock will be failed
await Task.Delay(TimeSpan.FromSeconds(5));
}
_postgresConnectionString = await Postgres.Resource.GetConnectionStringAsync() ?? throw new InvalidOperationException("Postgres connection string is null");
_rabbitMqConnectionString = await RabbitMq.Resource.ConnectionStringExpression.GetValueAsync(default) ?? throw new InvalidOperationException("RabbitMQ connection string is null");
}

public new async Task DisposeAsync()
{
Expand All @@ -100,25 +92,25 @@ public async Task InitializeAsync()

internal class ProductApiMock
{
public static async Task Build(AdminApiMappingBuilder builder)
public static async Task BuildAsync(AdminApiMappingBuilder builder)
{
var itemTypes = new List<ItemTypeDto> {
new() {
ItemType = ItemType.CAKEPOP
},
new() {
ItemType = ItemType.CAPPUCCINO
}};

builder.Given(builder => builder
builder.Given(b => b
.WithRequest(request => request
.UsingGet()
.WithPath("/api/v1/item-types")
)
.WithResponse(response => response
.WithBodyAsJson(itemTypes)
.WithHeaders(h => h.Add("Content-Type", "application/json"))
.WithBodyAsJson(() => new List<ItemTypeDto> {
new() {
ItemType = ItemType.CAKEPOP
},
new() {
ItemType = ItemType.CAPPUCCINO
}
}.ToArray()
)
);
));

await builder.BuildAndPostAsync();
}
Expand Down
8 changes: 0 additions & 8 deletions counter-api-tests/CounterApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
using CounterApi.Domain.Commands;
using CounterApi.IntegrationEvents.EventHandlers;

using MassTransit.Testing;

using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;

using Xunit;

namespace CoffeeShop.CounterApi.IntegrationTests;

internal class RetryHandler : DelegatingHandler
Expand Down
6 changes: 6 additions & 0 deletions counter-api-tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
global using MassTransit.Testing;
global using Microsoft.AspNetCore.Mvc.Testing;
global using Microsoft.AspNetCore.TestHost;
global using Microsoft.Extensions.DependencyInjection;
global using Xunit;
global using WireMock.Client.Builders;
Loading
Loading