diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfoFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfoFixture.cs new file mode 100644 index 000000000..9f9189b36 --- /dev/null +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfoFixture.cs @@ -0,0 +1,110 @@ +using System.Collections.Generic; +using FizzWare.NBuilder; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augmenters.Language; +using NzbDrone.Core.MediaFiles.MediaInfo; +using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augmenters.Language +{ + [TestFixture] + public class AugmentLanguageFromMediaInfoFixture : CoreTest + { + [Test] + public void should_return_null_if_media_info_is_null() + { + var localEpisode = Builder.CreateNew() + .With(l => l.MediaInfo = null) + .Build(); + + Subject.AugmentLanguage(localEpisode, null).Should().Be(null); + } + + [Test] + public void should_return_language_for_single_known_language() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = new List { "eng" }) + .Build(); + + var localEpisode = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localEpisode, null); + + result.Languages.Count.Should().Be(1); + result.Languages.Should().Contain(Core.Languages.Language.English); + } + + [Test] + public void should_only_return_one_when_language_duplicated() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = new List { "eng", "eng" }) + .Build(); + + var localEpisode = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localEpisode, null); + + result.Languages.Count.Should().Be(1); + result.Languages.Should().Contain(Core.Languages.Language.English); + } + + [Test] + public void should_return_null_if_all_unknown() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = new List { "pirate", "pirate" }) + .Build(); + + var localEpisode = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localEpisode, null); + + result.Should().BeNull(); + } + + [Test] + public void should_return_known_languages_only() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = new List { "eng", "pirate" }) + .Build(); + + var localEpisode = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localEpisode, null); + + result.Languages.Count.Should().Be(1); + result.Languages.Should().Contain(Core.Languages.Language.English); + } + + [Test] + public void should_return_multiple_known_languages() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = new List { "eng", "ger" }) + .Build(); + + var localMovie = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localMovie, null); + + result.Languages.Count.Should().Be(2); + result.Languages.Should().Contain(Core.Languages.Language.English); + result.Languages.Should().Contain(Core.Languages.Language.German); + } + } +} diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromDownloadClientItem.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromDownloadClientItem.cs index 3a5260dc6..6ef6d5d60 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromDownloadClientItem.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromDownloadClientItem.cs @@ -25,7 +25,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment { var episodeTitleLanguage = LanguageParser.ParseLanguages(episode.Title, false); - languages = localEpisode.DownloadClientEpisodeInfo.Languages.Except(episodeTitleLanguage).ToList(); + languages = languages.Except(episodeTitleLanguage).ToList(); } return new AugmentLanguageResult(languages, Confidence.DownloadClientItem); diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromFileName.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromFileName.cs index 307f25584..7bdb8c31d 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromFileName.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromFileName.cs @@ -23,7 +23,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment { var episodeTitleLanguage = LanguageParser.ParseLanguages(episode.Title, false); - languages = localEpisode.DownloadClientEpisodeInfo.Languages.Except(episodeTitleLanguage).ToList(); + languages = languages.Except(episodeTitleLanguage).ToList(); } return new AugmentLanguageResult(languages, Confidence.Filename); diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromFolder.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromFolder.cs index 60e378168..39c079f19 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromFolder.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromFolder.cs @@ -23,7 +23,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators.Augment { var episodeTitleLanguage = LanguageParser.ParseLanguages(episode.Title, false); - languages = localEpisode.DownloadClientEpisodeInfo.Languages.Except(episodeTitleLanguage).ToList(); + languages = languages.Except(episodeTitleLanguage).ToList(); } return new AugmentLanguageResult(languages, Confidence.Foldername);