A comprehensive .NET 9 Web API for currency conversion using Open Exchange Rates API, built with clean architecture principles and modern development practices.
- Real-time Currency Conversion: Integrates with Open Exchange Rates API for live exchange rates
- Clean Architecture: Implements SOLID principles with Repository and Service patterns
- Comprehensive Testing: Unit tests using MSTest2, AutoFixture, and Moq
- Database Integration: Entity Framework Core with code-first migrations
- API Documentation: Swagger/OpenAPI integration with detailed documentation
- Error Handling: ProblemDetails for consistent error responses
- Resilience: Polly policies for retry and circuit breaker patterns
- Logging: Structured logging with Serilog
- Dependency Injection: Full DI container configuration
The project follows Clean Architecture principles with the following layers:
Money/
βββ Controllers/ # API Controllers
βββ Services/ # Business Logic Services
βββ Repositories/ # Data Access Layer
βββ Factories/ # Factory Pattern Implementation
βββ Models/ # Entity Models
βββ DTOs/ # Data Transfer Objects
βββ Mappings/ # AutoMapper Profiles
βββ Data/ # Entity Framework DbContext
βββ External/ # External API Integration (Refit)
βββ Money.Tests/ # Unit Test Project
- .NET 9 - Latest .NET framework
- ASP.NET Core Web API - Web API framework
- Entity Framework Core - ORM for database operations
- AutoMapper - Object-to-object mapping
- Refit - Type-safe HTTP client for Open Exchange Rates API
- MSTest2 - Unit testing framework
- AutoFixture - Test data generation
- Moq - Mocking framework
- FluentAssertions - Fluent assertion library
- Swashbuckle.AspNetCore - Swagger/OpenAPI documentation
- Serilog - Structured logging
- Polly - Resilience and transient-fault-handling library
- Microsoft.Extensions.Http.Polly - HTTP resilience policies
- Visual Studio 2022 (Community/Professional/Enterprise)
- .NET 9 SDK
- SQL Server (LocalDB or full instance)
- Postman (for API testing)
git clone <repository-url>
cd Moneydotnet restoreUpdate appsettings.json with your database connection string if needed:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=CurrencyConverterDb;Trusted_Connection=true;MultipleActiveResultSets=true"
},
"OpenExchangeRates": {
"ApiKey": "041f13216f7840fbbeb5d9828390ce51",
"BaseUrl": "https://openexchangerates.org/api"
}
}dotnet run --project MoneyThe API will be available at:
- HTTPS:
https://localhost:7001 - HTTP:
http://localhost:5000 - Swagger UI:
https://localhost:7001(root URL)
dotnet test- POST
/api/currency/convert- Convert currency from one to another
- GET
/api/currency- Get all supported currencies
- GET
/api/currency/history- Get conversion history (optional userId filter) - GET
/api/currency/{id}- Get specific conversion by ID
curl -X POST "https://localhost:7001/api/currency/convert" \
-H "Content-Type: application/json" \
-d '{
"fromCurrency": "USD",
"toCurrency": "CAD",
"amount": 100.00,
"userId": "user-123"
}'curl -X GET "https://localhost:7001/api/currency"dotnet test Money.TestsThe test suite includes:
- Service Layer Tests: Business logic validation
- Controller Tests: API endpoint testing
- Factory Tests: Factory pattern implementation
- Integration Tests: End-to-end scenarios
See Money.Tests/AdditionalTestSuggestions.md for comprehensive test coverage recommendations.
Import the provided CurrencyConverterAPI.postman_collection.json into Postman for comprehensive API testing. The collection includes:
- Currency conversion examples
- Error handling scenarios
- Validation tests
- Automated test assertions
ConnectionStrings__DefaultConnection- Database connection stringOpenExchangeRates__ApiKey- Open Exchange Rates API keyOpenExchangeRates__BaseUrl- Open Exchange Rates base URL
Logs are written to the logs/ directory with daily rotation. Configure Serilog in Program.cs for custom logging behavior.
ICurrencyRepository/CurrencyRepositoryICurrencyConversionRepository/CurrencyConversionRepository
ICurrencyService/CurrencyServiceIExchangeRateService/ExchangeRateService
ICurrencyConverterFactory/CurrencyConverterFactory
- Full DI container configuration in
Program.cs - Interface-based dependency registration
CurrencyMappingProfilefor object mapping- DTO to Entity and Entity to DTO transformations
- API key stored in configuration (consider Azure Key Vault for production)
- Input validation on all endpoints
- SQL injection prevention through Entity Framework
- CORS configuration (add as needed)
dotnet run- Update connection strings for production database
- Configure proper logging levels
- Set up monitoring and health checks
- Configure SSL certificates
- Set up CI/CD pipeline
- Caching: Consider implementing Redis for exchange rate caching
- Rate Limiting: Implement rate limiting for API endpoints
- Database Optimization: Add indexes for frequently queried fields
- Async/Await: All database operations are asynchronous
- Add authentication and authorization
- Implement caching for exchange rates
- Add health checks
- Implement rate limiting
- Add monitoring and metrics
- Support for more currency providers
- Historical exchange rate data
- Bulk currency conversion
The project follows:
- SOLID Principles: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
- DRY Principle: Don't Repeat Yourself
- Clean Code: Meaningful names, small functions, clear structure
- Async/Await: Non-blocking operations throughout
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is created for technical assessment purposes.
For questions or issues, please refer to the code documentation or create an issue in the repository.
Built with β€οΈ using .NET 9 and modern development practices