diff --git a/code/backend/Cleanuparr.Infrastructure.Tests/Features/DownloadClient/QBitServiceTests.cs b/code/backend/Cleanuparr.Infrastructure.Tests/Features/DownloadClient/QBitServiceTests.cs index 848f5e31..603e2fcc 100644 --- a/code/backend/Cleanuparr.Infrastructure.Tests/Features/DownloadClient/QBitServiceTests.cs +++ b/code/backend/Cleanuparr.Infrastructure.Tests/Features/DownloadClient/QBitServiceTests.cs @@ -247,6 +247,25 @@ public class QBitServiceTests : IClassFixture result.DeleteFromClient.ShouldBeFalse(); } + [Fact] + public async Task TorrentListIsNull_ReturnsEmptyResult() + { + // Arrange + const string hash = "test-hash"; + QBitService sut = _fixture.CreateSut(); + + _fixture.ClientWrapper + .GetTorrentListAsync(Arg.Any()) + .Returns((IReadOnlyList?)null); + + // Act + DownloadCheckResult result = await sut.ShouldRemoveFromArrQueueAsync(hash, Array.Empty()); + + // Assert + result.Found.ShouldBeFalse(); + result.ShouldRemove.ShouldBeFalse(); + } + [Fact] public async Task TorrentTrackersNotFound_ReturnsEmptyResult() { @@ -1487,6 +1506,23 @@ public class QBitServiceTests : IClassFixture result.DeleteReason.ShouldBe(DeleteReason.None); } + [Fact] + public async Task TorrentListIsNull_ReturnsNotFound() + { + const string hash = "deleted-hash"; + QBitService sut = _fixture.CreateSut(); + SetMalwareBlockerContext(); + + _fixture.ClientWrapper + .GetTorrentListAsync(Arg.Any()) + .Returns((IReadOnlyList?)null); + + BlockFilesResult result = await sut.BlockUnwantedFilesAsync(hash, Array.Empty()); + + result.Found.ShouldBeFalse(); + result.ShouldRemove.ShouldBeFalse(); + } + [Fact] public async Task TrackersNotFound_ReturnsNotFound() { diff --git a/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/IQBittorrentClientWrapper.cs b/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/IQBittorrentClientWrapper.cs index 110457fa..368ad7e4 100644 --- a/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/IQBittorrentClientWrapper.cs +++ b/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/IQBittorrentClientWrapper.cs @@ -9,7 +9,7 @@ public interface IQBittorrentClientWrapper : IDisposable { Task LoginAsync(string username, string password); Task GetApiVersionAsync(); - Task> GetTorrentListAsync(TorrentListQuery query); + Task?> GetTorrentListAsync(TorrentListQuery query); Task GetTorrentPropertiesAsync(string hash); Task?> GetTorrentContentsAsync(string hash); Task?> GetTorrentTrackersAsync(string hash); diff --git a/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBitServiceCB.cs b/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBitServiceCB.cs index b5f536a3..93104401 100644 --- a/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBitServiceCB.cs +++ b/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBitServiceCB.cs @@ -15,7 +15,7 @@ public partial class QBitService public override async Task BlockUnwantedFilesAsync(string hash, IReadOnlyList ignoredDownloads) { TorrentInfo? download = (await _client.GetTorrentListAsync(new TorrentListQuery { Hashes = [hash] })) - .FirstOrDefault(); + ?.FirstOrDefault(); BlockFilesResult result = new(); if (download is null) diff --git a/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBitServiceQC.cs b/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBitServiceQC.cs index d07b7660..a2da79b2 100644 --- a/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBitServiceQC.cs +++ b/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBitServiceQC.cs @@ -15,7 +15,7 @@ public partial class QBitService { DownloadCheckResult result = new(); TorrentInfo? download = (await _client.GetTorrentListAsync(new TorrentListQuery { Hashes = [hash] })) - .FirstOrDefault(); + ?.FirstOrDefault(); if (download is null) { diff --git a/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBittorrentClientWrapper.cs b/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBittorrentClientWrapper.cs index 4f4140aa..a13675ab 100644 --- a/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBittorrentClientWrapper.cs +++ b/code/backend/Cleanuparr.Infrastructure/Features/DownloadClient/QBittorrent/QBittorrentClientWrapper.cs @@ -20,7 +20,7 @@ public sealed class QBittorrentClientWrapper : IQBittorrentClientWrapper public Task GetApiVersionAsync() => _client.GetApiVersionAsync(); - public Task> GetTorrentListAsync(TorrentListQuery query) + public Task?> GetTorrentListAsync(TorrentListQuery query) => _client.GetTorrentListAsync(query); public Task GetTorrentPropertiesAsync(string hash)