Skip to content

Commit d2d0a3e

Browse files
committed
feat: refatorando baseado em testes
1 parent daafd6f commit d2d0a3e

File tree

68 files changed

+2335
-1137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2335
-1137
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
src/DEPLOY.Cachorro.Api.Tests/coveragereport/
88
src/DEPLOY.Cachorro.Api.Tests/coveragereport/*
99
src/coverage.xml
10+
coverage.xml
11+
.sonarqube
1012

1113
# User-specific files
1214
*.rsuser

.vscode/launch.json

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
{
2-
"version": "0.2.0",
3-
"configurations": [
4-
{
5-
// Use IntelliSense to find out which attributes exist for C# debugging
6-
// Use hover for the description of the existing attributes
7-
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
8-
"name": ".NET Core Launch (web)",
9-
"type": "coreclr",
10-
"request": "launch",
11-
"preLaunchTask": "build",
12-
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/src/DEPLOY.Cachorro.Api/bin/Debug/net7.0/DEPLOY.Cachorro.Api.dll",
14-
"args": [],
15-
"cwd": "${workspaceFolder}/src/DEPLOY.Cachorro.Api",
16-
"stopAtEntry": false,
17-
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
18-
"serverReadyAction": {
19-
"action": "openExternally",
20-
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
21-
},
22-
"env": {
23-
"ASPNETCORE_ENVIRONMENT": "Development"
24-
},
25-
"sourceFileMap": {
26-
"/Views": "${workspaceFolder}/Views"
27-
}
28-
},
29-
{
30-
"name": ".NET Core Attach",
31-
"type": "coreclr",
32-
"request": "attach"
33-
}
34-
]
35-
}
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
// Use IntelliSense to find out which attributes exist for C# debugging
6+
// Use hover for the description of the existing attributes
7+
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
8+
"name": ".NET Core Launch (web)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/src/DEPLOY.Cachorro.Api/bin/Debug/net8.0/DEPLOY.Cachorro.Api.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/src/DEPLOY.Cachorro.Api",
16+
"stopAtEntry": false,
17+
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
18+
"serverReadyAction": {
19+
"action": "openExternally",
20+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
21+
},
22+
"env": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
},
25+
"sourceFileMap": {
26+
"/Views": "${workspaceFolder}/Views"
27+
}
28+
},
29+
{
30+
"name": ".NET Core Attach",
31+
"type": "coreclr",
32+
"request": "attach"
33+
}
34+
]
35+
}

CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Para todos os arquivos C#
2+
*.cs @felipementel

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ reportgenerator -reports:..\TestResults\DotnetCoverageCollect\**\coverage.cobert
124124

125125
1.2 A partir da pasta src execute o comando:
126126

127+
# Ambiente Local
128+
129+
## SonarQube
130+
131+
1. Comandos para submeter o código ao sonarqube do Container
132+
133+
dotnet sonarscanner begin /k:"CachorroAPI" /d:sonar.host.url="http://localhost:9044" /d:sonar.token="xxxxx" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.exclusions="**/Migrations/**"
134+
135+
dotnet restore .\src\DEPLOY.Cachorro.Api\DEPLOY.Cachorro.Api.csproj
136+
137+
dotnet build .\src\DEPLOY.Cachorro.Api\DEPLOY.Cachorro.Api.csproj --no-incremental
138+
139+
dotnet-coverage collect 'dotnet test ./src/' -f xml -o 'coverage.xml'
140+
141+
dotnet-sonarscanner end /d:sonar.token="xxxxx"
142+
127143
---
128144

129145
# EntityFramework Commands
@@ -144,8 +160,6 @@ dotnet ef migrations add InitDatabaseAPI -s DEPLOY.Cachorro.Api -p DEPLOY.Cachor
144160
145161
dotnet ef database update InitDatabaseAPI --startup-project DEPLOY.Cachorro.Api --project DEPLOY.Cachorro.Infra.Repository --context DEPLOY.Cachorro.Infra.Repository.CachorroDbContext --verbose
146162
147-
148-
149163
```
150164

151165
Connection String

docker/docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# docker-compose -f ../docker/docker-compose.yml up -d --build
33
# docker-compose -f ../docker/docker-compose.yml down --remove-orphans
44

5-
version: "3.8"
5+
version: '3.8'
66
services:
77
# cachorro.api:
88
# hostname: cachorro-api
@@ -44,7 +44,7 @@ services:
4444
- 1433:1433
4545

4646
sonarqube:
47-
image: sonarqube:10.3.0-community
47+
image: sonarqube:10.4.1-community
4848
hostname: sonar-canal-deploy
4949
container_name: sonar-canal-deploy
5050
restart: always

src/DEPLOY.Cachorro.Api/Controllers/AppConfigurationController.cs

-45
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.Reflection;
4+
5+
namespace DEPLOY.Cachorro.Api.Controllers
6+
{
7+
[ExcludeFromCodeCoverage]
8+
[ApiController]
9+
[Route("api/[controller]")]
10+
public class PingController : ControllerBase
11+
{
12+
[HttpGet]
13+
public IActionResult GetAsync()
14+
{
15+
return Ok(Assembly.GetExecutingAssembly().GetName().Version);
16+
}
17+
}
18+
}

src/DEPLOY.Cachorro.Api/Controllers/TestsKeyVaultController.cs renamed to src/DEPLOY.Cachorro.Api/Controllers/TestsResourcesController.cs

+39-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
1-
using Asp.Versioning;
2-
using Azure.Core;
1+
using Azure.Core;
32
using Azure.Identity;
43
using Azure.Security.KeyVault.Secrets;
4+
using DEPLOY.Cachorro.Api.Configs;
55
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Options;
7+
using Microsoft.FeatureManagement;
68
using System.Diagnostics.CodeAnalysis;
79

810
namespace DEPLOY.Cachorro.Api.Controllers
911
{
1012
[ExcludeFromCodeCoverage]
13+
[ApiExplorerSettings(IgnoreApi = true)]
1114
[ApiController]
12-
[ApiVersion("1.0")]
1315
[Route("api/[controller]")]
14-
public class TestsKeyVaultController : ControllerBase
16+
public class TestsResourcesController : ControllerBase
1517
{
1618
private readonly SecretClient _secretClient;
19+
private readonly Settings _settings;
20+
private readonly IFeatureManager _featureManager;
1721

18-
private readonly IConfiguration _configuration;
19-
20-
public TestsKeyVaultController(
21-
SecretClient secretClient,
22-
IConfiguration configuration)
23-
{
24-
_secretClient = secretClient;
25-
_configuration = configuration;
22+
private readonly IConfiguration _configuration;
23+
24+
public TestsResourcesController(
25+
SecretClient secretClient,
26+
IConfiguration configuration,
27+
IOptions<Settings> settings,
28+
IFeatureManager featureManager)
29+
{
30+
_secretClient = secretClient;
31+
_configuration = configuration;
32+
_settings = settings.Value;
33+
_featureManager = featureManager;
2634
}
2735

28-
[HttpGet("{key}")]
36+
[HttpGet("keyvault/withoptions/{key}")]
2937
public async Task<IActionResult> GetAsync(string key)
3038
{
3139
SecretClientOptions options = new SecretClientOptions()
@@ -51,7 +59,7 @@ public async Task<IActionResult> GetAsync(string key)
5159
return Ok(secretValue);
5260
}
5361

54-
[HttpGet("test2/{key}")]
62+
[HttpGet("keyvault/{key}")]
5563
public async Task<IActionResult> GetTest2Async(string key)
5664
{
5765
KeyVaultSecret secret = await _secretClient.GetSecretAsync(name: key);
@@ -60,5 +68,22 @@ public async Task<IActionResult> GetTest2Async(string key)
6068

6169
return Ok(secretValue);
6270
}
71+
72+
[HttpGet("featureflag")]
73+
public IActionResult GetAsync()
74+
{
75+
return Ok(_settings.ValorDaMensagem);
76+
}
77+
78+
[HttpGet("featureflag/{featureflag}")]
79+
public async Task<IActionResult> Get2FeatureFlagAsync(string featureflag)
80+
{
81+
var IsEnable = await _featureManager.IsEnabledAsync(featureflag);
82+
83+
if (IsEnable)
84+
return Ok("Sistema no ar.");
85+
else
86+
return BadRequest("Sistema fora do ar");
87+
}
6388
}
6489
}

src/DEPLOY.Cachorro.Api/Controllers/v1/AdocoesController.cs

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Asp.Versioning;
2-
using DEPLOY.Cachorro.Application.Dtos;
32
using DEPLOY.Cachorro.Application.Interfaces.Services;
3+
using DEPLOY.Cachorro.Domain.Aggregates.Cachorro.Interfaces.Repositories;
44
using Microsoft.AspNetCore.Authorization;
55
using Microsoft.AspNetCore.Mvc;
66
using Swashbuckle.AspNetCore.Annotations;
@@ -15,7 +15,8 @@ public class AdocoesController : ControllerBase
1515
{
1616
private readonly IAdocaoAppService _adocaoAppService;
1717

18-
public AdocoesController(IAdocaoAppService adocaoAppService)
18+
public AdocoesController(
19+
IAdocaoAppService adocaoAppService)
1920
{
2021
_adocaoAppService = adocaoAppService;
2122
}
@@ -25,15 +26,47 @@ public AdocoesController(IAdocaoAppService adocaoAppService)
2526
[ProducesResponseType(StatusCodes.Status201Created)]
2627
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
2728
[SwaggerOperation(
28-
Summary = "Adotar um cachorro Cachorro",
29+
Summary = "Adotar um Cachorro",
2930
Tags = new[] { "Adocoes" },
3031
Description = "Operação para um tutor adotar um cachorro")]
3132
public async Task<IActionResult> AdotarAsync(
3233
[FromRoute] Guid cachorroid,
3334
[FromRoute] long tutorid,
3435
CancellationToken cancellationToken = default)
3536
{
36-
await _adocaoAppService.AdotarAsync(cachorroid, tutorid, cancellationToken);
37+
var item = await _adocaoAppService.AdotarAsync(
38+
cachorroid,
39+
tutorid,
40+
cancellationToken);
41+
42+
if (item?.Count() > 0)
43+
{
44+
return UnprocessableEntity(item);
45+
}
46+
47+
return Ok();
48+
}
49+
50+
[HttpPost("cachorro/{cachorroid}")]
51+
[Produces("application/json")]
52+
[ProducesResponseType(StatusCodes.Status201Created)]
53+
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
54+
[SwaggerOperation(
55+
Summary = "Devolver um cachorro que estava adotado",
56+
Tags = new[] { "Adocoes" },
57+
Description = "Operação para um tutor devolver um cachorro")]
58+
public async Task<IActionResult> DevolverAsync(
59+
[FromRoute] Guid cachorroid,
60+
CancellationToken cancellationToken = default)
61+
{
62+
var item = await _adocaoAppService.DevolverAdocaoAsync(
63+
cachorroid,
64+
cancellationToken);
65+
66+
if (item?.Count() > 0)
67+
{
68+
return UnprocessableEntity(item);
69+
}
3770

3871
return Ok();
3972
}

0 commit comments

Comments
 (0)