From daf8a9c6da43d37c7640d2ce0c515564b5fa1d28 Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Mon, 17 Feb 2025 21:57:02 +0000 Subject: [PATCH] `DownloadHelper`: use `IFileSystem` for testable filesystem access --- server/RdtClient.Service/Helpers/DownloadHelper.cs | 11 +++++++---- server/RdtClient.Service/RdtClient.Service.csproj | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/RdtClient.Service/Helpers/DownloadHelper.cs b/server/RdtClient.Service/Helpers/DownloadHelper.cs index 64067b0..3e2653d 100644 --- a/server/RdtClient.Service/Helpers/DownloadHelper.cs +++ b/server/RdtClient.Service/Helpers/DownloadHelper.cs @@ -1,11 +1,12 @@ -using RdtClient.Data.Models.Data; +using System.IO.Abstractions; +using RdtClient.Data.Models.Data; using System.Web; namespace RdtClient.Service.Helpers; public static class DownloadHelper { - public static String? GetDownloadPath(String downloadPath, Torrent torrent, Download download) + public static String? GetDownloadPath(String downloadPath, Torrent torrent, Download download, IFileSystem? fileSystem = null) { var fileUrl = download.Link; @@ -41,9 +42,11 @@ public static class DownloadHelper } } - if (!Directory.Exists(torrentPath)) + fileSystem ??= new FileSystem(); + + if (!fileSystem.Directory.Exists(torrentPath)) { - Directory.CreateDirectory(torrentPath); + fileSystem.Directory.CreateDirectory(torrentPath); } var filePath = Path.Combine(torrentPath, fileName); diff --git a/server/RdtClient.Service/RdtClient.Service.csproj b/server/RdtClient.Service/RdtClient.Service.csproj index 2257d27..edb4d40 100644 --- a/server/RdtClient.Service/RdtClient.Service.csproj +++ b/server/RdtClient.Service/RdtClient.Service.csproj @@ -24,6 +24,7 @@ +