Este projeto contém uma API mínima em ASP.NET Core (.NET 8), além de projetos de teste unitário e de integração.
- Instale o .NET 8 SDK.
- Certifique-se de ter o MySQL instalado e rodando em sua máquina, pois ele é o banco configurado na aplicação.
- Configure a string de conexão na chave
ConnectionStrings:DefaultConnectiondoappsettings.json(ou via secrets do usuário). Exemplo genérico (substitua<usuario>e<senha>pelos seus dados do MySQL):"ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=MinimalApiDb;User Id=<usuario>;Password=<senha>;" }
- Configure a chave JWT na chave
Jwt:Keydoappsettings.json(ou via secrets do usuário). Para geração do token JWT é utilizado o algoritmo HS256, sendo necessário informar uma string com no mínimo 32 caracteres. Já existe uma chave de exemplo no arquivo para desenvolvimento:"Jwt": { "Key": "MySecretKeyForJWT123456789012345" }
- Certifique-se de estar na pasta raiz do projeto (onde está o arquivo
.sln) para que os comandos funcionem corretamente. - Execute o comando:
dotnet run --project MinimalApi/MinimalApi.csproj
- A aplicação irá rodar nas portas especificadas na chave
https:applicationUrldo arquivoMinimalApi/Properties/launchSettings.json:- HTTPS: https://localhost:7181
- HTTP: http://localhost:5207
- A documentação Swagger estará disponível em
/swagger(ex: https://localhost:7181/swagger).
- Os testes unitários estão em
MinimalApi.UnitTests. - Para rodar, esteja na pasta raiz do projeto:
dotnet test MinimalApi.UnitTests/MinimalApi.UnitTests.csproj
- Os testes de integração estão em
MinimalApi.IntegrationTests. - Para rodar, esteja na pasta raiz do projeto:
dotnet test MinimalApi.IntegrationTests/MinimalApi.IntegrationTests.csproj - Importante: Os testes de integração utilizam o Testcontainers para criar um banco MySQL temporário via Docker. Certifique-se de ter o Docker instalado e em execução. Isso elimina a necessidade de um banco de dados de teste manual, pois o container é criado e descartado automaticamente a cada rodada de teste, criando uma cópia do banco da aplicação para os testes.
This project contains a minimal ASP.NET Core API (.NET 8), as well as unit and integration test projects.
- Install .NET 8 SDK.
- Make sure you have MySQL installed and running on your machine, as it is the database configured for the application.
- Set the connection string in the
ConnectionStrings:DefaultConnectionkey inappsettings.json(or via user secrets). Example (replace<username>and<password>with your MySQL credentials):"ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=MinimalApiDb;User Id=<username>;Password=<password>;" }
- Set the JWT key in the
Jwt:Keykey inappsettings.json(or via user secrets). The JWT token uses the HS256 algorithm, so the key must be at least 32 characters long. A sample key is already provided for development:"Jwt": { "Key": "MySecretKeyForJWT123456789012345" }
- Make sure you are in the project root folder (where the
.slnfile is) so relative paths work correctly. - Run:
dotnet run --project MinimalApi/MinimalApi.csproj
- The application will run on the ports specified in the
https:applicationUrlkey inMinimalApi/Properties/launchSettings.json:- HTTPS: https://localhost:7181
- HTTP: http://localhost:5207
- Swagger documentation is available at
/swagger(e.g., https://localhost:7181/swagger).
- Unit tests are in
MinimalApi.UnitTests. - To run, be in the project root folder:
dotnet test MinimalApi.UnitTests/MinimalApi.UnitTests.csproj
- Integration tests are in
MinimalApi.IntegrationTests. - To run, be in the project root folder:
dotnet test MinimalApi.IntegrationTests/MinimalApi.IntegrationTests.csproj - Important: Integration tests use Testcontainers to create a temporary MySQL database via Docker. Make sure Docker is installed and running. This avoids the need for a manual test database, as the container is created and destroyed automatically for each test run, creating a copy of the application database for testing.