From af090c7a3a7dbb907174c746967f250b7b568962 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 8 Apr 2018 00:29:23 -0400 Subject: [PATCH] Fixed: Profile delete Unit Tests --- .../LanguageProfileServiceFixture.cs | 41 ++++++++++++++++++- .../Metadata/MetadataProfileServiceFixture.cs | 41 ++++++++++++++++++- .../Profiles/ProfileServiceFixture.cs | 39 +++++++++++++++++- 3 files changed, 118 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs b/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs index 8f3c6f9bb..5a0e1e4ce 100644 --- a/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs @@ -2,6 +2,7 @@ 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.Music; @@ -50,8 +51,41 @@ namespace NzbDrone.Core.Test.Languages .With(c => c.LanguageProfileId = profile.Id) .Build().ToList(); + var importLists = Builder.CreateListOfSize(2) + .All() + .With(c => c.ProfileId = 1) + .Build().ToList(); Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.All()).Returns(importLists); + Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); + + Assert.Throws(() => Subject.Delete(profile.Id)); + + Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); + + } + + [Test] + public void should_not_be_able_to_delete_profile_if_assigned_to_import_list() + { + var profile = Builder.CreateNew() + .With(p => p.Id = 2) + .Build(); + + var artistList = Builder.CreateListOfSize(3) + .All() + .With(c => c.LanguageProfileId = 1) + .Build().ToList(); + + var importLists = Builder.CreateListOfSize(2) + .Random(1) + .With(c => c.LanguageProfileId = profile.Id) + .Build().ToList(); + + + Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.All()).Returns(importLists); Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); Assert.Throws(() => Subject.Delete(profile.Id)); @@ -62,15 +96,20 @@ namespace NzbDrone.Core.Test.Languages [Test] - public void should_delete_profile_if_not_assigned_to_series() + public void should_delete_profile_if_not_assigned_to_artist_or_import_list() { var artistList = Builder.CreateListOfSize(3) .All() .With(c => c.LanguageProfileId = 2) .Build().ToList(); + var importLists = Builder.CreateListOfSize(2) + .All() + .With(c => c.LanguageProfileId = 2) + .Build().ToList(); Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.All()).Returns(importLists); Subject.Delete(1); diff --git a/src/NzbDrone.Core.Test/Profiles/Metadata/MetadataProfileServiceFixture.cs b/src/NzbDrone.Core.Test/Profiles/Metadata/MetadataProfileServiceFixture.cs index 3ee003760..729b68c34 100644 --- a/src/NzbDrone.Core.Test/Profiles/Metadata/MetadataProfileServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Profiles/Metadata/MetadataProfileServiceFixture.cs @@ -2,6 +2,8 @@ using System.Linq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; +using NzbDrone.Core.ImportLists; +using NzbDrone.Core.ImportLists.HeadphonesImport; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Music; @@ -50,8 +52,40 @@ namespace NzbDrone.Core.Test.Profiles.Metadata .With(c => c.MetadataProfileId = profile.Id) .Build().ToList(); + var importLists = Builder.CreateListOfSize(2) + .All() + .With(c => c.MetadataProfileId = 1) + .Build().ToList(); Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.All()).Returns(importLists); + Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); + + Assert.Throws(() => Subject.Delete(profile.Id)); + + Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); + + } + + [Test] + public void should_not_be_able_to_delete_profile_if_assigned_to_import_list() + { + var profile = Builder.CreateNew() + .With(p => p.Id = 2) + .Build(); + + var artistList = Builder.CreateListOfSize(3) + .All() + .With(c => c.MetadataProfileId = 1) + .Build().ToList(); + + var importLists = Builder.CreateListOfSize(2) + .Random(1) + .With(c => c.MetadataProfileId = profile.Id) + .Build().ToList(); + + Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.All()).Returns(importLists); Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); Assert.Throws(() => Subject.Delete(profile.Id)); @@ -62,15 +96,20 @@ namespace NzbDrone.Core.Test.Profiles.Metadata [Test] - public void should_delete_profile_if_not_assigned_to_series() + public void should_delete_profile_if_not_assigned_to_artist_or_import_list() { var artistList = Builder.CreateListOfSize(3) .All() .With(c => c.MetadataProfileId = 2) .Build().ToList(); + var importLists = Builder.CreateListOfSize(2) + .All() + .With(c => c.MetadataProfileId = 2) + .Build().ToList(); Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.All()).Returns(importLists); Subject.Delete(1); diff --git a/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs b/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs index 1f4338062..0bd06e3bd 100644 --- a/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs @@ -2,6 +2,7 @@ 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; @@ -50,8 +51,13 @@ namespace NzbDrone.Core.Test.Profiles .With(c => c.ProfileId = profile.Id) .Build().ToList(); + var importLists = Builder.CreateListOfSize(2) + .All() + .With(c => c.ProfileId = 1) + .Build().ToList(); Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.All()).Returns(importLists); Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); Assert.Throws(() => Subject.Delete(profile.Id)); @@ -60,17 +66,48 @@ namespace NzbDrone.Core.Test.Profiles } + [Test] + public void should_not_be_able_to_delete_profile_if_assigned_to_import_list() + { + var profile = Builder.CreateNew() + .With(p => p.Id = 2) + .Build(); + + var artistList = Builder.CreateListOfSize(3) + .All() + .With(c => c.ProfileId = 1) + .Build().ToList(); + + var importLists = Builder.CreateListOfSize(2) + .Random(1) + .With(c => c.ProfileId = profile.Id) + .Build().ToList(); + + Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.All()).Returns(importLists); + Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); + + 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_artist() + public void should_delete_profile_if_not_assigned_to_artist_or_import_list() { var artistList = Builder.CreateListOfSize(3) .All() .With(c => c.ProfileId = 2) .Build().ToList(); + var importLists = Builder.CreateListOfSize(2) + .All() + .With(c => c.ProfileId = 2) + .Build().ToList(); Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.All()).Returns(importLists); Subject.Delete(1);