This commit is contained in:
Roger Far 2026-02-18 21:34:51 -07:00
parent d0242f235c
commit d6020594ef
10 changed files with 65 additions and 64 deletions

View file

@ -20,11 +20,11 @@ public class WatchFolderCheckerTests : IDisposable
public WatchFolderCheckerTests() public WatchFolderCheckerTests()
{ {
_loggerMock = new Mock<ILogger<WatchFolderChecker>>(); _loggerMock = new();
_serviceProviderMock = new Mock<IServiceProvider>(); _serviceProviderMock = new();
_serviceScopeMock = new Mock<IServiceScope>(); _serviceScopeMock = new();
_scopeServiceProviderMock = new Mock<IServiceProvider>(); _scopeServiceProviderMock = new();
_torrentsServiceMock = new Mock<Torrents>(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); _torrentsServiceMock = new(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!);
_serviceProviderMock _serviceProviderMock
.Setup(x => x.GetService(typeof(IServiceScopeFactory))) .Setup(x => x.GetService(typeof(IServiceScopeFactory)))
@ -65,12 +65,12 @@ public class WatchFolderCheckerTests : IDisposable
{ {
var settings = new Data.Models.Internal.DbSettings var settings = new Data.Models.Internal.DbSettings
{ {
Watch = new Data.Models.Internal.DbSettingsWatch Watch = new()
{ {
Interval = 0, 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); var property = typeof(SettingData).GetProperty("Get", BindingFlags.Public | BindingFlags.Static);

View file

@ -15,21 +15,21 @@ public class NzbTorrentsTest
public NzbTorrentsTest() public NzbTorrentsTest()
{ {
_mocks = new Mocks(); _mocks = new();
_fileSystem = new MockFileSystem(); _fileSystem = new();
_torrents = new TorrentsService( _torrents = new(
_mocks.TorrentsLoggerMock.Object, _mocks.TorrentsLoggerMock.Object,
_mocks.TorrentDataMock.Object, _mocks.TorrentDataMock.Object,
_mocks.DownloadsMock.Object, _mocks.DownloadsMock.Object,
_mocks.ProcessFactoryMock.Object, _mocks.ProcessFactoryMock.Object,
_fileSystem, _fileSystem,
_mocks.EnricherMock.Object, _mocks.EnricherMock.Object,
null!, null!,
null!, null!,
null!, null!,
null!, null!,
null! null!
); );
} }
[Fact] [Fact]

View file

@ -15,11 +15,11 @@ public class QBittorrentTest
public QBittorrentTest() public QBittorrentTest()
{ {
_loggerMock = new Mock<ILogger<QBittorrent>>(); _loggerMock = new();
_torrentsMock = new Mock<Torrents>(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); _torrentsMock = new(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!);
_authenticationMock = new Mock<Authentication>(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] [Fact]

View file

@ -15,7 +15,7 @@ public class SabnzbdTest
public SabnzbdTest() public SabnzbdTest()
{ {
_torrentsMock = new Mock<Torrents>(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<Torrent>()); _torrentsMock.Setup(t => t.Get()).ReturnsAsync(new List<Torrent>());
} }

View file

@ -19,9 +19,9 @@ public class TorBoxDebridClientTest
public TorBoxDebridClientTest() public TorBoxDebridClientTest()
{ {
_loggerMock = new Mock<ILogger<TorBoxDebridClient>>(); _loggerMock = new();
_httpClientFactoryMock = new Mock<IHttpClientFactory>(); _httpClientFactoryMock = new();
_fileFilterMock = new Mock<IDownloadableFileFilter>(); _fileFilterMock = new();
var httpClient = new HttpClient(); var httpClient = new HttpClient();
_httpClientFactoryMock.Setup(m => m.CreateClient(It.IsAny<String>())).Returns(httpClient); _httpClientFactoryMock.Setup(m => m.CreateClient(It.IsAny<String>())).Returns(httpClient);
@ -71,11 +71,11 @@ public class TorBoxDebridClientTest
var hash = "test-hash"; var hash = "test-hash";
var availability = new Response<List<AvailableTorrent?>> var availability = new Response<List<AvailableTorrent?>>
{ {
Data = new List<AvailableTorrent?> Data = new()
{ {
new() new()
{ {
Files = new List<AvailableTorrentFile> Files = new()
{ {
new() { Name = "file1.mkv", Size = 100 }, new() { Name = "file1.mkv", Size = 100 },
new() { Name = "file2.txt", Size = 10 } new() { Name = "file2.txt", Size = 10 }
@ -103,14 +103,14 @@ public class TorBoxDebridClientTest
{ {
// Arrange // Arrange
var hash = "test-hash"; var hash = "test-hash";
var torrentAvailability = new Response<List<AvailableTorrent?>> { Data = new List<AvailableTorrent?>() }; var torrentAvailability = new Response<List<AvailableTorrent?>> { Data = new() };
var usenetAvailability = new Response<List<AvailableUsenet?>> var usenetAvailability = new Response<List<AvailableUsenet?>>
{ {
Data = new List<AvailableUsenet?> Data = new()
{ {
new() new()
{ {
Files = new List<AvailableUsenetFile> Files = new()
{ {
new() { Name = "file1.nzb", Size = 200 } new() { Name = "file1.nzb", Size = 200 }
} }
@ -136,8 +136,8 @@ public class TorBoxDebridClientTest
{ {
// Arrange // Arrange
var hash = "test-hash"; var hash = "test-hash";
var torrentAvailability = new Response<List<AvailableTorrent?>> { Data = new List<AvailableTorrent?>() }; var torrentAvailability = new Response<List<AvailableTorrent?>> { Data = new() };
var usenetAvailability = new Response<List<AvailableUsenet?>> { Data = new List<AvailableUsenet?>() }; var usenetAvailability = new Response<List<AvailableUsenet?>> { Data = new() };
var clientMock = new Mock<TorBoxDebridClient>(_loggerMock.Object, _httpClientFactoryMock.Object, _fileFilterMock.Object); var clientMock = new Mock<TorBoxDebridClient>(_loggerMock.Object, _httpClientFactoryMock.Object, _fileFilterMock.Object);
clientMock.Protected().Setup<Task<Response<List<AvailableTorrent?>>>>("GetTorrentAvailability", hash).ReturnsAsync(torrentAvailability); clientMock.Protected().Setup<Task<Response<List<AvailableTorrent?>>>>("GetTorrentAvailability", hash).ReturnsAsync(torrentAvailability);
@ -270,7 +270,8 @@ public class TorBoxDebridClientTest
clientMock.Protected().Setup<ITorBoxNetClient>("GetClient").Returns(torBoxClientMock.Object); clientMock.Protected().Setup<ITorBoxNetClient>("GetClient").Returns(torBoxClientMock.Object);
usenetApiMock.Setup(m => m.AddFileAsync(bytes, -1, name, null, It.IsAny<CancellationToken>())) usenetApiMock.Setup(m => m.AddFileAsync(bytes, -1, name, null, It.IsAny<CancellationToken>()))
.ReturnsAsync(new Response<UsenetAddResult> { Data = new UsenetAddResult { Hash = "new-hash" } }); .ReturnsAsync(new Response<UsenetAddResult> { Data = new()
{ Hash = "new-hash" } });
// Act // Act
var result = await clientMock.Object.AddNzbFile(bytes, name); var result = await clientMock.Object.AddNzbFile(bytes, name);

View file

@ -53,7 +53,7 @@ public class CredentialRedactorEnricher : ILogEventEnricher
if (property.Value is ScalarValue scalarValue && scalarValue.Value is String stringValue && stringValue.Contains(sensitiveValue)) if (property.Value is ScalarValue scalarValue && scalarValue.Value is String stringValue && stringValue.Contains(sensitiveValue))
{ {
var newValue = stringValue.Replace(sensitiveValue, "*****"); var newValue = stringValue.Replace(sensitiveValue, "*****");
propertiesToUpdate.Add(new LogEventProperty(property.Key, new ScalarValue(newValue))); propertiesToUpdate.Add(new(property.Key, new ScalarValue(newValue)));
} }
} }

View file

@ -210,7 +210,7 @@ public class Sabnzbd(ILogger<Sabnzbd> logger, Torrents torrents, AppSettings app
var config = new SabnzbdConfig var config = new SabnzbdConfig
{ {
Misc = new SabnzbdMisc Misc = new()
{ {
CompleteDir = savePath, CompleteDir = savePath,
DownloadDir = savePath, DownloadDir = savePath,

View file

@ -22,14 +22,14 @@ public class SabnzbdControllerTest
var torrentsMock = new Mock<Torrents>(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); var torrentsMock = new Mock<Torrents>(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!);
var sabnzbdLoggerMock = new Mock<ILogger<Sabnzbd>>(); var sabnzbdLoggerMock = new Mock<ILogger<Sabnzbd>>();
_sabnzbdMock = new Mock<Sabnzbd>(sabnzbdLoggerMock.Object, torrentsMock.Object, null!); _sabnzbdMock = new(sabnzbdLoggerMock.Object, torrentsMock.Object, null!);
var loggerMock = new Mock<ILogger<SabnzbdController>>(); var loggerMock = new Mock<ILogger<SabnzbdController>>();
_authenticationMock = new Mock<Authentication>(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(); var httpContext = new DefaultHttpContext();
_controller.ControllerContext = new ControllerContext _controller.ControllerContext = new()
{ {
HttpContext = httpContext HttpContext = httpContext
}; };
@ -75,7 +75,7 @@ public class SabnzbdControllerTest
// Arrange // Arrange
Data.Data.SettingData.Get.General.AuthenticationType = Data.Enums.AuthenticationType.UserNamePassword; Data.Data.SettingData.Get.General.AuthenticationType = Data.Enums.AuthenticationType.UserNamePassword;
var httpContext = new DefaultHttpContext(); 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; _controller.ControllerContext.HttpContext = httpContext;
_authenticationMock.Setup(a => a.Login("user", "pass")).ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Success); _authenticationMock.Setup(a => a.Login("user", "pass")).ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Success);
@ -140,7 +140,8 @@ public class SabnzbdControllerTest
public void GetConfig_ReturnsOk() public void GetConfig_ReturnsOk()
{ {
// Arrange // 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); _sabnzbdMock.Setup(s => s.GetConfig()).Returns(config);
// Act // Act
@ -199,7 +200,7 @@ public class SabnzbdControllerTest
// Arrange // Arrange
var httpContext = new DefaultHttpContext(); var httpContext = new DefaultHttpContext();
httpContext.Request.ContentType = "application/x-www-form-urlencoded"; httpContext.Request.ContentType = "application/x-www-form-urlencoded";
httpContext.Request.Form = new FormCollection(new Dictionary<String, Microsoft.Extensions.Primitives.StringValues> httpContext.Request.Form = new FormCollection(new()
{ {
{ "mode", "unknown_form" } { "mode", "unknown_form" }
}); });
@ -218,7 +219,7 @@ public class SabnzbdControllerTest
// Arrange // Arrange
var httpContext = new DefaultHttpContext(); var httpContext = new DefaultHttpContext();
httpContext.Request.Method = "POST"; 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 // Mocking multipart form data
var fileMock = new Mock<IFormFile>(); var fileMock = new Mock<IFormFile>();
@ -237,7 +238,7 @@ public class SabnzbdControllerTest
.Returns(Task.CompletedTask); .Returns(Task.CompletedTask);
httpContext.Request.ContentType = "multipart/form-data; boundary=something"; httpContext.Request.ContentType = "multipart/form-data; boundary=something";
httpContext.Request.Form = new FormCollection(new Dictionary<String, Microsoft.Extensions.Primitives.StringValues>(), new FormFileCollection { fileMock.Object }); httpContext.Request.Form = new FormCollection(new(), new FormFileCollection { fileMock.Object });
_controller.ControllerContext.HttpContext = httpContext; _controller.ControllerContext.HttpContext = httpContext;
_sabnzbdMock.Setup(s => s.AddFile(It.IsAny<Byte[]>(), fileName, "radarr", -100)).ReturnsAsync("nzo_id_123"); _sabnzbdMock.Setup(s => s.AddFile(It.IsAny<Byte[]>(), fileName, "radarr", -100)).ReturnsAsync("nzo_id_123");

View file

@ -15,9 +15,9 @@ public class SabnzbdHandlerTest
public SabnzbdHandlerTest() public SabnzbdHandlerTest()
{ {
_authenticationMock = new Mock<Authentication>(null!, null!, null!); _authenticationMock = new(null!, null!, null!);
_httpContextAccessorMock = new Mock<IHttpContextAccessor>(); _httpContextAccessorMock = new();
_handler = new SabnzbdHandler(_authenticationMock.Object, _httpContextAccessorMock.Object); _handler = new(_authenticationMock.Object, _httpContextAccessorMock.Object);
Data.Data.SettingData.Get.General.AuthenticationType = AuthenticationType.UserNamePassword; Data.Data.SettingData.Get.General.AuthenticationType = AuthenticationType.UserNamePassword;
} }
@ -41,7 +41,7 @@ public class SabnzbdHandlerTest
// Arrange // Arrange
Settings.Get.General.AuthenticationType = AuthenticationType.UserNamePassword; Settings.Get.General.AuthenticationType = AuthenticationType.UserNamePassword;
var httpContext = new DefaultHttpContext(); 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); _httpContextAccessorMock.Setup(a => a.HttpContext).Returns(httpContext);
var context = CreateContext(httpContext); var context = CreateContext(httpContext);
@ -79,7 +79,7 @@ public class SabnzbdHandlerTest
// Arrange // Arrange
Settings.Get.General.AuthenticationType = AuthenticationType.UserNamePassword; Settings.Get.General.AuthenticationType = AuthenticationType.UserNamePassword;
var httpContext = new DefaultHttpContext(); 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); _httpContextAccessorMock.Setup(a => a.HttpContext).Returns(httpContext);
var context = CreateContext(httpContext); var context = CreateContext(httpContext);
@ -113,6 +113,6 @@ public class SabnzbdHandlerTest
{ {
var requirement = new SabnzbdRequirement(); var requirement = new SabnzbdRequirement();
var user = httpContext?.User ?? new System.Security.Claims.ClaimsPrincipal(); var user = httpContext?.User ?? new System.Security.Claims.ClaimsPrincipal();
return new AuthorizationHandlerContext([requirement], user, null); return new([requirement], user, null);
} }
} }

View file

@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Moq; using Moq;
using RdtClient.Data.Models.Data;
using RdtClient.Service.Services; using RdtClient.Service.Services;
using RdtClient.Web.Controllers; using RdtClient.Web.Controllers;
@ -16,9 +15,9 @@ public class TorrentsControllerNzbTest
public TorrentsControllerNzbTest() public TorrentsControllerNzbTest()
{ {
_torrentsMock = new Mock<Torrents>(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!); _torrentsMock = new(null!, null!, null!, null!, null!, null!, null!, null!, null!, null!, null!);
_loggerMock = new Mock<ILogger<TorrentsController>>(); _loggerMock = new();
_controller = new TorrentsController(_loggerMock.Object, _torrentsMock.Object, null!); _controller = new(_loggerMock.Object, _torrentsMock.Object, null!);
} }
[Fact] [Fact]
@ -28,7 +27,7 @@ public class TorrentsControllerNzbTest
var request = new TorrentControllerUploadNzbLinkRequest var request = new TorrentControllerUploadNzbLinkRequest
{ {
NzbLink = "http://example.com/test.nzb", NzbLink = "http://example.com/test.nzb",
Torrent = new Torrent() Torrent = new()
}; };
// Act // Act
@ -56,7 +55,7 @@ public class TorrentsControllerNzbTest
var request = new TorrentControllerUploadNzbLinkRequest var request = new TorrentControllerUploadNzbLinkRequest
{ {
NzbLink = "", NzbLink = "",
Torrent = new Torrent() Torrent = new()
}; };
// Act // Act
@ -86,7 +85,7 @@ public class TorrentsControllerNzbTest
var formData = new TorrentControllerUploadFileRequest var formData = new TorrentControllerUploadFileRequest
{ {
Torrent = new Torrent() Torrent = new()
}; };
// Act // Act
@ -102,7 +101,7 @@ public class TorrentsControllerNzbTest
public async Task UploadNzbFile_NoFile_ReturnsBadRequest() public async Task UploadNzbFile_NoFile_ReturnsBadRequest()
{ {
// Act // Act
var result = await _controller.UploadNzbFile(null, new TorrentControllerUploadFileRequest()); var result = await _controller.UploadNzbFile(null, new());
// Assert // Assert
var badRequest = Assert.IsType<BadRequestObjectResult>(result); var badRequest = Assert.IsType<BadRequestObjectResult>(result);