This solution fetches jokes from an external API and stores them in SQLite. It demonstrates clean architecture, SOLID principles, resilience (Polly), Azure Functions (timer-trigger), and unit/integration testing.
- Jokes longer than 200 characters are rejected at the domain level.
- Duplicate jokes (by text) are filtered in-app and prevented by a UNIQUE constraint in the database.
- Provider is swappable via the
IJokeApiabstraction.
Antal.Core— Domain (Joke) and Application (IJokeFetcher,JokeFetcher, contracts, DI)Antal.Infrastructure— SQLite repository (Dapper), HttpClient-based jokes API, DI, Polly policiesAntal.Functions— Azure Functions (timer-trigger) host and configurationAntal.ConsoleApp— Simple console runner to fetch and print jokesAntal.UnitTests— Unit tests (domain and application)Antal.IntegrationTests— Integration tests (SQLite repo and upstream API)
- .NET SDK 8.0+
- Optional: Azure Functions Core Tools (for running Functions via
func start) - Optional: RapidAPI key (only for the external-API integration test)
- Azure Functions local settings:
Antal.Functions/local.settings.jsonValues:JokeFetcherTimerSchedule— CRON schedule for the timer trigger (default: every 15 minutes)Values:JokeFetcher:Count— number of jokes to fetch per runValues:JokeFetcher:MaxParallelism— parallel requests to the providerValues:SqliteConnectionStringorConnectionStrings:SqliteConnectionString— SQLite connection stringValues:JokeApi:BaseAddress— upstream API base URLValues:JokeApi:ApiKey— API key (set if using a provider that requires it)
Note: The console app has an in-memory configuration suitable for quick local runs.
From repository root (this folder):
# Windows PowerShell
dotnet run --project Antal.ConsoleAppThis will:
- Initialize SQLite (creates
jokes.dbin the working directory by default) - Fetch jokes
- Print fetch metrics and list all jokes from the DB
Option A — .NET run:
dotnet run --project Antal.FunctionsOption B — Functions Core Tools:
# In directory: Antal.Functions
func startAdjust JokeFetcherTimerSchedule in local.settings.json for quicker local testing (e.g., every 30s: "*/30 * * * * *").
Run all tests:
dotnet test Antal.sln- Upstream API integration test requires
RAPIDAPI_KEY.- If not set, the test is automatically skipped.
- To set for current session:
- PowerShell:
$env:RAPIDAPI_KEY = "<your_key>" - Bash:
export RAPIDAPI_KEY=<your_key>
- PowerShell:
- To replace the jokes provider, implement
Antal.Core.Application.Abstractions.IJokeApiand register your implementation in DI. - Resilience is configured in
Antal.Infrastructure.DependencyInjection(retry/circuit breaker via Polly).
- The database schema is initialized automatically on startup.
- No secrets are committed to the repository;
local.settings.jsoncontains a placeholder for the API key.