A simple ASP.NET Core project with full CRUD operations and comprehensive xUnit test coverage.
This is a simple ASP.NET Core Web API project created to demonstrate and apply unit testing using xUnit through real-world examples covering contacts and countries management.
- Setup of xUnit in ASP.NET Core project.
- Writing simple and structured unit tests.
- Add Country
- Get All Countries
- Get Country by ID
- Full xUnit test coverage for each operation.
- Add Person with model validation.
- Get Person by ID
- Get All Persons
- Get Filtered Persons
- Get Sorted Persons
- Update Person
- Delete Person
- Each action includes both implementation and xUnit test to verify behavior.
- Model validation for Add/Update Person operations.
- xUnit tests for invalid inputs and edge cases.
- Use of
ITestOutputHelper
for better visibility of test execution and debugging.
- ASP.NET Core Web API
- C#
- .NET 6+
- xUnit Testing Framework
- Visual Studio 2022 / VS Code
Controllers/
→ API endpoints for Person & CountryModels/
→ Entities, DTOs, and Validation RulesServices/
→ Business logic and data operationsTests/
→ xUnit test classes per featureProgram.cs
→ App configuration and service registration
git clone https://github.com/MuhammedReda263/xUnit.git
cd xUnit
dotnet restore
dotnet run