diff --git a/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs b/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs index 6a41dc76e..ac23ade33 100644 --- a/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs +++ b/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs @@ -75,7 +75,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } }; Mocker.GetMock() - .Setup(v => v.Get(1)) + .Setup(v => v.Find(1)) .Returns(indexerDefinition); _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { }, releaseTitle); @@ -83,7 +83,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators _remoteEpisode.Release.Title = releaseTitle; Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage, Language.French }); - Mocker.GetMock().Verify(c => c.Get(1), Times.Once()); + Mocker.GetMock().Verify(c => c.Find(1), Times.Once()); Mocker.GetMock().VerifyNoOtherCalls(); } @@ -105,7 +105,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators }; Mocker.GetMock() - .Setup(v => v.Get(1)) + .Setup(v => v.Find(1)) .Returns(indexerDefinition1); Mocker.GetMock() @@ -118,7 +118,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators _remoteEpisode.Release.Title = releaseTitle; Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage, Language.French }); - Mocker.GetMock().Verify(c => c.Get(1), Times.Once()); + Mocker.GetMock().Verify(c => c.Find(1), Times.Once()); Mocker.GetMock().VerifyNoOtherCalls(); } @@ -156,7 +156,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } }; Mocker.GetMock() - .Setup(v => v.Get(1)) + .Setup(v => v.Find(1)) .Returns(indexerDefinition); _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { Language.Unknown }, releaseTitle); @@ -164,7 +164,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators _remoteEpisode.Release.Title = releaseTitle; Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage, Language.French }); - Mocker.GetMock().Verify(c => c.Get(1), Times.Once()); + Mocker.GetMock().Verify(c => c.Find(1), Times.Once()); Mocker.GetMock().VerifyNoOtherCalls(); } @@ -178,7 +178,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators Settings = new TorrentRssIndexerSettings { } }; Mocker.GetMock() - .Setup(v => v.Get(1)) + .Setup(v => v.Find(1)) .Returns(indexerDefinition); _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { }, releaseTitle); @@ -186,7 +186,7 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators _remoteEpisode.Release.Title = releaseTitle; Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage }); - Mocker.GetMock().Verify(c => c.Get(1), Times.Once()); + Mocker.GetMock().Verify(c => c.Find(1), Times.Once()); Mocker.GetMock().VerifyNoOtherCalls(); } @@ -249,5 +249,85 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators Subject.Aggregate(_remoteEpisode).Languages.Should().Equal(Language.Greek); } + + [Test] + public void should_return_multi_languages_from_indexer_with_name_when_indexer_id_does_not_exist() + { + var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup"; + var indexerDefinition1 = new IndexerDefinition + { + Id = 1, + Name = "MyIndexer1", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } + }; + var indexerDefinition2 = new IndexerDefinition + { + Id = 2, + Name = "MyIndexer2", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.German.Id } } + }; + + Mocker.GetMock() + .Setup(v => v.Find(1)) + .Returns(null as IndexerDefinition); + + Mocker.GetMock() + .Setup(v => v.FindByName("MyIndexer1")) + .Returns(indexerDefinition1); + + Mocker.GetMock() + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition1, indexerDefinition2 }); + + _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { }, releaseTitle); + _remoteEpisode.Release.IndexerId = 10; + _remoteEpisode.Release.Indexer = "MyIndexer1"; + _remoteEpisode.Release.Title = releaseTitle; + + Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage, Language.French }); + Mocker.GetMock().Verify(c => c.Find(10), Times.Once()); + Mocker.GetMock().Verify(c => c.FindByName("MyIndexer1"), Times.Once()); + Mocker.GetMock().VerifyNoOtherCalls(); + } + + [Test] + public void should_return_multi_languages_from_indexer_with_name_when_indexer_id_not_available() + { + var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup"; + var indexerDefinition1 = new IndexerDefinition + { + Id = 1, + Name = "MyIndexer1", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } + }; + var indexerDefinition2 = new IndexerDefinition + { + Id = 2, + Name = "MyIndexer2", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.German.Id } } + }; + + Mocker.GetMock() + .Setup(v => v.Find(1)) + .Returns(null as IndexerDefinition); + + Mocker.GetMock() + .Setup(v => v.FindByName("MyIndexer1")) + .Returns(indexerDefinition1); + + Mocker.GetMock() + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition1, indexerDefinition2 }); + + _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { }, releaseTitle); + _remoteEpisode.Release.IndexerId = 0; + _remoteEpisode.Release.Indexer = "MyIndexer1"; + _remoteEpisode.Release.Title = releaseTitle; + + Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage, Language.French }); + Mocker.GetMock().Verify(c => c.Find(10), Times.Never()); + Mocker.GetMock().Verify(c => c.FindByName("MyIndexer1"), Times.Once()); + Mocker.GetMock().VerifyNoOtherCalls(); + } } } diff --git a/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs b/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs index 2baf81907..afa96dd1c 100644 --- a/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs +++ b/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs @@ -82,9 +82,10 @@ namespace NzbDrone.Core.Download.Aggregation.Aggregators if (releaseInfo is { IndexerId: > 0 }) { - indexer = _indexerFactory.Get(releaseInfo.IndexerId); + indexer = _indexerFactory.Find(releaseInfo.IndexerId); } - else if (releaseInfo.Indexer?.IsNotNullOrWhiteSpace() == true) + + if (indexer == null && releaseInfo.Indexer?.IsNotNullOrWhiteSpace() == true) { indexer = _indexerFactory.FindByName(releaseInfo.Indexer); }