Avoid unnecessary zero-length array allocations

This commit is contained in:
Qstick 2023-01-09 21:59:55 -06:00
parent b2c2c79a96
commit 0ed8ba828d
39 changed files with 77 additions and 66 deletions

View File

@ -194,7 +194,6 @@ dotnet_diagnostic.CA1819.severity = suggestion
dotnet_diagnostic.CA1822.severity = suggestion dotnet_diagnostic.CA1822.severity = suggestion
dotnet_diagnostic.CA1823.severity = suggestion dotnet_diagnostic.CA1823.severity = suggestion
dotnet_diagnostic.CA1824.severity = suggestion dotnet_diagnostic.CA1824.severity = suggestion
dotnet_diagnostic.CA1825.severity = suggestion
dotnet_diagnostic.CA1826.severity = suggestion dotnet_diagnostic.CA1826.severity = suggestion
dotnet_diagnostic.CA1827.severity = suggestion dotnet_diagnostic.CA1827.severity = suggestion
dotnet_diagnostic.CA1829.severity = suggestion dotnet_diagnostic.CA1829.severity = suggestion

View File

@ -1,3 +1,4 @@
using System;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
@ -11,7 +12,7 @@ namespace NzbDrone.Common.Test.EnvironmentTests
[Test] [Test]
public void empty_array_should_return_empty_flags() public void empty_array_should_return_empty_flags()
{ {
var args = new StartupContext(new string[0]); var args = new StartupContext(Array.Empty<string>());
args.Flags.Should().BeEmpty(); args.Flags.Should().BeEmpty();
} }

View File

@ -102,7 +102,7 @@ namespace NzbDrone.Common.Test.Http
Mocker.SetConstant<ICertificateValidationService>(new X509CertificateValidationService(Mocker.GetMock<IConfigService>().Object, TestLogger)); Mocker.SetConstant<ICertificateValidationService>(new X509CertificateValidationService(Mocker.GetMock<IConfigService>().Object, TestLogger));
Mocker.SetConstant<IRateLimitService>(Mocker.Resolve<RateLimitService>()); Mocker.SetConstant<IRateLimitService>(Mocker.Resolve<RateLimitService>());
Mocker.SetConstant<IEnumerable<IHttpRequestInterceptor>>(new IHttpRequestInterceptor[0]); Mocker.SetConstant<IEnumerable<IHttpRequestInterceptor>>(Array.Empty<IHttpRequestInterceptor>());
Mocker.SetConstant<IHttpDispatcher>(Mocker.Resolve<TDispatcher>()); Mocker.SetConstant<IHttpDispatcher>(Mocker.Resolve<TDispatcher>());
// Used for manual testing of socks proxies. // Used for manual testing of socks proxies.
@ -459,7 +459,7 @@ namespace NzbDrone.Common.Test.Http
var oldRequest = new HttpRequest($"https://{_httpBinHost2}/get"); var oldRequest = new HttpRequest($"https://{_httpBinHost2}/get");
oldRequest.Cookies["my"] = "cookie"; oldRequest.Cookies["my"] = "cookie";
var oldClient = new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve<ICacheManager>(), Mocker.Resolve<IRateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.GetMock<IUserAgentBuilder>().Object, Mocker.Resolve<Logger>()); var oldClient = new HttpClient(Array.Empty<IHttpRequestInterceptor>(), Mocker.Resolve<ICacheManager>(), Mocker.Resolve<IRateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.GetMock<IUserAgentBuilder>().Object, Mocker.Resolve<Logger>());
oldClient.Should().NotBeSameAs(Subject); oldClient.Should().NotBeSameAs(Subject);

View File

@ -60,7 +60,7 @@ namespace NzbDrone.Common.Http
public string[] GetCookieHeaders() public string[] GetCookieHeaders()
{ {
return Headers.GetValues("Set-Cookie") ?? new string[0]; return Headers.GetValues("Set-Cookie") ?? Array.Empty<string>();
} }
public Dictionary<string, string> GetCookies() public Dictionary<string, string> GetCookies()

View File

@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
} }
protected void GivenFailedDownload() protected void GivenFailedDownload()

View File

@ -35,7 +35,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
Mocker.GetMock<IRemotePathMappingService>() Mocker.GetMock<IRemotePathMappingService>()
.Setup(v => v.RemapRemoteToLocal(It.IsAny<string>(), It.IsAny<OsPath>())) .Setup(v => v.RemapRemoteToLocal(It.IsAny<string>(), It.IsAny<OsPath>()))

View File

@ -277,7 +277,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
_downloadStationConfigItems = new Dictionary<string, object> _downloadStationConfigItems = new Dictionary<string, object>
{ {

View File

@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
_downloadStationConfigItems = new Dictionary<string, object> _downloadStationConfigItems = new Dictionary<string, object>
{ {

View File

@ -79,7 +79,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
} }
protected void GivenCategory() protected void GivenCategory()

View File

@ -86,7 +86,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
} }
protected void GivenFailedDownload() protected void GivenFailedDownload()

View File

@ -38,7 +38,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
Mocker.GetMock<IQBittorrentProxy>() Mocker.GetMock<IQBittorrentProxy>()
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>())) .Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.SeeOther)); .Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, Array.Empty<byte>(), System.Net.HttpStatusCode.SeeOther));
} }
protected void GivenRedirectToTorrent() protected void GivenRedirectToTorrent()
@ -66,7 +66,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.Is<HttpRequest>(h => h.Url.FullUri == _downloadUrl))) .Setup(s => s.Get(It.Is<HttpRequest>(h => h.Url.FullUri == _downloadUrl)))
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.Found)); .Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, Array.Empty<byte>(), System.Net.HttpStatusCode.Found));
} }
protected void GivenFailedDownload() protected void GivenFailedDownload()
@ -523,7 +523,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
Mocker.GetMock<IQBittorrentProxy>() Mocker.GetMock<IQBittorrentProxy>()
.Setup(v => v.MoveTorrentToTopInQueue(It.IsAny<string>(), It.IsAny<QBittorrentSettings>())) .Setup(v => v.MoveTorrentToTopInQueue(It.IsAny<string>(), It.IsAny<QBittorrentSettings>()))
.Throws(new HttpException(new HttpResponse(new HttpRequest("http://me.local/"), new HttpHeader(), new byte[0], System.Net.HttpStatusCode.Forbidden))); .Throws(new HttpException(new HttpResponse(new HttpRequest("http://me.local/"), new HttpHeader(), Array.Empty<byte>(), System.Net.HttpStatusCode.Forbidden)));
var remoteEpisode = CreateRemoteEpisode(); var remoteEpisode = CreateRemoteEpisode();

View File

@ -545,7 +545,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
public void should_test_failed_if_tv_sorting_empty() public void should_test_failed_if_tv_sorting_empty()
{ {
_config.Misc.enable_tv_sorting = true; _config.Misc.enable_tv_sorting = true;
_config.Misc.tv_categories = new string[0]; _config.Misc.tv_categories = Array.Empty<string>();
var result = new NzbDroneValidationResult(Subject.Test()); var result = new NzbDroneValidationResult(Subject.Test());

View File

@ -99,7 +99,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
_transmissionConfigItems = new Dictionary<string, object>(); _transmissionConfigItems = new Dictionary<string, object>();

View File

@ -91,7 +91,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
} }
protected void GivenRedirectToMagnet() protected void GivenRedirectToMagnet()
@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.SeeOther)); .Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, Array.Empty<byte>(), System.Net.HttpStatusCode.SeeOther));
} }
protected void GivenRedirectToTorrent() protected void GivenRedirectToTorrent()
@ -111,7 +111,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.Is<HttpRequest>(h => h.Url.ToString() == _downloadUrl))) .Setup(s => s.Get(It.Is<HttpRequest>(h => h.Url.ToString() == _downloadUrl)))
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.Found)); .Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, Array.Empty<byte>(), System.Net.HttpStatusCode.Found));
} }
protected void GivenFailedDownload() protected void GivenFailedDownload()

View File

@ -132,7 +132,7 @@ namespace NzbDrone.Core.Test.Download
public void Download_report_should_trigger_indexer_backoff_on_http429_with_long_time() public void Download_report_should_trigger_indexer_backoff_on_http429_with_long_time()
{ {
var request = new HttpRequest("http://my.indexer.com"); var request = new HttpRequest("http://my.indexer.com");
var response = new HttpResponse(request, new HttpHeader(), new byte[0], (HttpStatusCode)429); var response = new HttpResponse(request, new HttpHeader(), Array.Empty<byte>(), (HttpStatusCode)429);
response.Headers["Retry-After"] = "300"; response.Headers["Retry-After"] = "300";
var mock = WithUsenetClient(); var mock = WithUsenetClient();
@ -152,7 +152,7 @@ namespace NzbDrone.Core.Test.Download
public void Download_report_should_trigger_indexer_backoff_on_http429_based_on_date() public void Download_report_should_trigger_indexer_backoff_on_http429_based_on_date()
{ {
var request = new HttpRequest("http://my.indexer.com"); var request = new HttpRequest("http://my.indexer.com");
var response = new HttpResponse(request, new HttpHeader(), new byte[0], (HttpStatusCode)429); var response = new HttpResponse(request, new HttpHeader(), Array.Empty<byte>(), (HttpStatusCode)429);
response.Headers["Retry-After"] = DateTime.UtcNow.AddSeconds(300).ToString("r"); response.Headers["Retry-After"] = DateTime.UtcNow.AddSeconds(300).ToString("r");
var mock = WithUsenetClient(); var mock = WithUsenetClient();

View File

@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.Framework
Mocker.SetConstant<ICreateManagedWebProxy>(new ManagedWebProxyFactory(Mocker.Resolve<CacheManager>())); Mocker.SetConstant<ICreateManagedWebProxy>(new ManagedWebProxyFactory(Mocker.Resolve<CacheManager>()));
Mocker.SetConstant<ICertificateValidationService>(new X509CertificateValidationService(Mocker.Resolve<ConfigService>(), TestLogger)); Mocker.SetConstant<ICertificateValidationService>(new X509CertificateValidationService(Mocker.Resolve<ConfigService>(), TestLogger));
Mocker.SetConstant<IHttpDispatcher>(new ManagedHttpDispatcher(Mocker.Resolve<IHttpProxySettingsProvider>(), Mocker.Resolve<ICreateManagedWebProxy>(), Mocker.Resolve<ICertificateValidationService>(), Mocker.Resolve<UserAgentBuilder>(), Mocker.Resolve<CacheManager>(), TestLogger)); Mocker.SetConstant<IHttpDispatcher>(new ManagedHttpDispatcher(Mocker.Resolve<IHttpProxySettingsProvider>(), Mocker.Resolve<ICreateManagedWebProxy>(), Mocker.Resolve<ICertificateValidationService>(), Mocker.Resolve<UserAgentBuilder>(), Mocker.Resolve<CacheManager>(), TestLogger));
Mocker.SetConstant<IHttpClient>(new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve<CacheManager>(), Mocker.Resolve<RateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.Resolve<UserAgentBuilder>(), TestLogger)); Mocker.SetConstant<IHttpClient>(new HttpClient(Array.Empty<IHttpRequestInterceptor>(), Mocker.Resolve<CacheManager>(), Mocker.Resolve<RateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.Resolve<UserAgentBuilder>(), TestLogger));
Mocker.SetConstant<ISonarrCloudRequestBuilder>(new SonarrCloudRequestBuilder()); Mocker.SetConstant<ISonarrCloudRequestBuilder>(new SonarrCloudRequestBuilder());
} }
} }

View File

@ -16,7 +16,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
{ {
Mocker.GetMock<IProvideDownloadClient>() Mocker.GetMock<IProvideDownloadClient>()
.Setup(s => s.GetDownloadClients()) .Setup(s => s.GetDownloadClients())
.Returns(new IDownloadClient[0]); .Returns(Array.Empty<IDownloadClient>());
Subject.Check().ShouldBeWarning(); Subject.Check().ShouldBeWarning();
} }

View File

@ -76,7 +76,7 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests
{ {
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(v => v.Execute(It.IsAny<HttpRequest>())) .Setup(v => v.Execute(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0], System.Net.HttpStatusCode.BadRequest)); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>(), System.Net.HttpStatusCode.BadRequest));
var results = Subject.FetchRecent(); var results = Subject.FetchRecent();
@ -92,7 +92,7 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests
{ {
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(v => v.Execute(It.IsAny<HttpRequest>())) .Setup(v => v.Execute(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0], System.Net.HttpStatusCode.Unauthorized)); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>(), System.Net.HttpStatusCode.Unauthorized));
var results = Subject.FetchRecent(); var results = Subject.FetchRecent();
@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests
{ {
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(v => v.Execute(It.IsAny<HttpRequest>())) .Setup(v => v.Execute(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0], System.Net.HttpStatusCode.NotFound)); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>(), System.Net.HttpStatusCode.NotFound));
var results = Subject.FetchRecent(); var results = Subject.FetchRecent();
@ -124,7 +124,7 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests
{ {
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(v => v.Execute(It.IsAny<HttpRequest>())) .Setup(v => v.Execute(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0], System.Net.HttpStatusCode.ServiceUnavailable)); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>(), System.Net.HttpStatusCode.ServiceUnavailable));
var results = Subject.FetchRecent(); var results = Subject.FetchRecent();

View File

@ -115,7 +115,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
public void should_record_indexer_failure_if_caps_throw() public void should_record_indexer_failure_if_caps_throw()
{ {
var request = new HttpRequest("http://my.indexer.com"); var request = new HttpRequest("http://my.indexer.com");
var response = new HttpResponse(request, new HttpHeader(), new byte[0], (HttpStatusCode)429); var response = new HttpResponse(request, new HttpHeader(), Array.Empty<byte>(), (HttpStatusCode)429);
response.Headers["Retry-After"] = "300"; response.Headers["Retry-After"] = "300";
Mocker.GetMock<INewznabCapabilitiesProvider>() Mocker.GetMock<INewznabCapabilitiesProvider>()

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -91,7 +92,7 @@ namespace NzbDrone.Core.Test.MediaFiles
private void WasImportedResponse() private void WasImportedResponse()
{ {
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>())) Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new string[0]); .Returns(Array.Empty<string>());
} }
[Test] [Test]
@ -140,7 +141,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDiskScanService>() Mocker.GetMock<IDiskScanService>()
.Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>())) .Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new string[0]); .Returns(Array.Empty<string>());
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory)); Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));

View File

@ -1,3 +1,4 @@
using System;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
@ -84,7 +85,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
public void should_should_be_accepted_for_full_season() public void should_should_be_accepted_for_full_season()
{ {
_localEpisode.Path = @"C:\Test\Unsorted\Series.Title.S01\S01E01.mkv".AsOsAgnostic(); _localEpisode.Path = @"C:\Test\Unsorted\Series.Title.S01\S01E01.mkv".AsOsAgnostic();
_localEpisode.FolderEpisodeInfo.EpisodeNumbers = new int[0]; _localEpisode.FolderEpisodeInfo.EpisodeNumbers = Array.Empty<int>();
_localEpisode.FolderEpisodeInfo.FullSeason = true; _localEpisode.FolderEpisodeInfo.FullSeason = true;
GivenEpisodes(_localEpisode.FileEpisodeInfo, _localEpisode.FileEpisodeInfo.EpisodeNumbers); GivenEpisodes(_localEpisode.FileEpisodeInfo, _localEpisode.FileEpisodeInfo.EpisodeNumbers);

View File

@ -1,3 +1,4 @@
using System;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
@ -104,9 +105,9 @@ namespace NzbDrone.Core.Test.NotificationTests.EmailTests
[Test] [Test]
public void should_not_be_valid_if_to_bcc_cc_are_all_empty() public void should_not_be_valid_if_to_bcc_cc_are_all_empty()
{ {
_emailSettings.To = new string[] { }; _emailSettings.To = Array.Empty<string>();
_emailSettings.Cc = new string[] { }; _emailSettings.Cc = Array.Empty<string>();
_emailSettings.Bcc = new string[] { }; _emailSettings.Bcc = Array.Empty<string>();
_validator.Validate(_emailSettings).IsValid.Should().BeFalse(); _validator.Validate(_emailSettings).IsValid.Should().BeFalse();
} }

View File

@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
SeriesTitle = _series.Title, SeriesTitle = _series.Title,
SeasonNumber = 1, SeasonNumber = 1,
EpisodeNumbers = new[] { 1 }, EpisodeNumbers = new[] { 1 },
AbsoluteEpisodeNumbers = new int[0], AbsoluteEpisodeNumbers = Array.Empty<int>(),
Languages = new List<Language> { Language.English } Languages = new List<Language> { Language.English }
}; };
@ -282,7 +282,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
{ {
GivenAbsoluteNumberingSeries(); GivenAbsoluteNumberingSeries();
_parsedEpisodeInfo.SeasonNumber = seasonNumber; _parsedEpisodeInfo.SeasonNumber = seasonNumber;
_parsedEpisodeInfo.EpisodeNumbers = new int[] { }; _parsedEpisodeInfo.EpisodeNumbers = Array.Empty<int>();
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Setup(s => s.FindEpisodesBySceneNumbering(It.IsAny<int>(), seasonNumber, It.IsAny<int>())) .Setup(s => s.FindEpisodesBySceneNumbering(It.IsAny<int>(), seasonNumber, It.IsAny<int>()))
@ -303,7 +303,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
{ {
GivenAbsoluteNumberingSeries(); GivenAbsoluteNumberingSeries();
_parsedEpisodeInfo.SeasonNumber = seasonNumber; _parsedEpisodeInfo.SeasonNumber = seasonNumber;
_parsedEpisodeInfo.EpisodeNumbers = new int[] { }; _parsedEpisodeInfo.EpisodeNumbers = Array.Empty<int>();
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Setup(s => s.FindEpisodesBySceneNumbering(It.IsAny<int>(), seasonNumber, It.IsAny<int>())) .Setup(s => s.FindEpisodesBySceneNumbering(It.IsAny<int>(), seasonNumber, It.IsAny<int>()))

View File

@ -192,7 +192,7 @@ namespace NzbDrone.Core.DecisionEngine
private DownloadDecision GetDecisionForReport(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria = null) private DownloadDecision GetDecisionForReport(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria = null)
{ {
var reasons = new Rejection[0]; var reasons = Array.Empty<Rejection>();
foreach (var specifications in _specifications.GroupBy(v => v.Priority).OrderBy(v => v.Key)) foreach (var specifications in _specifications.GroupBy(v => v.Priority).OrderBy(v => v.Key))
{ {

View File

@ -354,7 +354,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
{ {
if (result.Torrents == null) if (result.Torrents == null)
{ {
return new DelugeTorrent[0]; return Array.Empty<DelugeTorrent>();
} }
return result.Torrents.Values.ToArray(); return result.Torrents.Values.ToArray();

View File

@ -112,7 +112,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
{ {
if (torrentsRaw == null) if (torrentsRaw == null)
{ {
return new HadoukenTorrent[0]; return Array.Empty<HadoukenTorrent>();
} }
var torrents = new List<HadoukenTorrent>(); var torrents = new List<HadoukenTorrent>();

View File

@ -1,4 +1,5 @@
using NzbDrone.Core.Indexers; using System;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Download.TrackedDownloads namespace NzbDrone.Core.Download.TrackedDownloads
@ -18,7 +19,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
public TrackedDownload() public TrackedDownload()
{ {
StatusMessages = new TrackedDownloadStatusMessage[] { }; StatusMessages = Array.Empty<TrackedDownloadStatusMessage>();
} }
public void Warn(string message, params object[] args) public void Warn(string message, params object[] args)

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using FluentValidation; using FluentValidation;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
@ -22,9 +23,9 @@ namespace NzbDrone.Core.ImportLists.Sonarr
{ {
BaseUrl = ""; BaseUrl = "";
ApiKey = ""; ApiKey = "";
ProfileIds = new int[] { }; ProfileIds = Array.Empty<int>();
LanguageProfileIds = new int[] { }; LanguageProfileIds = Array.Empty<int>();
TagIds = new int[] { }; TagIds = Array.Empty<int>();
} }
[FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Sonarr V3 instance to import from")] [FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Sonarr V3 instance to import from")]

View File

@ -1,4 +1,5 @@
using System.Collections.Concurrent; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using FluentValidation; using FluentValidation;
@ -36,7 +37,7 @@ namespace NzbDrone.Core.Indexers.FileList
(int)FileListCategories.TV_4K (int)FileListCategories.TV_4K
}; };
AnimeCategories = new int[0]; AnimeCategories = Array.Empty<int>();
} }
[FieldDefinition(0, Label = "Username", Privacy = PrivacyLevel.UserName)] [FieldDefinition(0, Label = "Username", Privacy = PrivacyLevel.UserName)]

View File

@ -51,7 +51,7 @@ namespace NzbDrone.Core.Indexers.Newznab
yield return GetDefinition("OZnzb.com", GetSettings("https://api.oznzb.com")); yield return GetDefinition("OZnzb.com", GetSettings("https://api.oznzb.com"));
yield return GetDefinition("SimplyNZBs", GetSettings("https://simplynzbs.com")); yield return GetDefinition("SimplyNZBs", GetSettings("https://simplynzbs.com"));
yield return GetDefinition("Tabula Rasa", GetSettings("https://www.tabula-rasa.pw", apiPath: @"/api/v1/api")); yield return GetDefinition("Tabula Rasa", GetSettings("https://www.tabula-rasa.pw", apiPath: @"/api/v1/api"));
yield return GetDefinition("AnimeTosho Usenet", GetSettings("https://feed.animetosho.org", apiPath: @"/nabapi", categories: new int[0], animeCategories: new[] { 5070 })); yield return GetDefinition("AnimeTosho Usenet", GetSettings("https://feed.animetosho.org", apiPath: @"/nabapi", categories: Array.Empty<int>(), animeCategories: new[] { 5070 }));
} }
} }

View File

@ -41,8 +41,8 @@ namespace NzbDrone.Core.Indexers.Torznab
get get
{ {
yield return GetDefinition("HD4Free.xyz", GetSettings("http://hd4free.xyz")); yield return GetDefinition("HD4Free.xyz", GetSettings("http://hd4free.xyz"));
yield return GetDefinition("AnimeTosho Torrents", GetSettings("https://feed.animetosho.org", apiPath: @"/nabapi", categories: new int[0], animeCategories: new[] { 5070 })); yield return GetDefinition("AnimeTosho Torrents", GetSettings("https://feed.animetosho.org", apiPath: @"/nabapi", categories: Array.Empty<int>(), animeCategories: new[] { 5070 }));
yield return GetDefinition("Nyaa Pantsu", GetSettings("https://nyaa.pantsu.cat", apiPath: @"/feed/torznab", categories: new int[0], animeCategories: new[] { 5070 })); yield return GetDefinition("Nyaa Pantsu", GetSettings("https://nyaa.pantsu.cat", apiPath: @"/feed/torznab", categories: Array.Empty<int>(), animeCategories: new[] { 5070 }));
} }
} }

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using FluentValidation; using FluentValidation;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
@ -22,7 +23,7 @@ namespace NzbDrone.Core.Notifications.Mailgun
public MailgunSettings() public MailgunSettings()
{ {
Recipients = new string[] { }; Recipients = Array.Empty<string>();
} }
[FieldDefinition(0, Label = "API Key", HelpText = "The API key generated from MailGun")] [FieldDefinition(0, Label = "API Key", HelpText = "The API key generated from MailGun")]

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using FluentValidation; using FluentValidation;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
@ -20,8 +21,8 @@ namespace NzbDrone.Core.Notifications.PushBullet
public PushBulletSettings() public PushBulletSettings()
{ {
DeviceIds = new string[] { }; DeviceIds = Array.Empty<string>();
ChannelTags = new string[] { }; ChannelTags = Array.Empty<string>();
} }
[FieldDefinition(0, Label = "Access Token", Privacy = PrivacyLevel.ApiKey, HelpLink = "https://www.pushbullet.com/#settings/account")] [FieldDefinition(0, Label = "Access Token", Privacy = PrivacyLevel.ApiKey, HelpLink = "https://www.pushbullet.com/#settings/account")]

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using FluentValidation; using FluentValidation;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
@ -23,7 +24,7 @@ namespace NzbDrone.Core.Notifications.Pushover
public PushoverSettings() public PushoverSettings()
{ {
Priority = 0; Priority = 0;
Devices = new string[] { }; Devices = Array.Empty<string>();
} }
// TODO: Get Pushover to change our app name (or create a new app) when we have a new logo // TODO: Get Pushover to change our app name (or create a new app) when we have a new logo

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using FluentValidation; using FluentValidation;
using NzbDrone.Core.Annotations; using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
@ -24,7 +25,7 @@ namespace NzbDrone.Core.Notifications.SendGrid
public SendGridSettings() public SendGridSettings()
{ {
BaseUrl = "https://api.sendgrid.com/v3/"; BaseUrl = "https://api.sendgrid.com/v3/";
Recipients = new string[] { }; Recipients = Array.Empty<string>();
} }
public string BaseUrl { get; set; } public string BaseUrl { get; set; }

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@ -32,9 +33,9 @@ namespace NzbDrone.Core.Parser.Model
public ParsedEpisodeInfo() public ParsedEpisodeInfo()
{ {
EpisodeNumbers = new int[0]; EpisodeNumbers = Array.Empty<int>();
AbsoluteEpisodeNumbers = new int[0]; AbsoluteEpisodeNumbers = Array.Empty<int>();
SpecialAbsoluteEpisodeNumbers = new decimal[0]; SpecialAbsoluteEpisodeNumbers = Array.Empty<decimal>();
Languages = new List<Language>(); Languages = new List<Language>();
} }

View File

@ -890,8 +890,8 @@ namespace NzbDrone.Core.Parser
result = new ParsedEpisodeInfo result = new ParsedEpisodeInfo
{ {
ReleaseTitle = releaseTitle, ReleaseTitle = releaseTitle,
EpisodeNumbers = new int[0], EpisodeNumbers = Array.Empty<int>(),
AbsoluteEpisodeNumbers = new int[0] AbsoluteEpisodeNumbers = Array.Empty<int>()
}; };
foreach (Match matchGroup in matchCollection) foreach (Match matchGroup in matchCollection)

View File

@ -126,7 +126,7 @@ namespace NzbDrone.Host
c.AddSecurityRequirement(new OpenApiSecurityRequirement c.AddSecurityRequirement(new OpenApiSecurityRequirement
{ {
{ apiKeyHeader, new string[] { } } { apiKeyHeader, Array.Empty<string>() }
}); });
var apikeyQuery = new OpenApiSecurityScheme var apikeyQuery = new OpenApiSecurityScheme
@ -157,7 +157,7 @@ namespace NzbDrone.Host
c.AddSecurityRequirement(new OpenApiSecurityRequirement c.AddSecurityRequirement(new OpenApiSecurityRequirement
{ {
{ apikeyQuery, new string[] { } } { apikeyQuery, Array.Empty<string>() }
}); });
}); });

View File

@ -49,8 +49,8 @@ namespace NzbDrone.RuntimePatches.Mono
Instance.DebugOpcodes("Before", codes); Instance.DebugOpcodes("Before", codes);
var targetType = method.DeclaringType; var targetType = method.DeclaringType;
var copyMethod = targetType.GetMethod("Copy", new Type[0]); var copyMethod = targetType.GetMethod("Copy", Array.Empty<Type>());
var disposeMethod = targetType.GetMethod("Dispose", new Type[0]); var disposeMethod = targetType.GetMethod("Dispose", Array.Empty<Type>());
var setFlagsMethod = targetType.GetMethod("SetFlags", new[] { typeof(ulong) }); var setFlagsMethod = targetType.GetMethod("SetFlags", new[] { typeof(ulong) });
if (patchable && copyMethod != null && disposeMethod != null && setFlagsMethod != null) if (patchable && copyMethod != null && disposeMethod != null && setFlagsMethod != null)