Performed on pre-commit
using Husky.Net.
The linting of the codebase is done using dotnet format
which is included within the dotnet SDK, from version 6.0
.
Note: for new repositories, as dotnet format will only run against changed files, an 'Initial commit' needs to be present to allow Husky to determine which files are staged.
Structured logging using Serilog.
Example configuration in appsettings.json
:
"Serilog": {
"Using": ["Serilog.Sinks.Console"],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Error",
"System": "Warning"
}
},
"WriteTo": [
{ "Name": "Console" }
],
"Enrich": ["FromLogContext"]
}
Header:
{
"alg": "RS256",
"typ": "JWT",
"kid": "aa9a6015-0f47-436a-a99c-e8afb9810bde"
}
Payload:
{
"iss": "http://localhost:8081/identity/",
"iat": 1621262043,
"exp": 1905258846,
"aud": "mydomain-api",
"sub": "[email protected]",
"name": "Johnny",
"last_name": "Rocket",
"email": "[email protected]",
"scope": ["mydomain-api:write"]
}
Note: Expiry is set to 2031-01-01
.
Signature (header):
{
"kty": "RSA",
"e": "AQAB",
"kid": "aa9a6015-0f47-436a-a99c-e8afb9810bde",
"alg": "RS256",
"n": "h5_3CfgOS_aiTEigdv3LtLIexDrGWFVdnLLYOGOoeLur-gFcN65Ecff2Rt261GAUOTJYCcr0GPhz3wRcBH0r2-aJOYNfgzupo8iL-tjngGb_U8pFeZqSXGoeP4mG8FcN4wnKSoeMYMeLoUZhli3YE1RtjBb17ckUEJaX7q9PzJvubQZnqChWFjxkAf8Fa8ZuzBVqP_2_hm-09Ly7DTRl994DqLC3cchvtFC5wFaq_wABg43cvQn9ipmfx-oWg3uOTmlQjJmnrLbFkTnrSBLDMZCa6IpscphEbatwhAtrxTCfJf0L_kDpuj6scdeIUSj62vdsi_wDWXGz5cQxLLMQyQ"
}
Signature (payload):
{
"p": "0iwVIDn_VTBbstpJOXUDmK7uIDPQ8V6l-UcadgFp1NxewfG-hLFX0BGAUvTA114vY-6PiepkPEBsetJRG6gj3b7yZj1M-iWaJGccne59sOLScYkeicTn0MhgglM0DHDU0DRR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Qz-egjP6MhQCWsI0a9GHr2L_A9p4h2KBzr2oqVziliZepIcc3HApAssP007d-usufOZ58zL3MFyqPDz2onQoxXyE",
"n": "h5_3CfgOS_aiTEigdv3LtLIexDrGWFVdnLLYOGOoeLur-gFcN65Ecff2Rt261GAUOTJYCcr0GPhz3wRcBH0r2-aJOYNfgzupo8iL-tjngGb_U8pFeZqSXGoeP4mG8FcN4wnKSoeMYMeLoUZhli3YE1RtjBb17ckUEJaX7q9PzJvubQZnqChWFjxkAf8Fa8ZuzBVqP_2_hm-09Ly7DTRl994DqLC3cchvtFC5wFaq_wABg43cvQn9ipmfx-oWg3uOTmlQjJmnrLbFkTnrSBLDMZCa6IpscphEbatwhAtrxTCfJf0L_kDpuj6scdeIUSj62vdsi_wDWXGz5cQxLLMQyQ"
}
You can verify the JWT here https://jwt.io/#debugger.
Start environment:
.\environment.ps1 start
Stop environment:
.\environment.ps1 stop
Optional parameters:
-env_file "{environment}.env"
- Override the environment variable file.-detach $true|$false
- Run containers in the background. Default is$true
.
Navigate to http://localhost:8081/__admin/mappings to display mock mappings.
Health checks can be extended using https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks
Note: requires local test environment.
dotnet run --project ./src/api/MyDomain.Api
- Swagger - https://localhost:7217/swagger/index.html
- Health checks - https://localhost:7217/healthchecks-ui
docker-compose up --build
You can add custom certificates by setting the CERT_FILE_PATH
- default is .ca_certs
- and CERT_FILE
arguments via environment variables.
Note: the certificate needs to be available in the docker build context.
$env:CERT_FILE="my-certificate.crt";docker-compose up --build
- Swagger - http://localhost:1001/swagger/index.html
- Health checks - http://localhost:1001/healthchecks-ui
dotnet test ./src
docker-compose -f docker-compose.test.yml up --build
You can add custom certificates by setting the CERT_FILE_PATH
- default is .ca_certs
- and CERT_FILE
arguments via environment variables.
Note: the certificate needs to be available in the docker build context.
$env:CERT_FILE="my-certificate.crt";docker-compose -f docker-compose.test.yml up --build
https://schemathesis.readthedocs.io/en/stable/index.html
docker run -it -v ${pwd}:/api -v ${pwd}/testresults:/testresults -w /api schemathesis/schemathesis:stable run https://host.docker.internal:7217/swagger/v1/swagger.yaml --request-tls-verify false --checks all --stateful links -H "Authorization: Bearer <AUTHORIZATION_TOKEN>" > testresults/report.txt
Publish provider contract using the results from schemathesis
:
docker run --rm -v ${pwd}:/api -w /api pactfoundation/pact-cli pactflow publish-provider-contract https://host.docker.internal:7217/swagger/v1/swagger.yaml --broker-base-url <PACT_BROKER_BASE_URL> --broker-token <PACT_BROKER_TOKEN> --provider "my-domain-api" --provider-app-version 1.0.0 --branch <BRANCH> --content-type application/yaml --verification-exit-code=0 --verification-results testresults/report.txt --verification-results-content-type text/plain --verifier schemathesis
Check deployment status using can-i-deploy
:
docker run --rm -v ${pwd}:/api -w /api pactfoundation/pact-cli broker can-i-deploy --pacticipant "my-domain-api" --broker-base-url <PACT_BROKER_BASE_URL> --broker-token <PACT_BROKER_TOKEN> --version 1.0.0 --to-environment test --retry-while-unknown 0 --retry-interval 10
Requires the following secrets:
AUTHORIZATION_TOKEN
- test authorization tokenSCHEMATHESIS_TOKEN
- schemathesis tokenPACT_BROKER_BASE_URL
- set the pact broker URLPACT_BROKER_TOKEN
- set the Pact API Key
Managed using Codecov.
To set up the repository you need to create a token CODECOV_TOKEN
and enable app integration - see https://docs.codecov.com/docs/github-2-getting-a-codecov-account-and-uploading-coverage.
Uses append-to-gist action to update tests.svg
, requires:
- Creating new gist with the
gistURL
set in the formhttps://gist.githubusercontent.com/{user}/{id}
- Personal access toke (PAT) with
gist
permission only - GitHub Actions secret
GIST_TOKEN
using above PAT