AsyncDownload
is a .NET 8 based application designed for asynchronous downloading of content from the Internet. Utilizing the power of .NET's asynchronous programming model, it provides an efficient means of downloading content from specified URLs concurrently, without blocking the user interface or the application's main execution thread.
The application adopts a modular architecture focusing on separation of concerns, making it scalable and maintainable. Key components include:
-
DownloadService: Orchestrates the download process, managing asynchronous calls to fetch content from URLs and save them to the filesystem. It utilizes
IHttpClientFactory
for resilient HTTP requests and employs aSemaphoreSlim
for controlling concurrency, ensuring a customizable limit on the number of simultaneous downloads. -
FileService (Implements
IFileService
): Handles file operations, specifically writing downloaded content to the filesystem asynchronously. This abstraction allows for easier unit testing and future extensions, such as adding support for different storage backends. -
Program: Sets up dependency injection, logging, and application configuration. It initializes
DownloadService
with required dependencies and triggers the download process.
-
Microsoft.Extensions.DependencyInjection: Used for implementing dependency injection, allowing for decoupled and testable code.
-
Microsoft.Extensions.Logging: Provides logging capabilities, essential for monitoring the application's operation and troubleshooting issues.
-
Polly: Integrated with
IHttpClientFactory
for resilience and transient fault handling. It's configured to retry HTTP requests based on certain policies, enhancing the robustness of web requests.
Comprehensive error handling is implemented, with graceful handling of exceptions such as network failures or file write errors. Logging is extensively used across components, providing insights into the application's behavior and any errors that occur.
- .NET 8 SDK
- Clone the repository:
git clone https://github.com/CodingBrushUp2/AsyncDownload.git
- Build the solution:
dotnet build
- Run the application:
dotnet run
- Asynchronous content downloading from a list of URLs.
- Configurable concurrency limit for simultaneous downloads.
- Resilient HTTP requests with retry policies.
- Detailed logging for operational monitoring and error diagnosis.
Unit tests are provided for critical components, using XUnit
, Moq
for mocking dependencies, and asserting outcomes with precise conditions. The tests cover scenarios such as successful downloads, handling of HTTP request failures, and file write errors, ensuring the reliability and robustness of the service.
DownloadFileAsync_ShouldDownloadFile_WhenUrlIsInvalid
: Verifies download functionality with invalid URLs.LogsError_WhenFileWriteFails
: Tests error logging when file writing fails.DoesNotAttemptDownload_WhenUrlListIsEmpty
: Ensures no download attempts are made when the URL list is empty.
Contributions are welcome. Please feel free to fork the repository, make changes, and submit pull requests.
Distributed under the MIT License.