mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
Fixed: Profile delete Unit Tests
This commit is contained in:
parent
03360ca43f
commit
af090c7a3a
3 changed files with 118 additions and 3 deletions
|
@ -2,6 +2,7 @@ using System.Linq;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.ImportLists;
|
||||||
using NzbDrone.Core.Lifecycle;
|
using NzbDrone.Core.Lifecycle;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Core.Music;
|
using NzbDrone.Core.Music;
|
||||||
|
@ -50,8 +51,41 @@ namespace NzbDrone.Core.Test.Languages
|
||||||
.With(c => c.LanguageProfileId = profile.Id)
|
.With(c => c.LanguageProfileId = profile.Id)
|
||||||
.Build().ToList();
|
.Build().ToList();
|
||||||
|
|
||||||
|
var importLists = Builder<ImportListDefinition>.CreateListOfSize(2)
|
||||||
|
.All()
|
||||||
|
.With(c => c.ProfileId = 1)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||||
|
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||||
|
Mocker.GetMock<ILanguageProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
||||||
|
|
||||||
|
Assert.Throws<LanguageProfileInUseException>(() => Subject.Delete(profile.Id));
|
||||||
|
|
||||||
|
Mocker.GetMock<ILanguageProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_be_able_to_delete_profile_if_assigned_to_import_list()
|
||||||
|
{
|
||||||
|
var profile = Builder<LanguageProfile>.CreateNew()
|
||||||
|
.With(p => p.Id = 2)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||||
|
.All()
|
||||||
|
.With(c => c.LanguageProfileId = 1)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
|
var importLists = Builder<ImportListDefinition>.CreateListOfSize(2)
|
||||||
|
.Random(1)
|
||||||
|
.With(c => c.LanguageProfileId = profile.Id)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
|
|
||||||
|
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||||
|
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||||
Mocker.GetMock<ILanguageProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
Mocker.GetMock<ILanguageProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
||||||
|
|
||||||
Assert.Throws<LanguageProfileInUseException>(() => Subject.Delete(profile.Id));
|
Assert.Throws<LanguageProfileInUseException>(() => Subject.Delete(profile.Id));
|
||||||
|
@ -62,15 +96,20 @@ namespace NzbDrone.Core.Test.Languages
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[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<Artist>.CreateListOfSize(3)
|
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||||
.All()
|
.All()
|
||||||
.With(c => c.LanguageProfileId = 2)
|
.With(c => c.LanguageProfileId = 2)
|
||||||
.Build().ToList();
|
.Build().ToList();
|
||||||
|
|
||||||
|
var importLists = Builder<ImportListDefinition>.CreateListOfSize(2)
|
||||||
|
.All()
|
||||||
|
.With(c => c.LanguageProfileId = 2)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||||
|
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||||
|
|
||||||
Subject.Delete(1);
|
Subject.Delete(1);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ using System.Linq;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.ImportLists;
|
||||||
|
using NzbDrone.Core.ImportLists.HeadphonesImport;
|
||||||
using NzbDrone.Core.Lifecycle;
|
using NzbDrone.Core.Lifecycle;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Core.Music;
|
using NzbDrone.Core.Music;
|
||||||
|
@ -50,8 +52,40 @@ namespace NzbDrone.Core.Test.Profiles.Metadata
|
||||||
.With(c => c.MetadataProfileId = profile.Id)
|
.With(c => c.MetadataProfileId = profile.Id)
|
||||||
.Build().ToList();
|
.Build().ToList();
|
||||||
|
|
||||||
|
var importLists = Builder<ImportListDefinition>.CreateListOfSize(2)
|
||||||
|
.All()
|
||||||
|
.With(c => c.MetadataProfileId = 1)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||||
|
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||||
|
Mocker.GetMock<IMetadataProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
||||||
|
|
||||||
|
Assert.Throws<MetadataProfileInUseException>(() => Subject.Delete(profile.Id));
|
||||||
|
|
||||||
|
Mocker.GetMock<IMetadataProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_be_able_to_delete_profile_if_assigned_to_import_list()
|
||||||
|
{
|
||||||
|
var profile = Builder<MetadataProfile>.CreateNew()
|
||||||
|
.With(p => p.Id = 2)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||||
|
.All()
|
||||||
|
.With(c => c.MetadataProfileId = 1)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
|
var importLists = Builder<ImportListDefinition>.CreateListOfSize(2)
|
||||||
|
.Random(1)
|
||||||
|
.With(c => c.MetadataProfileId = profile.Id)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
|
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||||
|
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||||
Mocker.GetMock<IMetadataProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
Mocker.GetMock<IMetadataProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
||||||
|
|
||||||
Assert.Throws<MetadataProfileInUseException>(() => Subject.Delete(profile.Id));
|
Assert.Throws<MetadataProfileInUseException>(() => Subject.Delete(profile.Id));
|
||||||
|
@ -62,15 +96,20 @@ namespace NzbDrone.Core.Test.Profiles.Metadata
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[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<Artist>.CreateListOfSize(3)
|
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||||
.All()
|
.All()
|
||||||
.With(c => c.MetadataProfileId = 2)
|
.With(c => c.MetadataProfileId = 2)
|
||||||
.Build().ToList();
|
.Build().ToList();
|
||||||
|
|
||||||
|
var importLists = Builder<ImportListDefinition>.CreateListOfSize(2)
|
||||||
|
.All()
|
||||||
|
.With(c => c.MetadataProfileId = 2)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||||
|
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||||
|
|
||||||
Subject.Delete(1);
|
Subject.Delete(1);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System.Linq;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.ImportLists;
|
||||||
using NzbDrone.Core.Lifecycle;
|
using NzbDrone.Core.Lifecycle;
|
||||||
using NzbDrone.Core.Profiles.Qualities;
|
using NzbDrone.Core.Profiles.Qualities;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
@ -50,8 +51,13 @@ namespace NzbDrone.Core.Test.Profiles
|
||||||
.With(c => c.ProfileId = profile.Id)
|
.With(c => c.ProfileId = profile.Id)
|
||||||
.Build().ToList();
|
.Build().ToList();
|
||||||
|
|
||||||
|
var importLists = Builder<ImportListDefinition>.CreateListOfSize(2)
|
||||||
|
.All()
|
||||||
|
.With(c => c.ProfileId = 1)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||||
|
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||||
Mocker.GetMock<IProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
Mocker.GetMock<IProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
||||||
|
|
||||||
Assert.Throws<ProfileInUseException>(() => Subject.Delete(profile.Id));
|
Assert.Throws<ProfileInUseException>(() => 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<Profile>.CreateNew()
|
||||||
|
.With(p => p.Id = 2)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||||
|
.All()
|
||||||
|
.With(c => c.ProfileId = 1)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
|
var importLists = Builder<ImportListDefinition>.CreateListOfSize(2)
|
||||||
|
.Random(1)
|
||||||
|
.With(c => c.ProfileId = profile.Id)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
|
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||||
|
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||||
|
Mocker.GetMock<IProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
||||||
|
|
||||||
|
Assert.Throws<ProfileInUseException>(() => Subject.Delete(profile.Id));
|
||||||
|
|
||||||
|
Mocker.GetMock<IProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[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<Artist>.CreateListOfSize(3)
|
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||||
.All()
|
.All()
|
||||||
.With(c => c.ProfileId = 2)
|
.With(c => c.ProfileId = 2)
|
||||||
.Build().ToList();
|
.Build().ToList();
|
||||||
|
|
||||||
|
var importLists = Builder<ImportListDefinition>.CreateListOfSize(2)
|
||||||
|
.All()
|
||||||
|
.With(c => c.ProfileId = 2)
|
||||||
|
.Build().ToList();
|
||||||
|
|
||||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||||
|
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||||
|
|
||||||
Subject.Delete(1);
|
Subject.Delete(1);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue