From a92665c5cd352cec301bd0402c2f8fcf5f61c88d Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 10 Sep 2020 15:45:28 -0700 Subject: [PATCH] Fixed tests/null reference for import lists --- .../LanguageProfileServiceFixture.cs | 40 +++++++++++++++-- ...ure.cs => QualityProfileServiceFixture.cs} | 45 +++++++++++++++++-- .../ImportLists/ImportListSyncService.cs | 8 +++- 3 files changed, 85 insertions(+), 8 deletions(-) rename src/NzbDrone.Core.Test/Profiles/{ProfileServiceFixture.cs => QualityProfileServiceFixture.cs} (60%) diff --git a/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs b/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs index 873787d13..f4cb6966d 100644 --- a/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs @@ -1,7 +1,9 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; +using NzbDrone.Core.ImportLists; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; @@ -13,6 +15,14 @@ namespace NzbDrone.Core.Test.Languages public class LanguageProfileServiceFixture : CoreTest { + [SetUp] + public void Setup() + { + Mocker.GetMock() + .Setup(s => s.All()) + .Returns(new List()); + } + [Test] public void init_should_add_default_profiles() { @@ -52,10 +62,8 @@ public void should_not_be_able_to_delete_profile_if_assigned_to_series() Assert.Throws(() => Subject.Delete(2)); Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); - } - [Test] public void should_delete_profile_if_not_assigned_to_series() { @@ -71,5 +79,31 @@ public void should_delete_profile_if_not_assigned_to_series() Mocker.GetMock().Verify(c => c.Delete(1), Times.Once()); } + + [Test] + public void should_not_be_able_to_delete_profile_if_assigned_to_import_list() + { + var seriesList = Builder.CreateListOfSize(3) + .Random(1) + .With(c => c.LanguageProfileId = 2) + .Build().ToList(); + + var importLists = Builder.CreateListOfSize(3) + .Random(1) + .With(c => c.LanguageProfileId = 1) + .Build().ToList(); + + + + Mocker.GetMock().Setup(c => c.GetAllSeries()).Returns(seriesList); + + Mocker.GetMock() + .Setup(s => s.All()) + .Returns(importLists); + + Assert.Throws(() => Subject.Delete(1)); + + Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs b/src/NzbDrone.Core.Test/Profiles/QualityProfileServiceFixture.cs similarity index 60% rename from src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs rename to src/NzbDrone.Core.Test/Profiles/QualityProfileServiceFixture.cs index 8d0596180..c3f6bb9d1 100644 --- a/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Profiles/QualityProfileServiceFixture.cs @@ -1,7 +1,9 @@ +using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; +using NzbDrone.Core.ImportLists; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Profiles.Qualities; using NzbDrone.Core.Test.Framework; @@ -10,8 +12,16 @@ namespace NzbDrone.Core.Test.Profiles { [TestFixture] - public class ProfileServiceFixture : CoreTest + public class QualityProfileServiceFixture : CoreTest { + [SetUp] + public void Setup() + { + Mocker.GetMock() + .Setup(s => s.All()) + .Returns(new List()); + } + [Test] public void init_should_add_default_profiles() { @@ -56,10 +66,8 @@ public void should_not_be_able_to_delete_profile_if_assigned_to_series() Assert.Throws(() => Subject.Delete(profile.Id)); Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); - } - [Test] public void should_delete_profile_if_not_assigned_to_series() { @@ -75,5 +83,36 @@ public void should_delete_profile_if_not_assigned_to_series() Mocker.GetMock().Verify(c => c.Delete(1), Times.Once()); } + + [Test] + public void should_not_be_able_to_delete_profile_if_assigned_to_import_list() + { + var profile = Builder.CreateNew() + .With(p => p.Id = 1) + .Build(); + + var seriesList = Builder.CreateListOfSize(3) + .All() + .With(c => c.QualityProfileId = 2) + .Build().ToList(); + + var importLists = Builder.CreateListOfSize(3) + .Random(1) + .With(c => c.LanguageProfileId = 1) + .Build().ToList(); + + + Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); + Mocker.GetMock().Setup(c => c.GetAllSeries()).Returns(seriesList); + + Mocker.GetMock() + .Setup(s => s.All()) + .Returns(importLists); + + + Assert.Throws(() => Subject.Delete(1)); + + Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); + } } } diff --git a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs index 2359443a5..8b4d8b544 100644 --- a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs +++ b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs @@ -86,8 +86,12 @@ private void ProcessReports(List reports) { var mappedSeries = _seriesSearchService.SearchForNewSeries(report.Title) .FirstOrDefault(); - report.TvdbId = mappedSeries.TvdbId; - report.Title = mappedSeries?.Title; + + if (mappedSeries != null) + { + report.TvdbId = mappedSeries.TvdbId; + report.Title = mappedSeries?.Title; + } } // Check to see if series in DB