Skip to content

Commit 6a13113

Browse files
authored
Merge pull request #3 from tglima/v0.3
Release v0.3
2 parents 77a5f11 + e3a1c39 commit 6a13113

40 files changed

+797
-178
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Verify pull request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- v0.3
10+
env:
11+
DOTNET_VERSION: 6
12+
COVERAGE_RESULT: 0
13+
14+
jobs:
15+
build_and_test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up .NET Core
25+
run: |
26+
echo "##vso[task.setvariable variable=dotnet_path;isoutput=true]$(DOTNET_VERSION)"
27+
echo "##vso[task.setvariable variable=dotnet_sdk_path;isoutput=true]$(DOTNET_VERSION)"
28+
echo "##vso[task.setvariable variable=dotnet_pack_path;isoutput=true]$(DOTNET_VERSION)"
29+
dotnet --version
30+
31+
- name: Install dependencies
32+
run: |
33+
dotnet restore
34+
35+
- name: Run tests
36+
run: |
37+
dotnet test /p:CollectCoverage=true /p:CoverletOutput=../ /p:CoverletOutputFormat=cobertura
38+
if [ $? -eq 0 ]; then
39+
echo "Testes bem-sucedidos!"
40+
else
41+
echo "Testes falharam!"
42+
exit 1
43+
fi
44+
45+
- name: Get coverage %
46+
run: |
47+
coverage=$(grep -m 1 -oP '(?<=line-rate=")[^"]+' coverage.cobertura.xml)
48+
echo "Cobertura de código provisória: $coverage%"
49+
LC_NUMERIC="C"
50+
coverage=$(echo "$coverage * 100" | bc)
51+
coverage=$(printf "%.2f" $coverage)
52+
echo "Cobertura de código final: $coverage%"
53+
echo "COVERAGE_RESULT=$coverage" >> $GITHUB_ENV
54+
55+
- name: Check code coverage
56+
run: |
57+
LC_NUMERIC="C"
58+
coverage=${{ env.COVERAGE_RESULT }}
59+
# Check if coverage is at least 70%
60+
if (( $(echo "$coverage >= 70" | bc -l) )); then
61+
echo "Cobertura de código OK: $coverage%."
62+
else
63+
echo "Cobertura de código insuficiente: $coverage%."
64+
exit 1
65+
fi

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,8 @@ bin
6868
x64/
6969
x86/
7070
[Ll]og/
71-
[Ll]ogs/
71+
[Ll]ogs/
72+
73+
# Report Tests
74+
CoverageReport
75+
coverage.cobertura.xml

.vscode/launch.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"type": "coreclr",
77
"request": "launch",
88
"preLaunchTask": "build",
9-
"justMyCode": false,
10-
"program": "${workspaceFolder}/bin/Debug/net6.0/webapi.dll",
9+
"justMyCode": true,
10+
"program": "${workspaceFolder}/WebApi/bin/Debug/net6.0/WebApi.dll",
1111
"args": [],
12-
"cwd": "${workspaceFolder}",
12+
"cwd": "${workspaceFolder}/WebApi",
1313
"stopAtEntry": false,
1414
"serverReadyAction": {
1515
"action": "openExternally",
@@ -19,8 +19,11 @@
1919
"ASPNETCORE_ENVIRONMENT": "Development",
2020
"API_KEY": "77be91d8-4bb1ba8e27a9"
2121
},
22-
"sourceFileMap": {
23-
"/Views": "${workspaceFolder}/Views"
22+
"logging": {
23+
"consoleUsageMessage": false,
24+
"moduleLoad": false,
25+
"exception": true,
26+
"programOutput": true
2427
}
2528
}
2629
]

.vscode/tasks.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,37 @@
2424
"/consoleloggerparameters:NoSummary;ForceNoAlign"
2525
],
2626
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "release",
30+
"dependsOrder": "sequence",
31+
"dependsOn": "prebuild",
32+
"command": "dotnet",
33+
"type": "process",
34+
"args": [
35+
"publish",
36+
"-c",
37+
"Release",
38+
"${workspaceFolder}/SlnRestapiDotnetCore6.sln"
39+
],
40+
"problemMatcher": "$msCompile"
41+
},
42+
{
43+
"label": "clean",
44+
"type": "dotnet",
45+
"task": "clean",
46+
"problemMatcher": [
47+
"$msCompile"
48+
]
49+
},
50+
{
51+
"label": "Gerar relatório de cobertura",
52+
"type": "shell",
53+
"command": "dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=${workspaceFolder}/WebApi/CoverageReport/coverage.xml && reportgenerator -reports:${workspaceFolder}/WebApi.Tests/CoverageReport/coverage.xml -targetdir:${workspaceFolder}/WebApi.Tests/CoverageReport -reporttypes:HTML --force",
54+
"group": {
55+
"kind": "build",
56+
"isDefault": true
57+
}
2758
}
2859
]
2960
}

Controllers/HealthCheckController.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

Program.cs

Lines changed: 0 additions & 118 deletions
This file was deleted.

SlnRestapiDotnetCore6.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.5.002.0
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "webapi", "webapi.csproj", "{E7EE6396-AA31-44EF-A898-1587612BA3C9}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "webapi", "WebApi\WebApi.csproj", "{E7EE6396-AA31-44EF-A898-1587612BA3C9}"
7+
EndProject
8+
Project("{b0b3be86-5b3b-47b8-971d-896f1268e12b}") = "webapi.tests", "WebApi.Tests\WebApi.Tests.csproj", "{2386b57e-452c-41df-89d5-02ea2ecf7945}"
79
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
1517
{E7EE6396-AA31-44EF-A898-1587612BA3C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{E7EE6396-AA31-44EF-A898-1587612BA3C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{E7EE6396-AA31-44EF-A898-1587612BA3C9}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{2386b57e-452c-41df-89d5-02ea2ecf7945}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{2386b57e-452c-41df-89d5-02ea2ecf7945}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{2386b57e-452c-41df-89d5-02ea2ecf7945}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{2386b57e-452c-41df-89d5-02ea2ecf7945}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# TODO
22

33
- v0.3
4-
[ ] Implementar testes
5-
[ ] Criar endpoints /products
6-
[ ] Implementar GitHub actions para testes
4+
[X] Implementar testes
5+
[X] Criar endpoints /products
6+
[X] Implementar GitHub actions para testes
77

88
- v0.2
99
[X] Implementar middleware
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using WebApi.Helpers;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.Mvc.Testing;
4+
5+
6+
namespace WebApi.Tests.Factories
7+
{
8+
public class WebApiFactory : WebApplicationFactory<Program>
9+
{
10+
11+
public string[] ApiKeyArray;
12+
public readonly string InvalidApiKey = AppHelper.GenerateNuGuid();
13+
14+
public WebApiFactory()
15+
{
16+
var apiKeys = "testing;development";
17+
Environment.SetEnvironmentVariable(Constant.API_KEY, apiKeys);
18+
ApiKeyArray = apiKeys.Split(';');
19+
}
20+
21+
22+
protected override void ConfigureWebHost(IWebHostBuilder builder)
23+
{
24+
builder.UseEnvironment("Test");
25+
builder.ConfigureServices(services => { });
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)