A modern .NET 9 REST API with User CRUD operations, comprehensive unit tests, and automated Azure deployment using Bicep infrastructure as code.
- REST API: Full CRUD operations for User management
- Unit Tests: Comprehensive test coverage for all operations
- Azure Deployment: Automated deployment to Azure App Service using Bicep
- CI/CD Pipeline: GitHub Actions workflow for build, test, and deploy
- Infrastructure as Code: Bicep templates for reproducible deployments
haiku-test/
├── src/
│ └── HaikuApi/ # Main API project
│ ├── Controllers/ # REST API controllers
│ ├── Models/ # Data models
│ ├── Services/ # Business logic services
│ └── Program.cs # Application entry point
├── tests/
│ └── HaikuApi.Tests/ # Unit tests
├── infra/
│ ├── main.bicep # Bicep template for Azure resources
│ ├── parameters.dev.json # Dev environment parameters
│ └── parameters.prod.json # Prod environment parameters
├── .github/
│ └── workflows/
│ └── ci-cd.yml # GitHub Actions CI/CD pipeline
└── README.md
- .NET 9 SDK
- Azure CLI (for local deployment)
- GitHub account with repository access
- Clone the repository:
git clone https://github.com/fjordsnapper/haiku-test.git
cd haiku-test- Restore dependencies:
dotnet restore- Build the project:
dotnet build- Run the API:
cd src/HaikuApi
dotnet runThe API will be available at https://localhost:7001
dotnet test tests/HaikuApi.Tests/GET /api/users- Get all usersGET /api/users/{id}- Get user by IDPOST /api/users- Create new userPUT /api/users/{id}- Update userDELETE /api/users/{id}- Delete user
Create User:
POST /api/users
Content-Type: application/json
{
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com"
}Response:
{
"id": 1,
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com",
"createdAt": "2024-02-05T19:00:00Z",
"updatedAt": "2024-02-05T19:00:00Z"
}- Azure subscription
- GitHub secrets configured:
AZURE_CLIENT_IDAZURE_TENANT_IDAZURE_SUBSCRIPTION_IDAZURE_RESOURCE_SUFFIX
Deploy to development environment:
az deployment group create \
--resource-group haiku-api-rg-dev \
--template-file infra/main.bicep \
--parameters infra/parameters.dev.jsonDeploy to production environment:
az deployment group create \
--resource-group haiku-api-rg-prod \
--template-file infra/main.bicep \
--parameters infra/parameters.prod.jsonThe GitHub Actions workflow automatically:
- Builds the project on every push
- Runs unit tests
- Deploys to dev environment on
developbranch push - Deploys to prod environment on
masterbranch push (requires approval)
The workflow (ci-cd.yml) includes:
-
Build & Test Stage
- Restores dependencies
- Builds the project
- Runs unit tests with code coverage
- Publishes the application
-
Dev Deployment (on develop branch)
- Deploys Bicep template
- Deploys application to dev App Service
-
Prod Deployment (on master branch)
- Requires manual approval
- Deploys Bicep template
- Deploys application to prod App Service
The test suite covers:
- User creation with validation
- Retrieving users by ID
- Listing all users
- Updating user information
- Deleting users
- Timestamp management
- Error handling for invalid operations
Run tests with coverage:
dotnet test tests/HaikuApi.Tests/ /p:CollectCoverage=true- App Service Plan: B1 (1 instance)
- Location: East US
- Environment: dev
- App Service Plan: B2 (2 instances)
- Location: East US
- Environment: prod
- Create a feature branch:
git checkout -b feature/your-feature - Commit changes:
git commit -m "feat: Your feature description" - Push to branch:
git push origin feature/your-feature - Create a Pull Request
MIT