From c184e7ddcc54b266c45d75cdf5173e713338e882 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 11 May 2017 06:32:09 +0200 Subject: [PATCH] Fixed: Multiple Scene Mapping exception even when the mappings pointed to the same tvdbid. Closes #1917 --- .../Scene/SceneMappingServiceFixture.cs | 14 ++++++++++++++ .../DataAugmentation/Scene/SceneMappingService.cs | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/DataAugmentation/Scene/SceneMappingServiceFixture.cs b/src/NzbDrone.Core.Test/DataAugmentation/Scene/SceneMappingServiceFixture.cs index 42b0156ff..1f1a6ff8e 100644 --- a/src/NzbDrone.Core.Test/DataAugmentation/Scene/SceneMappingServiceFixture.cs +++ b/src/NzbDrone.Core.Test/DataAugmentation/Scene/SceneMappingServiceFixture.cs @@ -346,6 +346,20 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene Assert.Throws(() => Subject.FindTvdbId("Amareto", "Amareto.S01E01.720p.WEB-DL-Viva")); } + [Test] + public void should_not_throw_if_multiple_mappings_with_same_tvdbid() + { + var mappings = new List + { + new SceneMapping { Title = "Amareto", ParseTerm = "amareto", SearchTerm = "Amareto", TvdbId = 100 }, + new SceneMapping { Title = "Amareto", ParseTerm = "amareto", SearchTerm = "Amareto", TvdbId = 100 } + }; + + Mocker.GetMock().Setup(c => c.All()).Returns(mappings); + + Subject.FindTvdbId("Amareto", "Amareto.S01E01.720p.WEB-DL-Viva").Should().Be(100); + } + private void AssertNoUpdate() { _provider1.Verify(c => c.GetSceneMappings(), Times.Once()); diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs index 5b66f8fa4..c657ed7fa 100644 --- a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -102,9 +102,11 @@ namespace NzbDrone.Core.DataAugmentation.Scene return null; } - if (mappings.Count <= 1) + var distinctMappings = mappings.DistinctBy(v => v.TvdbId).ToList(); + + if (distinctMappings.Count <= 1) { - return mappings.FirstOrDefault(); + return distinctMappings.FirstOrDefault(); } throw new InvalidSceneMappingException(mappings);