diff --git a/Chapter-1-initial-architecture/Src/Fitnet.UnitTests/GlobalExceptionHandlerTests.cs b/Chapter-1-initial-architecture/Src/Fitnet.UnitTests/GlobalExceptionHandlerTests.cs index 1b9bc546..22f0c1b0 100644 --- a/Chapter-1-initial-architecture/Src/Fitnet.UnitTests/GlobalExceptionHandlerTests.cs +++ b/Chapter-1-initial-architecture/Src/Fitnet.UnitTests/GlobalExceptionHandlerTests.cs @@ -61,6 +61,7 @@ private async Task GetExceptionResponseMessage() using var streamReader = new StreamReader(_context.Response.Body); var responseBody = await streamReader.ReadToEndAsync(); var problemDetails = JsonConvert.DeserializeObject(responseBody); + return problemDetails!; } } diff --git a/Chapter-2-modules-separation/README.adoc b/Chapter-2-modules-separation/README.adoc index da2abe6e..daa15cfa 100644 --- a/Chapter-2-modules-separation/README.adoc +++ b/Chapter-2-modules-separation/README.adoc @@ -138,25 +138,21 @@ to download it from the official Microsoft website. === Run locally -The Fitnet application requires Docker to run properly. +The Fitnet application uses .NET Aspire for local development. -There are only 3 steps you need to start the application: +To run the application locally, follow these steps: -1. Make sure that you are in `/Src` directory. -2. Run `docker-compose build` to build the image of the application. -3. Run `docker-compose up` to start the application. In the meantime it will also start Postgres inside container. +1. **Ensure Docker is running** on your machine. +2. **Navigate to the solution root directory** in your terminal. +3. **Run the AppHost project using the following command:** -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. +=== How to run Integration Tests? +To run the integration tests for the project located in the `Fitnet.IntegrationTests` project, you can use either the command: -That's it! You should now be able to run the application using either one of the above. :thumbsup: +`dotnet test` + +or the `IDE test explorer`. + +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. -=== How to run Integration Tests? -To run the integration tests go to a module integration tests (`SelectedModule.IntegrationTests`) and run using either the command: -[source,shell] ----- -dotnet test ----- -or the `IDE test Explorer`. - -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. Therefore, make sure to have `Docker` running before executing the integration tests. diff --git a/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184153_MakeSignedAtColumnNullable.cs b/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184153_MakeSignedAtColumnNullable.cs index 8b35b64c..571ebd8b 100644 --- a/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184153_MakeSignedAtColumnNullable.cs +++ b/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184153_MakeSignedAtColumnNullable.cs @@ -1,7 +1,7 @@ #nullable disable namespace EvolutionaryArchitecture.Fitnet.Contracts.Data.Database.Migrations; -using System; + using Microsoft.EntityFrameworkCore.Migrations; [ExcludeFromCodeCoverage] diff --git a/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184328_AddCustomerIdColumn.cs b/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184328_AddCustomerIdColumn.cs index cf6a802e..97062368 100644 --- a/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184328_AddCustomerIdColumn.cs +++ b/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230601184328_AddCustomerIdColumn.cs @@ -1,7 +1,7 @@ #nullable disable namespace EvolutionaryArchitecture.Fitnet.Contracts.Data.Database.Migrations; -using System; + using Microsoft.EntityFrameworkCore.Migrations; [ExcludeFromCodeCoverage] diff --git a/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230624171216_ContractsAddColumnsToSupportContractExpiration.cs b/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230624171216_ContractsAddColumnsToSupportContractExpiration.cs index 30e31b28..6b90e659 100644 --- a/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230624171216_ContractsAddColumnsToSupportContractExpiration.cs +++ b/Chapter-2-modules-separation/Src/Contracts/Fitnet.Contracts.Infrastructure/Database/Migrations/20230624171216_ContractsAddColumnsToSupportContractExpiration.cs @@ -1,7 +1,7 @@ #nullable disable namespace EvolutionaryArchitecture.Fitnet.Contracts.Data.Database.Migrations; -using System; + using Microsoft.EntityFrameworkCore.Migrations; [ExcludeFromCodeCoverage] diff --git a/Chapter-2-modules-separation/Src/Directory.Packages.props b/Chapter-2-modules-separation/Src/Directory.Packages.props index 6f76a4a9..ed74deb1 100644 --- a/Chapter-2-modules-separation/Src/Directory.Packages.props +++ b/Chapter-2-modules-separation/Src/Directory.Packages.props @@ -3,10 +3,13 @@ true + + + diff --git a/Chapter-2-modules-separation/Src/Dockerfile b/Chapter-2-modules-separation/Src/Dockerfile deleted file mode 100644 index c7eab40d..00000000 --- a/Chapter-2-modules-separation/Src/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base -WORKDIR /app -EXPOSE 80 -EXPOSE 443 - -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build -WORKDIR /src -COPY Directory.Build.props ./ -COPY ["Fitnet/Fitnet.csproj", "Fitnet/"] -RUN dotnet restore "Fitnet/Fitnet.csproj" -COPY . . -WORKDIR "/src/Fitnet" -RUN dotnet build "Fitnet.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "Fitnet.csproj" -c Release -o /app/publish - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "EvolutionaryArchitecture.Fitnet.dll"] \ No newline at end of file diff --git a/Chapter-2-modules-separation/Src/Fitnet.AppHost/Fitnet.AppHost.csproj b/Chapter-2-modules-separation/Src/Fitnet.AppHost/Fitnet.AppHost.csproj new file mode 100644 index 00000000..80427197 --- /dev/null +++ b/Chapter-2-modules-separation/Src/Fitnet.AppHost/Fitnet.AppHost.csproj @@ -0,0 +1,23 @@ + + + + + Exe + enable + enable + true + a3ef42d8-8e72-4dd1-a8a7-cd43e2c575e8 + + + + + + + + + + + + + + diff --git a/Chapter-2-modules-separation/Src/Fitnet.AppHost/Program.cs b/Chapter-2-modules-separation/Src/Fitnet.AppHost/Program.cs new file mode 100644 index 00000000..c616513b --- /dev/null +++ b/Chapter-2-modules-separation/Src/Fitnet.AppHost/Program.cs @@ -0,0 +1,17 @@ +using Projects; + +var builder = DistributedApplication.CreateBuilder(args); +var postgres = builder.AddPostgres("postgres") + .WithImage("postgres", "14.3") + .WithPgAdmin(); +var db = postgres.AddDatabase("fitnetsdb", "fitnet"); + +builder.AddProject("fitnet") + .WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development") + .WithEnvironment("Passes__ConnectionStrings__Primary", db) + .WithEnvironment("Contracts__ConnectionStrings__Primary", db) + .WithEnvironment("Reports__ConnectionStrings__Primary", db) + .WithEnvironment("Offers__ConnectionStrings__Primary", db) + .WaitFor(postgres); + +await builder.Build().RunAsync(); diff --git a/Chapter-2-modules-separation/Src/Fitnet.AppHost/Properties/launchSettings.json b/Chapter-2-modules-separation/Src/Fitnet.AppHost/Properties/launchSettings.json new file mode 100644 index 00000000..7fad3943 --- /dev/null +++ b/Chapter-2-modules-separation/Src/Fitnet.AppHost/Properties/launchSettings.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:17106;http://localhost:15108", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21130", + "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22190" + } + } + } +} diff --git a/Chapter-2-modules-separation/Src/Fitnet.AppHost/appsettings.json b/Chapter-2-modules-separation/Src/Fitnet.AppHost/appsettings.json new file mode 100644 index 00000000..31c092aa --- /dev/null +++ b/Chapter-2-modules-separation/Src/Fitnet.AppHost/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Aspire.Hosting.Dcp": "Warning" + } + } +} diff --git a/Chapter-2-modules-separation/Src/Fitnet.slnx b/Chapter-2-modules-separation/Src/Fitnet.slnx index d152a3c9..322b8d88 100644 --- a/Chapter-2-modules-separation/Src/Fitnet.slnx +++ b/Chapter-2-modules-separation/Src/Fitnet.slnx @@ -42,5 +42,6 @@ + \ No newline at end of file diff --git a/Chapter-2-modules-separation/Src/Fitnet/.dockerignore b/Chapter-2-modules-separation/Src/Fitnet/.dockerignore deleted file mode 100644 index cd967fc3..00000000 --- a/Chapter-2-modules-separation/Src/Fitnet/.dockerignore +++ /dev/null @@ -1,25 +0,0 @@ -**/.dockerignore -**/.env -**/.git -**/.gitignore -**/.project -**/.settings -**/.toolstarget -**/.vs -**/.vscode -**/.idea -**/*.*proj.user -**/*.dbmdl -**/*.jfm -**/azds.yaml -**/bin -**/charts -**/docker-compose* -**/Dockerfile* -**/node_modules -**/npm-debug.log -**/obj -**/secrets.dev.yaml -**/values.dev.yaml -LICENSE -README.md \ No newline at end of file diff --git a/Chapter-2-modules-separation/Src/Offers/Fitnet.Offers.DataAccess/Database/Migrations/20230503180337_CreateOfferTable.cs b/Chapter-2-modules-separation/Src/Offers/Fitnet.Offers.DataAccess/Database/Migrations/20230503180337_CreateOfferTable.cs index d295823d..73e7f712 100644 --- a/Chapter-2-modules-separation/Src/Offers/Fitnet.Offers.DataAccess/Database/Migrations/20230503180337_CreateOfferTable.cs +++ b/Chapter-2-modules-separation/Src/Offers/Fitnet.Offers.DataAccess/Database/Migrations/20230503180337_CreateOfferTable.cs @@ -1,7 +1,7 @@ #nullable disable namespace SuperSimpleArchitecture.Fitnet.Migrations.OffersPersistenceMigrations; -using System; + using System.Diagnostics.CodeAnalysis; using Microsoft.EntityFrameworkCore.Migrations; diff --git a/Chapter-2-modules-separation/Src/Passes/Fitnet.Passes.DataAccess/Database/Migrations/20230503180338_CreatePassesTable.cs b/Chapter-2-modules-separation/Src/Passes/Fitnet.Passes.DataAccess/Database/Migrations/20230503180338_CreatePassesTable.cs index 2f854018..2facfb9a 100644 --- a/Chapter-2-modules-separation/Src/Passes/Fitnet.Passes.DataAccess/Database/Migrations/20230503180338_CreatePassesTable.cs +++ b/Chapter-2-modules-separation/Src/Passes/Fitnet.Passes.DataAccess/Database/Migrations/20230503180338_CreatePassesTable.cs @@ -1,7 +1,7 @@ #nullable disable namespace EvolutionaryArchitecture.Fitnet.Passes.DataAccess.Database; -using System; + using Microsoft.EntityFrameworkCore.Migrations; [ExcludeFromCodeCoverage] diff --git a/Chapter-2-modules-separation/Src/docker-compose.yml b/Chapter-2-modules-separation/Src/docker-compose.yml deleted file mode 100644 index 170f04ef..00000000 --- a/Chapter-2-modules-separation/Src/docker-compose.yml +++ /dev/null @@ -1,30 +0,0 @@ -version: '3.9' - -services: - fitnet: - environment: - - ASPNETCORE_ENVIRONMENT=Development - - ASPNETCORE_URLS=http://+:80 - - Passes__ConnectionStrings__Primary=Host=postgres;Database=fitnet;Username=postgres;Password=mysecretpassword - - Contracts__ConnectionStrings__Primary=Host=postgres;Database=fitnet;Username=postgres;Password=mysecretpassword - - Reports__ConnectionStrings__Primary=Host=postgres;Database=fitnet;Username=postgres;Password=mysecretpassword - - Offers__ConnectionStrings__Primary=Host=postgres;Database=fitnet;Username=postgres;Password=mysecretpassword - build: . - ports: - - "8080:80" - depends_on: - postgres: - condition: service_healthy - - postgres: - image: postgres:14.3 - container_name: postgres - ports: - - 5432:5432 - environment: - - POSTGRES_PASSWORD=mysecretpassword - healthcheck: - test: [ "CMD-SHELL", "pg_isready -U postgres" ] - interval: 10s - timeout: 5s - retries: 5