From d6020594ef7f7dba4b44511940d8c30d1936dbeb Mon Sep 17 00:00:00 2001 From: Roger Far Date: Wed, 18 Feb 2026 21:34:51 -0700 Subject: [PATCH] Cleanup. --- .../WatchFolderCheckerTests.cs | 16 +++++----- .../Services/NzbTorrentsTest.cs | 30 +++++++++---------- .../Services/QBittorrentTest.cs | 8 ++--- .../Services/SabnzbdTest.cs | 2 +- .../TorrentClients/TorBoxDebridClientTest.cs | 23 +++++++------- .../Helpers/CredentialRedactorEnricher.cs | 2 +- server/RdtClient.Service/Services/Sabnzbd.cs | 2 +- .../Controllers/SabnzbdControllerTest.cs | 19 ++++++------ .../Controllers/SabnzbdHandlerTest.cs | 12 ++++---- .../Controllers/TorrentsControllerNzbTest.cs | 15 +++++----- 10 files changed, 65 insertions(+), 64 deletions(-) diff --git a/server/RdtClient.Service.Test/BackgroundServices/WatchFolderCheckerTests.cs b/server/RdtClient.Service.Test/BackgroundServices/WatchFolderCheckerTests.cs index f900398..fa2e8ee 100644 --- a/server/RdtClient.Service.Test/BackgroundServices/WatchFolderCheckerTests.cs +++ b/server/RdtClient.Service.Test/BackgroundServices/WatchFolderCheckerTests.cs @@ -20,11 +20,11 @@ public class WatchFolderCheckerTests : IDisposable public WatchFolderCheckerTests() { - _loggerMock = new Mock>(); - _serviceProviderMock = new Mock(); - _serviceScopeMock = new Mock(); - _scopeServiceProviderMock = new Mock(); - _torrentsServiceMock = new Mock(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); + _loggerMock = new(); + _serviceProviderMock = new(); + _serviceScopeMock = new(); + _scopeServiceProviderMock = new(); + _torrentsServiceMock = new(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); _serviceProviderMock .Setup(x => x.GetService(typeof(IServiceScopeFactory))) @@ -65,12 +65,12 @@ public class WatchFolderCheckerTests : IDisposable { var settings = new Data.Models.Internal.DbSettings { - Watch = new Data.Models.Internal.DbSettingsWatch + Watch = new() { Interval = 0, - Default = new Data.Models.Internal.DbSettingsDefaultsWithCategory() + Default = new() }, - DownloadClient = new Data.Models.Internal.DbSettingsDownloadClient() + DownloadClient = new() }; var property = typeof(SettingData).GetProperty("Get", BindingFlags.Public | BindingFlags.Static); diff --git a/server/RdtClient.Service.Test/Services/NzbTorrentsTest.cs b/server/RdtClient.Service.Test/Services/NzbTorrentsTest.cs index 906e810..41d5198 100644 --- a/server/RdtClient.Service.Test/Services/NzbTorrentsTest.cs +++ b/server/RdtClient.Service.Test/Services/NzbTorrentsTest.cs @@ -15,21 +15,21 @@ public class NzbTorrentsTest public NzbTorrentsTest() { - _mocks = new Mocks(); - _fileSystem = new MockFileSystem(); - _torrents = new TorrentsService( - _mocks.TorrentsLoggerMock.Object, - _mocks.TorrentDataMock.Object, - _mocks.DownloadsMock.Object, - _mocks.ProcessFactoryMock.Object, - _fileSystem, - _mocks.EnricherMock.Object, - null!, - null!, - null!, - null!, - null! - ); + _mocks = new(); + _fileSystem = new(); + _torrents = new( + _mocks.TorrentsLoggerMock.Object, + _mocks.TorrentDataMock.Object, + _mocks.DownloadsMock.Object, + _mocks.ProcessFactoryMock.Object, + _fileSystem, + _mocks.EnricherMock.Object, + null!, + null!, + null!, + null!, + null! + ); } [Fact] diff --git a/server/RdtClient.Service.Test/Services/QBittorrentTest.cs b/server/RdtClient.Service.Test/Services/QBittorrentTest.cs index c2979a1..a189639 100644 --- a/server/RdtClient.Service.Test/Services/QBittorrentTest.cs +++ b/server/RdtClient.Service.Test/Services/QBittorrentTest.cs @@ -15,11 +15,11 @@ public class QBittorrentTest public QBittorrentTest() { - _loggerMock = new Mock>(); - _torrentsMock = new Mock(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); - _authenticationMock = new Mock(null!, null!, null!); + _loggerMock = new(); + _torrentsMock = new(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); + _authenticationMock = new(null!, null!, null!); - _qBittorrent = new QBittorrent(_loggerMock.Object, null!, _authenticationMock.Object, _torrentsMock.Object, null!); + _qBittorrent = new(_loggerMock.Object, null!, _authenticationMock.Object, _torrentsMock.Object, null!); } [Fact] diff --git a/server/RdtClient.Service.Test/Services/SabnzbdTest.cs b/server/RdtClient.Service.Test/Services/SabnzbdTest.cs index de8dd1a..51b1058 100644 --- a/server/RdtClient.Service.Test/Services/SabnzbdTest.cs +++ b/server/RdtClient.Service.Test/Services/SabnzbdTest.cs @@ -15,7 +15,7 @@ public class SabnzbdTest public SabnzbdTest() { - _torrentsMock = new Mock(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); + _torrentsMock = new(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); _torrentsMock.Setup(t => t.Get()).ReturnsAsync(new List()); } diff --git a/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs b/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs index 365369b..f303bb5 100644 --- a/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs +++ b/server/RdtClient.Service.Test/Services/TorrentClients/TorBoxDebridClientTest.cs @@ -19,9 +19,9 @@ public class TorBoxDebridClientTest public TorBoxDebridClientTest() { - _loggerMock = new Mock>(); - _httpClientFactoryMock = new Mock(); - _fileFilterMock = new Mock(); + _loggerMock = new(); + _httpClientFactoryMock = new(); + _fileFilterMock = new(); var httpClient = new HttpClient(); _httpClientFactoryMock.Setup(m => m.CreateClient(It.IsAny())).Returns(httpClient); @@ -71,11 +71,11 @@ public class TorBoxDebridClientTest var hash = "test-hash"; var availability = new Response> { - Data = new List + Data = new() { new() { - Files = new List + Files = new() { new() { Name = "file1.mkv", Size = 100 }, new() { Name = "file2.txt", Size = 10 } @@ -103,14 +103,14 @@ public class TorBoxDebridClientTest { // Arrange var hash = "test-hash"; - var torrentAvailability = new Response> { Data = new List() }; + var torrentAvailability = new Response> { Data = new() }; var usenetAvailability = new Response> { - Data = new List + Data = new() { new() { - Files = new List + Files = new() { new() { Name = "file1.nzb", Size = 200 } } @@ -136,8 +136,8 @@ public class TorBoxDebridClientTest { // Arrange var hash = "test-hash"; - var torrentAvailability = new Response> { Data = new List() }; - var usenetAvailability = new Response> { Data = new List() }; + var torrentAvailability = new Response> { Data = new() }; + var usenetAvailability = new Response> { Data = new() }; var clientMock = new Mock(_loggerMock.Object, _httpClientFactoryMock.Object, _fileFilterMock.Object); clientMock.Protected().Setup>>>("GetTorrentAvailability", hash).ReturnsAsync(torrentAvailability); @@ -270,7 +270,8 @@ public class TorBoxDebridClientTest clientMock.Protected().Setup("GetClient").Returns(torBoxClientMock.Object); usenetApiMock.Setup(m => m.AddFileAsync(bytes, -1, name, null, It.IsAny())) - .ReturnsAsync(new Response { Data = new UsenetAddResult { Hash = "new-hash" } }); + .ReturnsAsync(new Response { Data = new() + { Hash = "new-hash" } }); // Act var result = await clientMock.Object.AddNzbFile(bytes, name); diff --git a/server/RdtClient.Service/Helpers/CredentialRedactorEnricher.cs b/server/RdtClient.Service/Helpers/CredentialRedactorEnricher.cs index 33d22e5..56cf99a 100644 --- a/server/RdtClient.Service/Helpers/CredentialRedactorEnricher.cs +++ b/server/RdtClient.Service/Helpers/CredentialRedactorEnricher.cs @@ -53,7 +53,7 @@ public class CredentialRedactorEnricher : ILogEventEnricher if (property.Value is ScalarValue scalarValue && scalarValue.Value is String stringValue && stringValue.Contains(sensitiveValue)) { var newValue = stringValue.Replace(sensitiveValue, "*****"); - propertiesToUpdate.Add(new LogEventProperty(property.Key, new ScalarValue(newValue))); + propertiesToUpdate.Add(new(property.Key, new ScalarValue(newValue))); } } diff --git a/server/RdtClient.Service/Services/Sabnzbd.cs b/server/RdtClient.Service/Services/Sabnzbd.cs index 2498741..a7bd066 100644 --- a/server/RdtClient.Service/Services/Sabnzbd.cs +++ b/server/RdtClient.Service/Services/Sabnzbd.cs @@ -210,7 +210,7 @@ public class Sabnzbd(ILogger logger, Torrents torrents, AppSettings app var config = new SabnzbdConfig { - Misc = new SabnzbdMisc + Misc = new() { CompleteDir = savePath, DownloadDir = savePath, diff --git a/server/RdtClient.Web.Test/Controllers/SabnzbdControllerTest.cs b/server/RdtClient.Web.Test/Controllers/SabnzbdControllerTest.cs index c156822..fd3505e 100644 --- a/server/RdtClient.Web.Test/Controllers/SabnzbdControllerTest.cs +++ b/server/RdtClient.Web.Test/Controllers/SabnzbdControllerTest.cs @@ -22,14 +22,14 @@ public class SabnzbdControllerTest var torrentsMock = new Mock(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); var sabnzbdLoggerMock = new Mock>(); - _sabnzbdMock = new Mock(sabnzbdLoggerMock.Object, torrentsMock.Object, null!); + _sabnzbdMock = new(sabnzbdLoggerMock.Object, torrentsMock.Object, null!); var loggerMock = new Mock>(); - _authenticationMock = new Mock(null!, null!, null!); + _authenticationMock = new(null!, null!, null!); - _controller = new SabnzbdController(loggerMock.Object, _sabnzbdMock.Object); + _controller = new(loggerMock.Object, _sabnzbdMock.Object); var httpContext = new DefaultHttpContext(); - _controller.ControllerContext = new ControllerContext + _controller.ControllerContext = new() { HttpContext = httpContext }; @@ -75,7 +75,7 @@ public class SabnzbdControllerTest // Arrange Data.Data.SettingData.Get.General.AuthenticationType = Data.Enums.AuthenticationType.UserNamePassword; var httpContext = new DefaultHttpContext(); - httpContext.Request.QueryString = new QueryString("?ma_username=user&ma_password=pass"); + httpContext.Request.QueryString = new("?ma_username=user&ma_password=pass"); _controller.ControllerContext.HttpContext = httpContext; _authenticationMock.Setup(a => a.Login("user", "pass")).ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Success); @@ -140,7 +140,8 @@ public class SabnzbdControllerTest public void GetConfig_ReturnsOk() { // Arrange - var config = new SabnzbdConfig { Misc = new SabnzbdMisc { Port = "6500" } }; + var config = new SabnzbdConfig { Misc = new() + { Port = "6500" } }; _sabnzbdMock.Setup(s => s.GetConfig()).Returns(config); // Act @@ -199,7 +200,7 @@ public class SabnzbdControllerTest // Arrange var httpContext = new DefaultHttpContext(); httpContext.Request.ContentType = "application/x-www-form-urlencoded"; - httpContext.Request.Form = new FormCollection(new Dictionary + httpContext.Request.Form = new FormCollection(new() { { "mode", "unknown_form" } }); @@ -218,7 +219,7 @@ public class SabnzbdControllerTest // Arrange var httpContext = new DefaultHttpContext(); httpContext.Request.Method = "POST"; - httpContext.Request.QueryString = new QueryString("?cat=radarr&priority=-100"); + httpContext.Request.QueryString = new("?cat=radarr&priority=-100"); // Mocking multipart form data var fileMock = new Mock(); @@ -237,7 +238,7 @@ public class SabnzbdControllerTest .Returns(Task.CompletedTask); httpContext.Request.ContentType = "multipart/form-data; boundary=something"; - httpContext.Request.Form = new FormCollection(new Dictionary(), new FormFileCollection { fileMock.Object }); + httpContext.Request.Form = new FormCollection(new(), new FormFileCollection { fileMock.Object }); _controller.ControllerContext.HttpContext = httpContext; _sabnzbdMock.Setup(s => s.AddFile(It.IsAny(), fileName, "radarr", -100)).ReturnsAsync("nzo_id_123"); diff --git a/server/RdtClient.Web.Test/Controllers/SabnzbdHandlerTest.cs b/server/RdtClient.Web.Test/Controllers/SabnzbdHandlerTest.cs index 764e917..599b3d2 100644 --- a/server/RdtClient.Web.Test/Controllers/SabnzbdHandlerTest.cs +++ b/server/RdtClient.Web.Test/Controllers/SabnzbdHandlerTest.cs @@ -15,9 +15,9 @@ public class SabnzbdHandlerTest public SabnzbdHandlerTest() { - _authenticationMock = new Mock(null!, null!, null!); - _httpContextAccessorMock = new Mock(); - _handler = new SabnzbdHandler(_authenticationMock.Object, _httpContextAccessorMock.Object); + _authenticationMock = new(null!, null!, null!); + _httpContextAccessorMock = new(); + _handler = new(_authenticationMock.Object, _httpContextAccessorMock.Object); Data.Data.SettingData.Get.General.AuthenticationType = AuthenticationType.UserNamePassword; } @@ -41,7 +41,7 @@ public class SabnzbdHandlerTest // Arrange Settings.Get.General.AuthenticationType = AuthenticationType.UserNamePassword; var httpContext = new DefaultHttpContext(); - httpContext.Request.QueryString = new QueryString("?ma_username=user&ma_password=pass"); + httpContext.Request.QueryString = new("?ma_username=user&ma_password=pass"); _httpContextAccessorMock.Setup(a => a.HttpContext).Returns(httpContext); var context = CreateContext(httpContext); @@ -79,7 +79,7 @@ public class SabnzbdHandlerTest // Arrange Settings.Get.General.AuthenticationType = AuthenticationType.UserNamePassword; var httpContext = new DefaultHttpContext(); - httpContext.Request.QueryString = new QueryString("?ma_username=user&ma_password=wrong"); + httpContext.Request.QueryString = new("?ma_username=user&ma_password=wrong"); _httpContextAccessorMock.Setup(a => a.HttpContext).Returns(httpContext); var context = CreateContext(httpContext); @@ -113,6 +113,6 @@ public class SabnzbdHandlerTest { var requirement = new SabnzbdRequirement(); var user = httpContext?.User ?? new System.Security.Claims.ClaimsPrincipal(); - return new AuthorizationHandlerContext([requirement], user, null); + return new([requirement], user, null); } } diff --git a/server/RdtClient.Web.Test/Controllers/TorrentsControllerNzbTest.cs b/server/RdtClient.Web.Test/Controllers/TorrentsControllerNzbTest.cs index 8c315c6..63e9e6d 100644 --- a/server/RdtClient.Web.Test/Controllers/TorrentsControllerNzbTest.cs +++ b/server/RdtClient.Web.Test/Controllers/TorrentsControllerNzbTest.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Moq; -using RdtClient.Data.Models.Data; using RdtClient.Service.Services; using RdtClient.Web.Controllers; @@ -16,9 +15,9 @@ public class TorrentsControllerNzbTest public TorrentsControllerNzbTest() { - _torrentsMock = new Mock(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); - _loggerMock = new Mock>(); - _controller = new TorrentsController(_loggerMock.Object, _torrentsMock.Object, null!); + _torrentsMock = new(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); + _loggerMock = new(); + _controller = new(_loggerMock.Object, _torrentsMock.Object, null!); } [Fact] @@ -28,7 +27,7 @@ public class TorrentsControllerNzbTest var request = new TorrentControllerUploadNzbLinkRequest { NzbLink = "http://example.com/test.nzb", - Torrent = new Torrent() + Torrent = new() }; // Act @@ -56,7 +55,7 @@ public class TorrentsControllerNzbTest var request = new TorrentControllerUploadNzbLinkRequest { NzbLink = "", - Torrent = new Torrent() + Torrent = new() }; // Act @@ -86,7 +85,7 @@ public class TorrentsControllerNzbTest var formData = new TorrentControllerUploadFileRequest { - Torrent = new Torrent() + Torrent = new() }; // Act @@ -102,7 +101,7 @@ public class TorrentsControllerNzbTest public async Task UploadNzbFile_NoFile_ReturnsBadRequest() { // Act - var result = await _controller.UploadNzbFile(null, new TorrentControllerUploadFileRequest()); + var result = await _controller.UploadNzbFile(null, new()); // Assert var badRequest = Assert.IsType(result);