Skip to content

Commit

Permalink
feat: refatorando baseado em testes
Browse files Browse the repository at this point in the history
  • Loading branch information
felipementel committed Apr 8, 2024
1 parent daafd6f commit d2d0a3e
Show file tree
Hide file tree
Showing 68 changed files with 2,335 additions and 1,137 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
src/DEPLOY.Cachorro.Api.Tests/coveragereport/
src/DEPLOY.Cachorro.Api.Tests/coveragereport/*
src/coverage.xml
coverage.xml
.sonarqube

# User-specific files
*.rsuser
Expand Down
68 changes: 34 additions & 34 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/DEPLOY.Cachorro.Api/bin/Debug/net7.0/DEPLOY.Cachorro.Api.dll",
"args": [],
"cwd": "${workspaceFolder}/src/DEPLOY.Cachorro.Api",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/DEPLOY.Cachorro.Api/bin/Debug/net8.0/DEPLOY.Cachorro.Api.dll",
"args": [],
"cwd": "${workspaceFolder}/src/DEPLOY.Cachorro.Api",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Para todos os arquivos C#
*.cs @felipementel
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ reportgenerator -reports:..\TestResults\DotnetCoverageCollect\**\coverage.cobert

1.2 A partir da pasta src execute o comando:

# Ambiente Local

## SonarQube

1. Comandos para submeter o código ao sonarqube do Container

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/**"

dotnet restore .\src\DEPLOY.Cachorro.Api\DEPLOY.Cachorro.Api.csproj

dotnet build .\src\DEPLOY.Cachorro.Api\DEPLOY.Cachorro.Api.csproj --no-incremental

dotnet-coverage collect 'dotnet test ./src/' -f xml -o 'coverage.xml'

dotnet-sonarscanner end /d:sonar.token="xxxxx"

---

# EntityFramework Commands
Expand All @@ -144,8 +160,6 @@ dotnet ef migrations add InitDatabaseAPI -s DEPLOY.Cachorro.Api -p DEPLOY.Cachor
dotnet ef database update InitDatabaseAPI --startup-project DEPLOY.Cachorro.Api --project DEPLOY.Cachorro.Infra.Repository --context DEPLOY.Cachorro.Infra.Repository.CachorroDbContext --verbose
```

Connection String
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# docker-compose -f ../docker/docker-compose.yml up -d --build
# docker-compose -f ../docker/docker-compose.yml down --remove-orphans

version: "3.8"
version: '3.8'
services:
# cachorro.api:
# hostname: cachorro-api
Expand Down Expand Up @@ -44,7 +44,7 @@ services:
- 1433:1433

sonarqube:
image: sonarqube:10.3.0-community
image: sonarqube:10.4.1-community
hostname: sonar-canal-deploy
container_name: sonar-canal-deploy
restart: always
Expand Down
45 changes: 0 additions & 45 deletions src/DEPLOY.Cachorro.Api/Controllers/AppConfigurationController.cs

This file was deleted.

18 changes: 18 additions & 0 deletions src/DEPLOY.Cachorro.Api/Controllers/PingController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace DEPLOY.Cachorro.Api.Controllers
{
[ExcludeFromCodeCoverage]
[ApiController]
[Route("api/[controller]")]
public class PingController : ControllerBase
{
[HttpGet]
public IActionResult GetAsync()
{
return Ok(Assembly.GetExecutingAssembly().GetName().Version);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
using Asp.Versioning;
using Azure.Core;
using Azure.Core;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using DEPLOY.Cachorro.Api.Configs;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Microsoft.FeatureManagement;
using System.Diagnostics.CodeAnalysis;

namespace DEPLOY.Cachorro.Api.Controllers
{
[ExcludeFromCodeCoverage]
[ApiExplorerSettings(IgnoreApi = true)]
[ApiController]
[ApiVersion("1.0")]
[Route("api/[controller]")]
public class TestsKeyVaultController : ControllerBase
public class TestsResourcesController : ControllerBase
{
private readonly SecretClient _secretClient;
private readonly Settings _settings;
private readonly IFeatureManager _featureManager;

private readonly IConfiguration _configuration;

public TestsKeyVaultController(
SecretClient secretClient,
IConfiguration configuration)
{
_secretClient = secretClient;
_configuration = configuration;
private readonly IConfiguration _configuration;

public TestsResourcesController(
SecretClient secretClient,
IConfiguration configuration,
IOptions<Settings> settings,
IFeatureManager featureManager)
{
_secretClient = secretClient;
_configuration = configuration;
_settings = settings.Value;
_featureManager = featureManager;
}

[HttpGet("{key}")]
[HttpGet("keyvault/withoptions/{key}")]
public async Task<IActionResult> GetAsync(string key)

Check warning on line 37 in src/DEPLOY.Cachorro.Api/Controllers/TestsResourcesController.cs

View workflow job for this annotation

GitHub Actions / build-and-sonar

All 'GetAsync' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)
{
SecretClientOptions options = new SecretClientOptions()
Expand All @@ -51,7 +59,7 @@ public async Task<IActionResult> GetAsync(string key)
return Ok(secretValue);
}

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

return Ok(secretValue);
}

[HttpGet("featureflag")]
public IActionResult GetAsync()
{
return Ok(_settings.ValorDaMensagem);
}

[HttpGet("featureflag/{featureflag}")]
public async Task<IActionResult> Get2FeatureFlagAsync(string featureflag)
{
var IsEnable = await _featureManager.IsEnabledAsync(featureflag);

if (IsEnable)
return Ok("Sistema no ar.");
else
return BadRequest("Sistema fora do ar");
}
}
}
41 changes: 37 additions & 4 deletions src/DEPLOY.Cachorro.Api/Controllers/v1/AdocoesController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Asp.Versioning;
using DEPLOY.Cachorro.Application.Dtos;
using DEPLOY.Cachorro.Application.Interfaces.Services;
using DEPLOY.Cachorro.Domain.Aggregates.Cachorro.Interfaces.Repositories;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
Expand All @@ -15,7 +15,8 @@ public class AdocoesController : ControllerBase
{
private readonly IAdocaoAppService _adocaoAppService;

public AdocoesController(IAdocaoAppService adocaoAppService)
public AdocoesController(
IAdocaoAppService adocaoAppService)
{
_adocaoAppService = adocaoAppService;
}
Expand All @@ -25,15 +26,47 @@ public AdocoesController(IAdocaoAppService adocaoAppService)
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[SwaggerOperation(
Summary = "Adotar um cachorro Cachorro",
Summary = "Adotar um Cachorro",
Tags = new[] { "Adocoes" },
Description = "Operação para um tutor adotar um cachorro")]
public async Task<IActionResult> AdotarAsync(
[FromRoute] Guid cachorroid,
[FromRoute] long tutorid,
CancellationToken cancellationToken = default)
{
await _adocaoAppService.AdotarAsync(cachorroid, tutorid, cancellationToken);
var item = await _adocaoAppService.AdotarAsync(
cachorroid,
tutorid,
cancellationToken);

if (item?.Count() > 0)
{
return UnprocessableEntity(item);
}

return Ok();
}

[HttpPost("cachorro/{cachorroid}")]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[SwaggerOperation(
Summary = "Devolver um cachorro que estava adotado",
Tags = new[] { "Adocoes" },
Description = "Operação para um tutor devolver um cachorro")]
public async Task<IActionResult> DevolverAsync(
[FromRoute] Guid cachorroid,
CancellationToken cancellationToken = default)
{
var item = await _adocaoAppService.DevolverAdocaoAsync(
cachorroid,
cancellationToken);

if (item?.Count() > 0)
{
return UnprocessableEntity(item);
}

return Ok();
}
Expand Down
Loading

0 comments on commit d2d0a3e

Please sign in to comment.