Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
65625f0
test: added contact fixture
gricar Dec 19, 2024
0f9f080
integration test setup
gricar Dec 20, 2024
cba752e
contacts test
gricar Dec 20, 2024
5347d89
added database container service and tests
gricar Dec 20, 2024
b09413a
updated migrations startup project
gricar Dec 20, 2024
eec0f36
install dotnet ef
gricar Dec 20, 2024
7134c87
dotnet ef version
gricar Dec 20, 2024
49e8f54
change directory and add env
gricar Dec 20, 2024
e317eda
folder name
gricar Dec 20, 2024
8b8efb4
removed apply migration
gricar Dec 20, 2024
f4d45b9
updated test cmd
gricar Dec 20, 2024
3820e6c
skip tests - validate CI pipeline
gricar Dec 20, 2024
9f42a2e
added prometheus and serilog libs
gricar Jan 3, 2025
4940595
added API dockerfile
gricar Jan 3, 2025
6d2aa68
added docker-compose
gricar Jan 3, 2025
7e45c96
specified solution file
gricar Jan 3, 2025
3f6aefe
add list current directory step
gricar Jan 3, 2025
4336dce
fix solution file dir
gricar Jan 3, 2025
4eccffd
add migration extension
gricar Jan 7, 2025
6120bdc
renamed folder structure
gricar Jan 7, 2025
6d51c88
removed unused service
gricar Jan 7, 2025
57b9492
List current directory
gricar Jan 7, 2025
6aa8033
demo workflow
gricar Jan 7, 2025
52f0975
Merge branch 'test/application-integration' of https://github.com/gri…
gricar Jan 7, 2025
dc78f3c
reorgranize folder
gricar Jan 7, 2025
addef0e
update workflow
gricar Jan 7, 2025
2855cd2
add Integration Test Collection
gricar Jan 18, 2025
098ee6a
add contact fixture
gricar Jan 18, 2025
655ed56
add test data seeder
gricar Jan 18, 2025
40a6227
update volumes
gricar Jan 18, 2025
db9727f
add contact fixture
gricar Jan 18, 2025
cbded82
refactor create contacts handler tests
gricar Jan 18, 2025
6652474
refactor update contacts handler tests
gricar Jan 18, 2025
b168ce0
refactor: extensible methods
gricar Jan 20, 2025
4dfad53
refactor: using fixture class
gricar Jan 20, 2025
b52b490
test: add contacts by ddd handler
gricar Jan 20, 2025
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
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*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
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
7 changes: 3 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: CI Pipeline - Contacts Manager API

# Executa o pipeline em cada push ou pull request para a branch main
on:
push:
branches:
Expand All @@ -23,10 +22,10 @@ jobs:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore
run: dotnet restore ./Contact37.sln

- name: Build solution
run: dotnet build --configuration Release --no-restore
run: dotnet build ./Contact37.sln --configuration Release --no-restore

- name: Run tests
run: dotnet test --configuration Release --no-build --verbosity normal
run: dotnet test ./Contact37.sln --configuration Release --no-build --verbosity normal
15 changes: 14 additions & 1 deletion Contact37.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contacts37.API", "Contacts3
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contacts37.Domain.Tests", "Contacts37.Domain.Tests\Contacts37.Domain.Tests.csproj", "{2B82BA02-9D3F-45E6-88DC-8201CA210974}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contacts37.Application.Tests", "Contacts37.Application.Tests\Contacts37.Application.Tests.csproj", "{67F02028-C088-41AC-BA06-8D95DB8F28FB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contacts37.Application.Tests", "Contacts37.Application.Tests\Contacts37.Application.Tests.csproj", "{67F02028-C088-41AC-BA06-8D95DB8F28FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contacts37.Application.IntegrationTests", "Contacts37.Application.IntegrationTests\Contacts37.Application.IntegrationTests.csproj", "{334BA499-25A0-4C6B-B317-8592A2E4AD8F}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{2B09ABA7-B0CC-46E9-8133-945757E3EA12}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -55,6 +59,14 @@ Global
{67F02028-C088-41AC-BA06-8D95DB8F28FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67F02028-C088-41AC-BA06-8D95DB8F28FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67F02028-C088-41AC-BA06-8D95DB8F28FB}.Release|Any CPU.Build.0 = Release|Any CPU
{334BA499-25A0-4C6B-B317-8592A2E4AD8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{334BA499-25A0-4C6B-B317-8592A2E4AD8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{334BA499-25A0-4C6B-B317-8592A2E4AD8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{334BA499-25A0-4C6B-B317-8592A2E4AD8F}.Release|Any CPU.Build.0 = Release|Any CPU
{2B09ABA7-B0CC-46E9-8133-945757E3EA12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B09ABA7-B0CC-46E9-8133-945757E3EA12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B09ABA7-B0CC-46E9-8133-945757E3EA12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B09ABA7-B0CC-46E9-8133-945757E3EA12}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -69,6 +81,7 @@ Global
{F738FCAC-569A-4C0A-9E81-1B2F6901E8D3} = {52A30A57-415B-4A7C-80FA-F407E0105DAE}
{2B82BA02-9D3F-45E6-88DC-8201CA210974} = {9797DF73-8B56-4F82-84A0-3F8FD0AC3ECF}
{67F02028-C088-41AC-BA06-8D95DB8F28FB} = {9797DF73-8B56-4F82-84A0-3F8FD0AC3ECF}
{334BA499-25A0-4C6B-B317-8592A2E4AD8F} = {9797DF73-8B56-4F82-84A0-3F8FD0AC3ECF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {684A1232-DFE2-45B7-84F7-85F6C270F627}
Expand Down
9 changes: 8 additions & 1 deletion Contacts37.API/Contacts37.API.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>false</InvariantGlobalization>
<UserSecretsId>1f76d21a-9e54-47e7-8c24-2a213f107bb0</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,7 +17,11 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.6" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

Expand Down
26 changes: 26 additions & 0 deletions Contacts37.API/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Contacts37.API/Contacts37.API.csproj", "Contacts37.API/"]
COPY ["Contact37.Persistence/Contacts37.Persistence.csproj", "Contact37.Persistence/"]
COPY ["Contacts37.Application/Contacts37.Application.csproj", "Contacts37.Application/"]
COPY ["Contacts37.Domain/Contacts37.Domain.csproj", "Contacts37.Domain/"]
RUN dotnet restore "./Contacts37.API/./Contacts37.API.csproj"
COPY . .
WORKDIR "/src/Contacts37.API"
RUN dotnet build "./Contacts37.API.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Contacts37.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Contacts37.API.dll"]
17 changes: 17 additions & 0 deletions Contacts37.API/Extensions/MigrationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Contacts37.Persistence;
using Microsoft.EntityFrameworkCore;

namespace Contacts37.API.Extensions
{
public static class MigrationExtensions
{
public static void ApplyMigrations(this IApplicationBuilder app)
{
using IServiceScope scope = app.ApplicationServices.CreateScope();

var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();

dbContext.Database.Migrate();
}
}
}
14 changes: 14 additions & 0 deletions Contacts37.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
using Contacts37.API.Extensions;
using Contacts37.API.Middlewares;
using Contacts37.Application.DependencyInjection;
using Contacts37.Persistence.DependencyInjection;
using Prometheus;
using Serilog;

var builder = WebApplication.CreateBuilder(args);

builder.Services
.ConfigurePersistenceServices(builder.Configuration)
.ConfigureApplicationServices();

builder.Host.UseSerilog((context, config) =>
config.ReadFrom.Configuration(context.Configuration)
);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
Expand All @@ -19,6 +26,7 @@
{
app.UseSwagger();
app.UseSwaggerUI();
app.ApplyMigrations();
}

app.UseMiddleware<ErrorHandlerMiddleware>();
Expand All @@ -27,6 +35,12 @@

app.UseAuthorization();

app.UseMetricServer();

app.UseHttpMetrics();

app.MapControllers();

app.Run();

public partial class Program { }
45 changes: 28 additions & 17 deletions Contacts37.API/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:38899",
"sslPort": 44371
}
},
{
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5070",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5070"
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7202;http://localhost:5070",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7202;http://localhost:5070"
},
"IIS Express": {
"commandName": "IISExpress",
Expand All @@ -36,6 +27,26 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:38899",
"sslPort": 44371
}
}
}
}
25 changes: 18 additions & 7 deletions Contacts37.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Contact37ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=ContactManager37Db;Trusted_Connection=True;MultipleActiveResultSets=true"
"Contact37ConnectionString": "Server=mssql;Database=ContactManager37Db;User Id=sa;Password=P@ssw0rd1;TrustServerCertificate=yes"
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "Seq",
"Args": { "serverUrl": "http://seq-logs" }
}
],
"Enrich": [ "FromLogContext", "WithMachineName" ],
"Properties": {
"ApplicationName": "Contacts Manager API"
}
}
}
Loading
Loading