Skip to content

Commit e76b947

Browse files
authored
feat: Apply .NET Aspire orchestration to Chapter 2 (#226)
1 parent 369936c commit e76b947

File tree

16 files changed

+88
-97
lines changed

16 files changed

+88
-97
lines changed

Chapter-1-initial-architecture/Src/Fitnet.UnitTests/GlobalExceptionHandlerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private async Task<ProblemDetails> GetExceptionResponseMessage()
6161
using var streamReader = new StreamReader(_context.Response.Body);
6262
var responseBody = await streamReader.ReadToEndAsync();
6363
var problemDetails = JsonConvert.DeserializeObject<ProblemDetails>(responseBody);
64+
6465
return problemDetails!;
6566
}
6667
}

Chapter-2-modules-separation/README.adoc

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,21 @@ to download it from the official Microsoft website.
138138

139139
=== Run locally
140140

141-
The Fitnet application requires Docker to run properly.
141+
The Fitnet application uses .NET Aspire for local development.
142142

143-
There are only 3 steps you need to start the application:
143+
To run the application locally, follow these steps:
144144

145-
1. Make sure that you are in `/Src` directory.
146-
2. Run `docker-compose build` to build the image of the application.
147-
3. Run `docker-compose up` to start the application. In the meantime it will also start Postgres inside container.
145+
1. **Ensure Docker is running** on your machine.
146+
2. **Navigate to the solution root directory** in your terminal.
147+
3. **Run the AppHost project using the following command:**
148148

149-
The application runs on port `:8080`. Please navigate to http://localhost:8080 in your browser or http://localhost:8080/swagger/index.html to explore the API.
149+
=== How to run Integration Tests?
150+
To run the integration tests for the project located in the `Fitnet.IntegrationTests` project, you can use either the command:
150151

151-
That's it! You should now be able to run the application using either one of the above. :thumbsup:
152+
`dotnet test`
153+
154+
or the `IDE test explorer`.
155+
156+
These tests are written using `xUnit` and require `Docker` to be running as they use `test containers` package to run PostgresSQL in a Docker container during testing.
152157

153-
=== How to run Integration Tests?
154-
To run the integration tests go to a module integration tests (`SelectedModule.IntegrationTests`) and run using either the command:
155-
[source,shell]
156-
----
157-
dotnet test
158-
----
159-
or the `IDE test Explorer`.
160-
161-
These tests are written using `xUnit` and require `Docker` to be running as they use `test containers` package to run PostgresSQL in a Docker container during testing.
162158
Therefore, make sure to have `Docker` running before executing the integration tests.

Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184153_MakeSignedAtColumnNullable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#nullable disable
22

33
namespace EvolutionaryArchitecture.Fitnet.Contracts.Data.Database.Migrations;
4-
using System;
4+
55
using Microsoft.EntityFrameworkCore.Migrations;
66

77
[ExcludeFromCodeCoverage]

Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184328_AddCustomerIdColumn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#nullable disable
22

33
namespace EvolutionaryArchitecture.Fitnet.Contracts.Data.Database.Migrations;
4-
using System;
4+
55
using Microsoft.EntityFrameworkCore.Migrations;
66

77
[ExcludeFromCodeCoverage]

Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230624171216_ContractsAddColumnsToSupportContractExpiration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#nullable disable
22

33
namespace EvolutionaryArchitecture.Fitnet.Contracts.Data.Database.Migrations;
4-
using System;
4+
55
using Microsoft.EntityFrameworkCore.Migrations;
66

77
[ExcludeFromCodeCoverage]

Chapter-2-modules-separation/Src/Directory.Packages.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
55
<ItemGroup Label="Production">
6+
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
7+
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="9.0.0" />
68
<PackageVersion Include="Dapper" Version="2.1.66" />
79
<PackageVersion Include="FluentValidation" Version="12.0.0" />
810
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />
911
<PackageVersion Include="JetBrains.Annotations" Version="2025.2.2" />
12+
<PackageVersion Include="KubernetesClient" Version="17.0.14" />
1013
<PackageVersion Include="MediatR" Version="12.5.0" />
1114
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
1215
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />

Chapter-2-modules-separation/Src/Dockerfile

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0"/>
3+
4+
<PropertyGroup>
5+
<OutputType>Exe</OutputType>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsAspireHost>true</IsAspireHost>
9+
<UserSecretsId>a3ef42d8-8e72-4dd1-a8a7-cd43e2c575e8</UserSecretsId>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Aspire.Hosting.AppHost" />
14+
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
15+
<PackageReference Include="KubernetesClient" />
16+
<PackageReference Update="SonarAnalyzer.CSharp" Version="10.15.0.120848" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\Fitnet\Fitnet.csproj"/>
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Projects;
2+
3+
var builder = DistributedApplication.CreateBuilder(args);
4+
var postgres = builder.AddPostgres("postgres")
5+
.WithImage("postgres", "14.3")
6+
.WithPgAdmin();
7+
var db = postgres.AddDatabase("fitnetsdb", "fitnet");
8+
9+
builder.AddProject<Fitnet>("fitnet")
10+
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
11+
.WithEnvironment("Passes__ConnectionStrings__Primary", db)
12+
.WithEnvironment("Contracts__ConnectionStrings__Primary", db)
13+
.WithEnvironment("Reports__ConnectionStrings__Primary", db)
14+
.WithEnvironment("Offers__ConnectionStrings__Primary", db)
15+
.WaitFor(postgres);
16+
17+
await builder.Build().RunAsync();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17106;http://localhost:15108",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21130",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22190"
14+
}
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)