REST API for a quiz application that allows users to practice programming knowledge through multiple-choice questions on various topics (HTML, CSS, JavaScript, Python, PHP, etc.).
| Layer | Technology |
|---|---|
| Framework | .NET 9 / ASP.NET Core Web API |
| Database | SQL Server + Entity Framework Core |
| Authentication | ASP.NET Core Identity + JWT Bearer |
| Validation | FluentValidation |
| Documentation | Swagger / OpenAPI |
| Testing | xUnit + FsCheck (property-based testing) |
- .NET 9 SDK
- SQL Server (LocalDB, Express, or Developer Edition)
- EF Core CLI Tools
dotnet tool install --global dotnet-efEdit src/QuizApp/appsettings.json with your SQL Server connection string:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=QuizAppDb;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}JWT settings are in appsettings.json. For production, change the secret key:
{
"Jwt": {
"Key": "YourSecretKeyHere_AtLeast32Characters!",
"Issuer": "QuizApp",
"Audience": "QuizApp",
"ExpirationInMinutes": 60
}
}The Angular frontend is allowed by default at http://localhost:4200:
{
"Cors": {
"FrontendUrl": "http://localhost:4200"
}
}From the backend/src/QuizApp directory:
dotnet ef migrations add InitialCreate
dotnet ef database updatedotnet run --project src/QuizAppThe API will be available at https://localhost:7013 (or http://localhost:5276).
Open in your browser: https://localhost:7013/swagger
From the backend directory:
dotnet testTests include:
- Unit tests — Controllers, Services, Validators
- Property-based tests (FsCheck) — 13 formal correctness properties
backend/
├── QuizApp.sln
├── src/
│ └── QuizApp/
│ ├── Controllers/ # API Controllers (Auth, Quiz, Session, Dashboard)
│ ├── Data/ # DbContext and EF Core configurations
│ ├── DTOs/ # Data Transfer Objects
│ ├── Exceptions/ # Custom exceptions (404, 409, 401, 400)
│ ├── Middleware/ # Global Exception Handler
│ ├── Models/ # Domain entities
│ ├── Services/ # Service layer (business logic)
│ ├── Validators/ # FluentValidation validators
│ └── Program.cs # Configuration and startup
└── tests/
└── QuizApp.Tests/
├── Controllers/ # Controller tests
├── Middleware/ # Middleware tests
├── PropertyTests/ # Property-based tests (FsCheck)
├── Services/ # Service tests
└── Validators/ # Validation tests
| Method | Route | Description | Auth Required |
|---|---|---|---|
| POST | /api/auth/register |
Register a new user | No |
| POST | /api/auth/login |
Authenticate user | No |
| Method | Route | Description | Auth Required |
|---|---|---|---|
| GET | /api/quizzes |
List all quizzes | No |
| GET | /api/quizzes/{id} |
Get quiz details | No |
| POST | /api/quizzes |
Create a quiz | Yes |
| PUT | /api/quizzes/{id} |
Update a quiz | Yes |
| DELETE | /api/quizzes/{id} |
Delete a quiz | Yes |
| Method | Route | Description | Auth Required |
|---|---|---|---|
| POST | /api/quizzes/{quizId}/sessions |
Start a session | No |
| POST | /api/sessions/{sessionId}/answers |
Submit an answer | No |
| POST | /api/sessions/{sessionId}/complete |
Complete session | No |
| GET | /api/sessions/{sessionId}/result |
Get result | No |
| Method | Route | Description | Auth Required |
|---|---|---|---|
| GET | /api/dashboard |
Get user's quiz history | Yes |
- Authentication & Registration — JWT with Identity, minimum 8-character password
- Quiz CRUD — Create, read, update, and delete quizzes (protected by authentication)
- Quiz Sessions — Start, submit answers, complete with result calculation
- Result Calculation — Correct answer count, elapsed time, pass/fail determination (≥70%)
- Guest Access — Users can take quizzes without creating an account
- Dashboard — Complete history of all attempts for authenticated users
- Validation — Each question must have exactly 4 options with exactly 1 correct
- Error Handling — Global middleware with consistent JSON error responses
- Duplicate Prevention — Cannot answer the same question twice in a session
| # | Property | Description |
|---|---|---|
| 1 | Question Structure Invariant | Every question has exactly 4 options with 1 correct |
| 4 | Answer Persistence Round-Trip | Stored answers contain the exact IDs submitted |
| 5 | Elapsed Time Calculation | Elapsed time = completedAt - startedAt |
| 6 | Correct Answer Count | Correct count = number of answers where isCorrect=true |
| 7 | Pass/Fail Threshold | Pass if and only if correctAnswers/total ≥ 0.70 |
| 8 | Quiz List Completeness | List returns all quizzes with correct question counts |
| 10 | Password Length Validation | Passwords < 8 chars rejected, ≥ 8 chars accepted |
| 11 | Dashboard Chronological Ordering | Sessions sorted by completion date descending |
| 12 | Repeat Attempt Preservation | K completions = K records on dashboard |
| 13 | Guest Session Non-Association | Guest sessions have null userId and calculable results |
This project is licensed under the MIT License.