From e40508e5e99f4cbba68a410b969641cde13efe36 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 21 Apr 2015 16:50:48 -0700 Subject: [PATCH] Fixed: Don't save invalid scene mappings into database --- .../Scene/SceneMappingServiceFixture.cs | 43 +++++++++++++++++++ .../Scene/SceneMappingService.cs | 6 +++ 2 files changed, 49 insertions(+) diff --git a/src/NzbDrone.Core.Test/DataAugmentationFixture/Scene/SceneMappingServiceFixture.cs b/src/NzbDrone.Core.Test/DataAugmentationFixture/Scene/SceneMappingServiceFixture.cs index e4dbf0859..7079d165e 100644 --- a/src/NzbDrone.Core.Test/DataAugmentationFixture/Scene/SceneMappingServiceFixture.cs +++ b/src/NzbDrone.Core.Test/DataAugmentationFixture/Scene/SceneMappingServiceFixture.cs @@ -10,6 +10,7 @@ using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; using FluentAssertions; +using NzbDrone.Common.Extensions; namespace NzbDrone.Core.Test.DataAugmentationFixture.Scene { @@ -134,6 +135,48 @@ namespace NzbDrone.Core.Test.DataAugmentationFixture.Scene .Verify(v => v.All(), Times.Once()); } + [Test] + public void should_not_add_mapping_with_blank_parse_title() + { + GivenProviders(new[] { _provider1 }); + + var fakeMappings = Builder.CreateListOfSize(2) + .TheLast(1) + .With(m => m.ParseTerm = null) + .Build() + .ToList(); + + _provider1.Setup(s => s.GetSceneMappings()).Returns(fakeMappings); + + Mocker.GetMock().Setup(c => c.All()).Returns(_fakeMappings); + + Subject.Execute(new UpdateSceneMappingCommand()); + + Mocker.GetMock().Verify(c => c.InsertMany(It.Is>(m => !m.Any(s => s.ParseTerm.IsNullOrWhiteSpace()))), Times.Once()); + ExceptionVerification.ExpectedWarns(1); + } + + [Test] + public void should_not_add_mapping_with_blank_search_title() + { + GivenProviders(new[] { _provider1 }); + + var fakeMappings = Builder.CreateListOfSize(2) + .TheLast(1) + .With(m => m.SearchTerm = null) + .Build() + .ToList(); + + _provider1.Setup(s => s.GetSceneMappings()).Returns(fakeMappings); + + Mocker.GetMock().Setup(c => c.All()).Returns(_fakeMappings); + + Subject.Execute(new UpdateSceneMappingCommand()); + + Mocker.GetMock().Verify(c => c.InsertMany(It.Is>(m => !m.Any(s => s. SearchTerm.IsNullOrWhiteSpace()))), Times.Once()); + ExceptionVerification.ExpectedWarns(1); + } + 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 90a7cef9b..5aa7f8c41 100644 --- a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -114,6 +114,12 @@ namespace NzbDrone.Core.DataAugmentation.Scene foreach (var sceneMapping in mappings) { + if (sceneMapping.ParseTerm.IsNullOrWhiteSpace() || + sceneMapping.SearchTerm.IsNullOrWhiteSpace()) + { + _logger.Warn("Invalid scene mapping found for: {0}, skipping", sceneMapping.TvdbId); + } + sceneMapping.ParseTerm = sceneMapping.Title.CleanSeriesTitle(); sceneMapping.Type = sceneMappingProvider.GetType().Name; }