From 0ed8ba828d86b2a684e078dab40910d08f707b23 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 9 Jan 2023 21:59:55 -0600 Subject: [PATCH] Avoid unnecessary zero-length array allocations --- .editorconfig | 1 - .../EnvironmentTests/StartupArgumentsFixture.cs | 3 ++- src/NzbDrone.Common.Test/Http/HttpClientFixture.cs | 4 ++-- src/NzbDrone.Common/Http/HttpResponse.cs | 2 +- .../DownloadClientTests/DelugeTests/DelugeFixture.cs | 2 +- .../DownloadClientTests/DownloadClientFixtureBase.cs | 2 +- .../DownloadStationTests/TorrentDownloadStationFixture.cs | 2 +- .../DownloadStationTests/UsenetDownloadStationFixture.cs | 2 +- .../FreeboxDownloadTests/TorrentFreeboxDownloadFixture.cs | 2 +- .../DownloadClientTests/HadoukenTests/HadoukenFixture.cs | 2 +- .../QBittorrentTests/QBittorrentFixture.cs | 8 ++++---- .../DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs | 2 +- .../TransmissionTests/TransmissionFixtureBase.cs | 2 +- .../DownloadClientTests/UTorrentTests/UTorrentFixture.cs | 6 +++--- src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs | 4 ++-- src/NzbDrone.Core.Test/Framework/CoreTest.cs | 2 +- .../HealthCheck/Checks/DownloadClientCheckFixture.cs | 2 +- .../BroadcastheNetTests/BroadcastheNetFixture.cs | 8 ++++---- .../IndexerTests/NewznabTests/NewznabFixture.cs | 2 +- .../MediaFiles/DownloadedEpisodesImportServiceFixture.cs | 5 +++-- .../Specifications/MatchesFolderSpecificationFixture.cs | 3 ++- .../EmailTests/EmailSettingsValidatorFixture.cs | 7 ++++--- .../ParserTests/ParsingServiceTests/GetEpisodesFixture.cs | 6 +++--- src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs | 2 +- src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs | 2 +- .../Download/Clients/Hadouken/HadoukenProxy.cs | 2 +- .../Download/TrackedDownloads/TrackedDownload.cs | 5 +++-- src/NzbDrone.Core/ImportLists/Sonarr/SonarrSettings.cs | 7 ++++--- src/NzbDrone.Core/Indexers/FileList/FileListSettings.cs | 5 +++-- src/NzbDrone.Core/Indexers/Newznab/Newznab.cs | 2 +- src/NzbDrone.Core/Indexers/Torznab/Torznab.cs | 4 ++-- .../Notifications/Mailgun/MailgunSettings.cs | 3 ++- .../Notifications/PushBullet/PushBulletSettings.cs | 5 +++-- .../Notifications/Pushover/PushoverSettings.cs | 3 ++- .../Notifications/SendGrid/SendGridSettings.cs | 5 +++-- src/NzbDrone.Core/Parser/Model/ParsedEpisodeInfo.cs | 7 ++++--- src/NzbDrone.Core/Parser/Parser.cs | 4 ++-- src/NzbDrone.Host/Startup.cs | 4 ++-- .../Mono/BoringTLSVerifyFlagsPatch.cs | 4 ++-- 39 files changed, 77 insertions(+), 66 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2afbdde32..58a294dc1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -194,7 +194,6 @@ dotnet_diagnostic.CA1819.severity = suggestion dotnet_diagnostic.CA1822.severity = suggestion dotnet_diagnostic.CA1823.severity = suggestion dotnet_diagnostic.CA1824.severity = suggestion -dotnet_diagnostic.CA1825.severity = suggestion dotnet_diagnostic.CA1826.severity = suggestion dotnet_diagnostic.CA1827.severity = suggestion dotnet_diagnostic.CA1829.severity = suggestion diff --git a/src/NzbDrone.Common.Test/EnvironmentTests/StartupArgumentsFixture.cs b/src/NzbDrone.Common.Test/EnvironmentTests/StartupArgumentsFixture.cs index 07df9c79e..f53dfee9a 100644 --- a/src/NzbDrone.Common.Test/EnvironmentTests/StartupArgumentsFixture.cs +++ b/src/NzbDrone.Common.Test/EnvironmentTests/StartupArgumentsFixture.cs @@ -1,3 +1,4 @@ +using System; using FluentAssertions; using NUnit.Framework; using NzbDrone.Common.EnvironmentInfo; @@ -11,7 +12,7 @@ namespace NzbDrone.Common.Test.EnvironmentTests [Test] public void empty_array_should_return_empty_flags() { - var args = new StartupContext(new string[0]); + var args = new StartupContext(Array.Empty()); args.Flags.Should().BeEmpty(); } diff --git a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs index 4757f805d..df8ea57ae 100644 --- a/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs +++ b/src/NzbDrone.Common.Test/Http/HttpClientFixture.cs @@ -102,7 +102,7 @@ namespace NzbDrone.Common.Test.Http Mocker.SetConstant(new X509CertificateValidationService(Mocker.GetMock().Object, TestLogger)); Mocker.SetConstant(Mocker.Resolve()); - Mocker.SetConstant>(new IHttpRequestInterceptor[0]); + Mocker.SetConstant>(Array.Empty()); Mocker.SetConstant(Mocker.Resolve()); // Used for manual testing of socks proxies. @@ -459,7 +459,7 @@ namespace NzbDrone.Common.Test.Http var oldRequest = new HttpRequest($"https://{_httpBinHost2}/get"); oldRequest.Cookies["my"] = "cookie"; - var oldClient = new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve(), Mocker.Resolve(), Mocker.Resolve(), Mocker.GetMock().Object, Mocker.Resolve()); + var oldClient = new HttpClient(Array.Empty(), Mocker.Resolve(), Mocker.Resolve(), Mocker.Resolve(), Mocker.GetMock().Object, Mocker.Resolve()); oldClient.Should().NotBeSameAs(Subject); diff --git a/src/NzbDrone.Common/Http/HttpResponse.cs b/src/NzbDrone.Common/Http/HttpResponse.cs index bc4bc2c74..43340c40e 100644 --- a/src/NzbDrone.Common/Http/HttpResponse.cs +++ b/src/NzbDrone.Common/Http/HttpResponse.cs @@ -60,7 +60,7 @@ namespace NzbDrone.Common.Http public string[] GetCookieHeaders() { - return Headers.GetValues("Set-Cookie") ?? new string[0]; + return Headers.GetValues("Set-Cookie") ?? Array.Empty(); } public Dictionary GetCookies() diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DelugeTests/DelugeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DelugeTests/DelugeFixture.cs index 52728b3da..f94fff6ea 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DelugeTests/DelugeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DelugeTests/DelugeFixture.cs @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0])); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); } protected void GivenFailedDownload() diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs index f3e341475..2ba48a0bb 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadClientFixtureBase.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0])); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); Mocker.GetMock() .Setup(v => v.RemapRemoteToLocal(It.IsAny(), It.IsAny())) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs index 609f4a97b..ecc1b5c8d 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs @@ -277,7 +277,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0])); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); _downloadStationConfigItems = new Dictionary { diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs index f7e618bb0..fbf06df35 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs @@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0])); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); _downloadStationConfigItems = new Dictionary { diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/FreeboxDownloadTests/TorrentFreeboxDownloadFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/FreeboxDownloadTests/TorrentFreeboxDownloadFixture.cs index 2549644e3..4521b50b9 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/FreeboxDownloadTests/TorrentFreeboxDownloadFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/FreeboxDownloadTests/TorrentFreeboxDownloadFixture.cs @@ -79,7 +79,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0])); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); } protected void GivenCategory() diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/HadoukenTests/HadoukenFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/HadoukenTests/HadoukenFixture.cs index b7650b4cb..1b08dfdda 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/HadoukenTests/HadoukenFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/HadoukenTests/HadoukenFixture.cs @@ -86,7 +86,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0])); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); } protected void GivenFailedDownload() diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs index 88359e456..004dc7ff0 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs @@ -38,7 +38,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0])); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); Mocker.GetMock() .Setup(s => s.GetConfig(It.IsAny())) @@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.SeeOther)); + .Returns(r => new HttpResponse(r, httpHeader, Array.Empty(), System.Net.HttpStatusCode.SeeOther)); } protected void GivenRedirectToTorrent() @@ -66,7 +66,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests Mocker.GetMock() .Setup(s => s.Get(It.Is(h => h.Url.FullUri == _downloadUrl))) - .Returns(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.Found)); + .Returns(r => new HttpResponse(r, httpHeader, Array.Empty(), System.Net.HttpStatusCode.Found)); } protected void GivenFailedDownload() @@ -523,7 +523,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests Mocker.GetMock() .Setup(v => v.MoveTorrentToTopInQueue(It.IsAny(), It.IsAny())) - .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(), System.Net.HttpStatusCode.Forbidden))); var remoteEpisode = CreateRemoteEpisode(); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 5761ab84d..6597410b8 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -545,7 +545,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests public void should_test_failed_if_tv_sorting_empty() { _config.Misc.enable_tv_sorting = true; - _config.Misc.tv_categories = new string[0]; + _config.Misc.tv_categories = Array.Empty(); var result = new NzbDroneValidationResult(Subject.Test()); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/TransmissionTests/TransmissionFixtureBase.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/TransmissionTests/TransmissionFixtureBase.cs index a90b787f9..5cfb3acf6 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/TransmissionTests/TransmissionFixtureBase.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/TransmissionTests/TransmissionFixtureBase.cs @@ -99,7 +99,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0])); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); _transmissionConfigItems = new Dictionary(); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/UTorrentTests/UTorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/UTorrentTests/UTorrentFixture.cs index 97ce9ed0a..5a7e8b432 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/UTorrentTests/UTorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/UTorrentTests/UTorrentFixture.cs @@ -91,7 +91,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0])); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty())); } protected void GivenRedirectToMagnet() @@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) - .Returns(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.SeeOther)); + .Returns(r => new HttpResponse(r, httpHeader, Array.Empty(), System.Net.HttpStatusCode.SeeOther)); } protected void GivenRedirectToTorrent() @@ -111,7 +111,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests Mocker.GetMock() .Setup(s => s.Get(It.Is(h => h.Url.ToString() == _downloadUrl))) - .Returns(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.Found)); + .Returns(r => new HttpResponse(r, httpHeader, Array.Empty(), System.Net.HttpStatusCode.Found)); } protected void GivenFailedDownload() diff --git a/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs index 42319d4a2..da9411d0f 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs @@ -132,7 +132,7 @@ namespace NzbDrone.Core.Test.Download public void Download_report_should_trigger_indexer_backoff_on_http429_with_long_time() { 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(), (HttpStatusCode)429); response.Headers["Retry-After"] = "300"; 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() { 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(), (HttpStatusCode)429); response.Headers["Retry-After"] = DateTime.UtcNow.AddSeconds(300).ToString("r"); var mock = WithUsenetClient(); diff --git a/src/NzbDrone.Core.Test/Framework/CoreTest.cs b/src/NzbDrone.Core.Test/Framework/CoreTest.cs index 5481e1f4e..f3424807e 100644 --- a/src/NzbDrone.Core.Test/Framework/CoreTest.cs +++ b/src/NzbDrone.Core.Test/Framework/CoreTest.cs @@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.Framework Mocker.SetConstant(new ManagedWebProxyFactory(Mocker.Resolve())); Mocker.SetConstant(new X509CertificateValidationService(Mocker.Resolve(), TestLogger)); Mocker.SetConstant(new ManagedHttpDispatcher(Mocker.Resolve(), Mocker.Resolve(), Mocker.Resolve(), Mocker.Resolve(), Mocker.Resolve(), TestLogger)); - Mocker.SetConstant(new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve(), Mocker.Resolve(), Mocker.Resolve(), Mocker.Resolve(), TestLogger)); + Mocker.SetConstant(new HttpClient(Array.Empty(), Mocker.Resolve(), Mocker.Resolve(), Mocker.Resolve(), Mocker.Resolve(), TestLogger)); Mocker.SetConstant(new SonarrCloudRequestBuilder()); } } diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/DownloadClientCheckFixture.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/DownloadClientCheckFixture.cs index b8ceaaba3..b1eaec369 100644 --- a/src/NzbDrone.Core.Test/HealthCheck/Checks/DownloadClientCheckFixture.cs +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/DownloadClientCheckFixture.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks { Mocker.GetMock() .Setup(s => s.GetDownloadClients()) - .Returns(new IDownloadClient[0]); + .Returns(Array.Empty()); Subject.Check().ShouldBeWarning(); } diff --git a/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs index 40e9cedd5..8b95bb560 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs @@ -76,7 +76,7 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests { Mocker.GetMock() .Setup(v => v.Execute(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0], System.Net.HttpStatusCode.BadRequest)); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty(), System.Net.HttpStatusCode.BadRequest)); var results = Subject.FetchRecent(); @@ -92,7 +92,7 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests { Mocker.GetMock() .Setup(v => v.Execute(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0], System.Net.HttpStatusCode.Unauthorized)); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty(), System.Net.HttpStatusCode.Unauthorized)); var results = Subject.FetchRecent(); @@ -108,7 +108,7 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests { Mocker.GetMock() .Setup(v => v.Execute(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0], System.Net.HttpStatusCode.NotFound)); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty(), System.Net.HttpStatusCode.NotFound)); var results = Subject.FetchRecent(); @@ -124,7 +124,7 @@ namespace NzbDrone.Core.Test.IndexerTests.BroadcastheNetTests { Mocker.GetMock() .Setup(v => v.Execute(It.IsAny())) - .Returns(r => new HttpResponse(r, new HttpHeader(), new byte[0], System.Net.HttpStatusCode.ServiceUnavailable)); + .Returns(r => new HttpResponse(r, new HttpHeader(), Array.Empty(), System.Net.HttpStatusCode.ServiceUnavailable)); var results = Subject.FetchRecent(); diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs index 7840e4253..b67d35c64 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs @@ -115,7 +115,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests public void should_record_indexer_failure_if_caps_throw() { 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(), (HttpStatusCode)429); response.Headers["Retry-After"] = "300"; Mocker.GetMock() diff --git a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs index f75b4d5e0..be8ade27e 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -91,7 +92,7 @@ namespace NzbDrone.Core.Test.MediaFiles private void WasImportedResponse() { Mocker.GetMock().Setup(c => c.GetVideoFiles(It.IsAny(), It.IsAny())) - .Returns(new string[0]); + .Returns(Array.Empty()); } [Test] @@ -140,7 +141,7 @@ namespace NzbDrone.Core.Test.MediaFiles Mocker.GetMock() .Setup(c => c.GetVideoFiles(It.IsAny(), It.IsAny())) - .Returns(new string[0]); + .Returns(Array.Empty()); Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory)); diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/MatchesFolderSpecificationFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/MatchesFolderSpecificationFixture.cs index 5fee6a979..1ed999597 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/MatchesFolderSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/MatchesFolderSpecificationFixture.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using FizzWare.NBuilder; using FluentAssertions; @@ -84,7 +85,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications public void should_should_be_accepted_for_full_season() { _localEpisode.Path = @"C:\Test\Unsorted\Series.Title.S01\S01E01.mkv".AsOsAgnostic(); - _localEpisode.FolderEpisodeInfo.EpisodeNumbers = new int[0]; + _localEpisode.FolderEpisodeInfo.EpisodeNumbers = Array.Empty(); _localEpisode.FolderEpisodeInfo.FullSeason = true; GivenEpisodes(_localEpisode.FileEpisodeInfo, _localEpisode.FileEpisodeInfo.EpisodeNumbers); diff --git a/src/NzbDrone.Core.Test/NotificationTests/EmailTests/EmailSettingsValidatorFixture.cs b/src/NzbDrone.Core.Test/NotificationTests/EmailTests/EmailSettingsValidatorFixture.cs index e5d1b2bc6..b80e32ec1 100644 --- a/src/NzbDrone.Core.Test/NotificationTests/EmailTests/EmailSettingsValidatorFixture.cs +++ b/src/NzbDrone.Core.Test/NotificationTests/EmailTests/EmailSettingsValidatorFixture.cs @@ -1,3 +1,4 @@ +using System; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; @@ -104,9 +105,9 @@ namespace NzbDrone.Core.Test.NotificationTests.EmailTests [Test] public void should_not_be_valid_if_to_bcc_cc_are_all_empty() { - _emailSettings.To = new string[] { }; - _emailSettings.Cc = new string[] { }; - _emailSettings.Bcc = new string[] { }; + _emailSettings.To = Array.Empty(); + _emailSettings.Cc = Array.Empty(); + _emailSettings.Bcc = Array.Empty(); _validator.Validate(_emailSettings).IsValid.Should().BeFalse(); } diff --git a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetEpisodesFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetEpisodesFixture.cs index 1dd3940c5..77c726fa8 100644 --- a/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetEpisodesFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/ParsingServiceTests/GetEpisodesFixture.cs @@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests SeriesTitle = _series.Title, SeasonNumber = 1, EpisodeNumbers = new[] { 1 }, - AbsoluteEpisodeNumbers = new int[0], + AbsoluteEpisodeNumbers = Array.Empty(), Languages = new List { Language.English } }; @@ -282,7 +282,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { GivenAbsoluteNumberingSeries(); _parsedEpisodeInfo.SeasonNumber = seasonNumber; - _parsedEpisodeInfo.EpisodeNumbers = new int[] { }; + _parsedEpisodeInfo.EpisodeNumbers = Array.Empty(); Mocker.GetMock() .Setup(s => s.FindEpisodesBySceneNumbering(It.IsAny(), seasonNumber, It.IsAny())) @@ -303,7 +303,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests { GivenAbsoluteNumberingSeries(); _parsedEpisodeInfo.SeasonNumber = seasonNumber; - _parsedEpisodeInfo.EpisodeNumbers = new int[] { }; + _parsedEpisodeInfo.EpisodeNumbers = Array.Empty(); Mocker.GetMock() .Setup(s => s.FindEpisodesBySceneNumbering(It.IsAny(), seasonNumber, It.IsAny())) diff --git a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index 78c4a6c65..aaa9ac392 100644 --- a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -192,7 +192,7 @@ namespace NzbDrone.Core.DecisionEngine private DownloadDecision GetDecisionForReport(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria = null) { - var reasons = new Rejection[0]; + var reasons = Array.Empty(); foreach (var specifications in _specifications.GroupBy(v => v.Priority).OrderBy(v => v.Key)) { diff --git a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs index 0bac88e16..6ab45ec40 100644 --- a/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Deluge/DelugeProxy.cs @@ -354,7 +354,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge { if (result.Torrents == null) { - return new DelugeTorrent[0]; + return Array.Empty(); } return result.Torrents.Values.ToArray(); diff --git a/src/NzbDrone.Core/Download/Clients/Hadouken/HadoukenProxy.cs b/src/NzbDrone.Core/Download/Clients/Hadouken/HadoukenProxy.cs index ec0dd1ffe..5dd548e5a 100644 --- a/src/NzbDrone.Core/Download/Clients/Hadouken/HadoukenProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Hadouken/HadoukenProxy.cs @@ -112,7 +112,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken { if (torrentsRaw == null) { - return new HadoukenTorrent[0]; + return Array.Empty(); } var torrents = new List(); diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownload.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownload.cs index 1cbf0d327..2dfd4baee 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownload.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownload.cs @@ -1,4 +1,5 @@ -using NzbDrone.Core.Indexers; +using System; +using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Download.TrackedDownloads @@ -18,7 +19,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads public TrackedDownload() { - StatusMessages = new TrackedDownloadStatusMessage[] { }; + StatusMessages = Array.Empty(); } public void Warn(string message, params object[] args) diff --git a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrSettings.cs b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrSettings.cs index 3b607a2cf..5e7655f12 100644 --- a/src/NzbDrone.Core/ImportLists/Sonarr/SonarrSettings.cs +++ b/src/NzbDrone.Core/ImportLists/Sonarr/SonarrSettings.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; @@ -22,9 +23,9 @@ namespace NzbDrone.Core.ImportLists.Sonarr { BaseUrl = ""; ApiKey = ""; - ProfileIds = new int[] { }; - LanguageProfileIds = new int[] { }; - TagIds = new int[] { }; + ProfileIds = Array.Empty(); + LanguageProfileIds = Array.Empty(); + TagIds = Array.Empty(); } [FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Sonarr V3 instance to import from")] diff --git a/src/NzbDrone.Core/Indexers/FileList/FileListSettings.cs b/src/NzbDrone.Core/Indexers/FileList/FileListSettings.cs index 00a1358bf..8b99055d5 100644 --- a/src/NzbDrone.Core/Indexers/FileList/FileListSettings.cs +++ b/src/NzbDrone.Core/Indexers/FileList/FileListSettings.cs @@ -1,4 +1,5 @@ -using System.Collections.Concurrent; +using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using FluentValidation; @@ -36,7 +37,7 @@ namespace NzbDrone.Core.Indexers.FileList (int)FileListCategories.TV_4K }; - AnimeCategories = new int[0]; + AnimeCategories = Array.Empty(); } [FieldDefinition(0, Label = "Username", Privacy = PrivacyLevel.UserName)] diff --git a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 79115bd26..12c09ce0a 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -51,7 +51,7 @@ namespace NzbDrone.Core.Indexers.Newznab yield return GetDefinition("OZnzb.com", GetSettings("https://api.oznzb.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("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(), animeCategories: new[] { 5070 })); } } diff --git a/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs b/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs index 48d6386b5..299d0e4a8 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/Torznab.cs @@ -41,8 +41,8 @@ namespace NzbDrone.Core.Indexers.Torznab get { 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("Nyaa Pantsu", GetSettings("https://nyaa.pantsu.cat", apiPath: @"/feed/torznab", categories: new int[0], animeCategories: new[] { 5070 })); + yield return GetDefinition("AnimeTosho Torrents", GetSettings("https://feed.animetosho.org", apiPath: @"/nabapi", categories: Array.Empty(), animeCategories: new[] { 5070 })); + yield return GetDefinition("Nyaa Pantsu", GetSettings("https://nyaa.pantsu.cat", apiPath: @"/feed/torznab", categories: Array.Empty(), animeCategories: new[] { 5070 })); } } diff --git a/src/NzbDrone.Core/Notifications/Mailgun/MailgunSettings.cs b/src/NzbDrone.Core/Notifications/Mailgun/MailgunSettings.cs index b09824ac3..181de5faa 100644 --- a/src/NzbDrone.Core/Notifications/Mailgun/MailgunSettings.cs +++ b/src/NzbDrone.Core/Notifications/Mailgun/MailgunSettings.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; @@ -22,7 +23,7 @@ namespace NzbDrone.Core.Notifications.Mailgun public MailgunSettings() { - Recipients = new string[] { }; + Recipients = Array.Empty(); } [FieldDefinition(0, Label = "API Key", HelpText = "The API key generated from MailGun")] diff --git a/src/NzbDrone.Core/Notifications/PushBullet/PushBulletSettings.cs b/src/NzbDrone.Core/Notifications/PushBullet/PushBulletSettings.cs index 0203c7d95..d4e9d0661 100644 --- a/src/NzbDrone.Core/Notifications/PushBullet/PushBulletSettings.cs +++ b/src/NzbDrone.Core/Notifications/PushBullet/PushBulletSettings.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; @@ -20,8 +21,8 @@ namespace NzbDrone.Core.Notifications.PushBullet public PushBulletSettings() { - DeviceIds = new string[] { }; - ChannelTags = new string[] { }; + DeviceIds = Array.Empty(); + ChannelTags = Array.Empty(); } [FieldDefinition(0, Label = "Access Token", Privacy = PrivacyLevel.ApiKey, HelpLink = "https://www.pushbullet.com/#settings/account")] diff --git a/src/NzbDrone.Core/Notifications/Pushover/PushoverSettings.cs b/src/NzbDrone.Core/Notifications/Pushover/PushoverSettings.cs index 281289573..d84f4873c 100644 --- a/src/NzbDrone.Core/Notifications/Pushover/PushoverSettings.cs +++ b/src/NzbDrone.Core/Notifications/Pushover/PushoverSettings.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; @@ -23,7 +24,7 @@ namespace NzbDrone.Core.Notifications.Pushover public PushoverSettings() { Priority = 0; - Devices = new string[] { }; + Devices = Array.Empty(); } // TODO: Get Pushover to change our app name (or create a new app) when we have a new logo diff --git a/src/NzbDrone.Core/Notifications/SendGrid/SendGridSettings.cs b/src/NzbDrone.Core/Notifications/SendGrid/SendGridSettings.cs index 25b78b9c4..cfd65987c 100644 --- a/src/NzbDrone.Core/Notifications/SendGrid/SendGridSettings.cs +++ b/src/NzbDrone.Core/Notifications/SendGrid/SendGridSettings.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.ThingiProvider; @@ -24,7 +25,7 @@ namespace NzbDrone.Core.Notifications.SendGrid public SendGridSettings() { BaseUrl = "https://api.sendgrid.com/v3/"; - Recipients = new string[] { }; + Recipients = Array.Empty(); } public string BaseUrl { get; set; } diff --git a/src/NzbDrone.Core/Parser/Model/ParsedEpisodeInfo.cs b/src/NzbDrone.Core/Parser/Model/ParsedEpisodeInfo.cs index 35cf41cbe..aed075f2c 100644 --- a/src/NzbDrone.Core/Parser/Model/ParsedEpisodeInfo.cs +++ b/src/NzbDrone.Core/Parser/Model/ParsedEpisodeInfo.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; @@ -32,9 +33,9 @@ namespace NzbDrone.Core.Parser.Model public ParsedEpisodeInfo() { - EpisodeNumbers = new int[0]; - AbsoluteEpisodeNumbers = new int[0]; - SpecialAbsoluteEpisodeNumbers = new decimal[0]; + EpisodeNumbers = Array.Empty(); + AbsoluteEpisodeNumbers = Array.Empty(); + SpecialAbsoluteEpisodeNumbers = Array.Empty(); Languages = new List(); } diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index c3d584d5e..683996f53 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -890,8 +890,8 @@ namespace NzbDrone.Core.Parser result = new ParsedEpisodeInfo { ReleaseTitle = releaseTitle, - EpisodeNumbers = new int[0], - AbsoluteEpisodeNumbers = new int[0] + EpisodeNumbers = Array.Empty(), + AbsoluteEpisodeNumbers = Array.Empty() }; foreach (Match matchGroup in matchCollection) diff --git a/src/NzbDrone.Host/Startup.cs b/src/NzbDrone.Host/Startup.cs index 4226a5e4c..25926d1b4 100644 --- a/src/NzbDrone.Host/Startup.cs +++ b/src/NzbDrone.Host/Startup.cs @@ -126,7 +126,7 @@ namespace NzbDrone.Host c.AddSecurityRequirement(new OpenApiSecurityRequirement { - { apiKeyHeader, new string[] { } } + { apiKeyHeader, Array.Empty() } }); var apikeyQuery = new OpenApiSecurityScheme @@ -157,7 +157,7 @@ namespace NzbDrone.Host c.AddSecurityRequirement(new OpenApiSecurityRequirement { - { apikeyQuery, new string[] { } } + { apikeyQuery, Array.Empty() } }); }); diff --git a/src/Sonarr.RuntimePatches/Mono/BoringTLSVerifyFlagsPatch.cs b/src/Sonarr.RuntimePatches/Mono/BoringTLSVerifyFlagsPatch.cs index bf4e8246a..2db2ec1e0 100644 --- a/src/Sonarr.RuntimePatches/Mono/BoringTLSVerifyFlagsPatch.cs +++ b/src/Sonarr.RuntimePatches/Mono/BoringTLSVerifyFlagsPatch.cs @@ -49,8 +49,8 @@ namespace NzbDrone.RuntimePatches.Mono Instance.DebugOpcodes("Before", codes); var targetType = method.DeclaringType; - var copyMethod = targetType.GetMethod("Copy", new Type[0]); - var disposeMethod = targetType.GetMethod("Dispose", new Type[0]); + var copyMethod = targetType.GetMethod("Copy", Array.Empty()); + var disposeMethod = targetType.GetMethod("Dispose", Array.Empty()); var setFlagsMethod = targetType.GetMethod("SetFlags", new[] { typeof(ulong) }); if (patchable && copyMethod != null && disposeMethod != null && setFlagsMethod != null)