diff --git a/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs b/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs index 94ff97dcb..8f3c6f9bb 100644 --- a/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Languages/LanguageProfileServiceFixture.cs @@ -41,15 +41,20 @@ namespace NzbDrone.Core.Test.Languages [Test] public void should_not_be_able_to_delete_profile_if_assigned_to_artist() { + var profile = Builder.CreateNew() + .With(p => p.Id = 2) + .Build(); + var artistList = Builder.CreateListOfSize(3) .Random(1) - .With(c => c.LanguageProfileId = 2) + .With(c => c.LanguageProfileId = profile.Id) .Build().ToList(); Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); - Assert.Throws(() => Subject.Delete(2)); + Assert.Throws(() => Subject.Delete(profile.Id)); Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); diff --git a/src/NzbDrone.Core.Test/Profiles/Metadata/MetadataProfileServiceFixture.cs b/src/NzbDrone.Core.Test/Profiles/Metadata/MetadataProfileServiceFixture.cs index 51899ea66..3ee003760 100644 --- a/src/NzbDrone.Core.Test/Profiles/Metadata/MetadataProfileServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Profiles/Metadata/MetadataProfileServiceFixture.cs @@ -41,15 +41,20 @@ namespace NzbDrone.Core.Test.Profiles.Metadata [Test] public void should_not_be_able_to_delete_profile_if_assigned_to_artist() { + var profile = Builder.CreateNew() + .With(p => p.Id = 2) + .Build(); + var artistList = Builder.CreateListOfSize(3) .Random(1) - .With(c => c.MetadataProfileId = 2) + .With(c => c.MetadataProfileId = profile.Id) .Build().ToList(); Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); - Assert.Throws(() => Subject.Delete(2)); + Assert.Throws(() => Subject.Delete(profile.Id)); Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); diff --git a/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs b/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs index 65e103ec0..1f4338062 100644 --- a/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Profiles/ProfileServiceFixture.cs @@ -41,15 +41,20 @@ namespace NzbDrone.Core.Test.Profiles [Test] public void should_not_be_able_to_delete_profile_if_assigned_to_artist() { + var profile = Builder.CreateNew() + .With(p => p.Id = 2) + .Build(); + var artistList = Builder.CreateListOfSize(3) .Random(1) - .With(c => c.ProfileId = 2) + .With(c => c.ProfileId = profile.Id) .Build().ToList(); Mocker.GetMock().Setup(c => c.GetAllArtists()).Returns(artistList); + Mocker.GetMock().Setup(c => c.Get(profile.Id)).Returns(profile); - Assert.Throws(() => Subject.Delete(2)); + Assert.Throws(() => Subject.Delete(profile.Id)); Mocker.GetMock().Verify(c => c.Delete(It.IsAny()), Times.Never()); diff --git a/src/NzbDrone.Core/Profiles/Languages/LanguageProfileInUseException.cs b/src/NzbDrone.Core/Profiles/Languages/LanguageProfileInUseException.cs index bfba8045d..b64f804a7 100644 --- a/src/NzbDrone.Core/Profiles/Languages/LanguageProfileInUseException.cs +++ b/src/NzbDrone.Core/Profiles/Languages/LanguageProfileInUseException.cs @@ -1,13 +1,14 @@ -using NzbDrone.Common.Exceptions; +using System.Net; +using NzbDrone.Core.Exceptions; namespace NzbDrone.Core.Profiles.Languages { - public class LanguageProfileInUseException : NzbDroneException + public class LanguageProfileInUseException : NzbDroneClientException { - public LanguageProfileInUseException(int profileId) - : base("Language profile [{0}] is in use.", profileId) + public LanguageProfileInUseException(string name) + : base(HttpStatusCode.BadRequest, "Language profile [{0}] is in use.", name) { } } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Core/Profiles/Languages/LanguageProfileService.cs b/src/NzbDrone.Core/Profiles/Languages/LanguageProfileService.cs index dfab045bd..395a717e0 100644 --- a/src/NzbDrone.Core/Profiles/Languages/LanguageProfileService.cs +++ b/src/NzbDrone.Core/Profiles/Languages/LanguageProfileService.cs @@ -45,7 +45,8 @@ namespace NzbDrone.Core.Profiles.Languages { if (_artistService.GetAllArtists().Any(c => c.LanguageProfileId == id)) { - throw new LanguageProfileInUseException(id); + var profile = _profileRepository.Get(id); + throw new LanguageProfileInUseException(profile.Name); } _profileRepository.Delete(id); diff --git a/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileInUseException.cs b/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileInUseException.cs index b7849d231..7f215f8dc 100644 --- a/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileInUseException.cs +++ b/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileInUseException.cs @@ -1,11 +1,12 @@ -using NzbDrone.Common.Exceptions; +using System.Net; +using NzbDrone.Core.Exceptions; namespace NzbDrone.Core.Profiles.Metadata { - public class MetadataProfileInUseException : NzbDroneException + public class MetadataProfileInUseException : NzbDroneClientException { - public MetadataProfileInUseException(int profileId) - : base("Metadata profile [{0}] is in use.", profileId) + public MetadataProfileInUseException(string name) + : base(HttpStatusCode.BadRequest, "Metadata profile [{0}] is in use.", name) { } diff --git a/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs b/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs index 01ac7dc13..9ec454adf 100644 --- a/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs +++ b/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs @@ -44,7 +44,8 @@ namespace NzbDrone.Core.Profiles.Metadata { if (_artistService.GetAllArtists().Any(c => c.MetadataProfileId == id)) { - throw new MetadataProfileInUseException(id); + var profile = _profileRepository.Get(id); + throw new MetadataProfileInUseException(profile.Name); } _profileRepository.Delete(id); diff --git a/src/NzbDrone.Core/Profiles/Qualities/ProfileInUseException.cs b/src/NzbDrone.Core/Profiles/Qualities/ProfileInUseException.cs index b56c9f1db..77245cf1c 100644 --- a/src/NzbDrone.Core/Profiles/Qualities/ProfileInUseException.cs +++ b/src/NzbDrone.Core/Profiles/Qualities/ProfileInUseException.cs @@ -1,11 +1,12 @@ -using NzbDrone.Common.Exceptions; +using System.Net; +using NzbDrone.Core.Exceptions; namespace NzbDrone.Core.Profiles.Qualities { - public class ProfileInUseException : NzbDroneException + public class ProfileInUseException : NzbDroneClientException { - public ProfileInUseException(int profileId) - : base("Profile [{0}] is in use.", profileId) + public ProfileInUseException(string name) + : base(HttpStatusCode.BadRequest, "Profile [{0}] is in use.", name) { } diff --git a/src/NzbDrone.Core/Profiles/Qualities/ProfileService.cs b/src/NzbDrone.Core/Profiles/Qualities/ProfileService.cs index 50602da96..c275aad07 100644 --- a/src/NzbDrone.Core/Profiles/Qualities/ProfileService.cs +++ b/src/NzbDrone.Core/Profiles/Qualities/ProfileService.cs @@ -49,7 +49,8 @@ namespace NzbDrone.Core.Profiles.Qualities { if (_artistService.GetAllArtists().Any(c => c.ProfileId == id)) { - throw new ProfileInUseException(id); + var profile = _profileRepository.Get(id); + throw new ProfileInUseException(profile.Name); } _profileRepository.Delete(id);