This project is a modern .NET 9 minimal API that exposes CRUD operations for managing users. It includes validation, structured error responses via RFC 7807 ProblemDetails
, OpenAPI documentation, and integration tests built with xUnit and WebApplicationFactory
.
- .NET SDK 9.0 or later
dotnet run
The API listens on the configured ASP.NET Core URLs (defaults to http://localhost:5196
). Navigate to /swagger
for the interactive documentation.
dotnet test
The integration tests spin up the in-memory server and cover happy-path and error scenarios (empty state, creation, conflicts, deletions).
All routes are grouped under /api/users
.
Method | Route | Description |
---|---|---|
GET | /api/users |
List all users |
GET | /api/users/{id} |
Fetch a specific user |
POST | /api/users |
Create a new user |
PUT | /api/users/{id} |
Update an existing user |
DELETE | /api/users/{id} |
Delete a user |
POST /api/users
Content-Type: application/json
{
"email": "ada.lovelace@example.com",
"fullName": "Ada Lovelace"
}
PUT /api/users/{id}
Content-Type: application/json
{
"email": "ada.lovelace@example.com",
"fullName": "Augusta Ada King"
}
- Validation problems return
400
with aValidationProblemDetails
payload. - Missing entities return
404
with aProblemDetails
body that includes the requested identifier. - Email conflicts return
409
with aProblemDetails
payload describing the conflict.
Domain/ // User domain model
Contracts/ // Request/response DTOs + validation helpers
Infrastructure/ // In-memory repository implementation
csharp-user-management.Tests/
CustomWebApplicationFactory.cs
UnitTest1.cs // Integration tests
Program.cs // Minimal API setup and endpoints
- Replace the in-memory repository with a persistent data store (EF Core, Dapper, etc.).
- Add authentication/authorization (e.g., JWT bearer) and role-based policies.
- Extend test coverage with negative cases for validation payloads and concurrency.