Improve error message when deleting a profile that is in use

pull/221/head
Qstick 7 years ago
parent e8771c9c78
commit 425a9045b8

@ -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<LanguageProfile>.CreateNew()
.With(p => p.Id = 2)
.Build();
var artistList = Builder<Artist>.CreateListOfSize(3)
.Random(1)
.With(c => c.LanguageProfileId = 2)
.With(c => c.LanguageProfileId = profile.Id)
.Build().ToList();
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
Mocker.GetMock<ILanguageProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
Assert.Throws<LanguageProfileInUseException>(() => Subject.Delete(2));
Assert.Throws<LanguageProfileInUseException>(() => Subject.Delete(profile.Id));
Mocker.GetMock<ILanguageProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());

@ -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<MetadataProfile>.CreateNew()
.With(p => p.Id = 2)
.Build();
var artistList = Builder<Artist>.CreateListOfSize(3)
.Random(1)
.With(c => c.MetadataProfileId = 2)
.With(c => c.MetadataProfileId = profile.Id)
.Build().ToList();
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
Mocker.GetMock<IMetadataProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
Assert.Throws<MetadataProfileInUseException>(() => Subject.Delete(2));
Assert.Throws<MetadataProfileInUseException>(() => Subject.Delete(profile.Id));
Mocker.GetMock<IMetadataProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());

@ -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<Profile>.CreateNew()
.With(p => p.Id = 2)
.Build();
var artistList = Builder<Artist>.CreateListOfSize(3)
.Random(1)
.With(c => c.ProfileId = 2)
.With(c => c.ProfileId = profile.Id)
.Build().ToList();
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
Mocker.GetMock<IProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
Assert.Throws<ProfileInUseException>(() => Subject.Delete(2));
Assert.Throws<ProfileInUseException>(() => Subject.Delete(profile.Id));
Mocker.GetMock<IProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());

@ -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)
{
}
}
}
}

@ -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);

@ -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)
{
}

@ -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);

@ -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)
{
}

@ -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);

Loading…
Cancel
Save