Add Metadata Profiles (#132)

* Add Metadata Profiles

* fixup! Codacy
This commit is contained in:
Qstick
2017-11-25 22:51:37 -05:00
committed by GitHub
parent dd11f74073
commit 5b7339cd73
92 changed files with 2611 additions and 145 deletions
@@ -0,0 +1,42 @@
using FluentAssertions;
using System.Linq;
using NUnit.Framework;
using NzbDrone.Core.Music;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Profiles.Metadata;
namespace NzbDrone.Core.Test.Profiles.Metadata
{
[TestFixture]
public class MetadataProfileRepositoryFixture : DbTest<MetadataProfileRepository, MetadataProfile>
{
[Test]
public void should_be_able_to_read_and_write()
{
var profile = new MetadataProfile
{
PrimaryAlbumTypes = PrimaryAlbumType.All.OrderByDescending(l => l.Name).Select(l => new ProfilePrimaryAlbumTypeItem
{
PrimaryAlbumType = l,
Allowed = l == PrimaryAlbumType.Album
}).ToList(),
SecondaryAlbumTypes = SecondaryAlbumType.All.OrderByDescending(l => l.Name).Select(l => new ProfileSecondaryAlbumTypeItem
{
SecondaryAlbumType = l,
Allowed = l == SecondaryAlbumType.Studio
}).ToList(),
Name = "TestProfile"
};
Subject.Insert(profile);
StoredModel.Name.Should().Be(profile.Name);
StoredModel.PrimaryAlbumTypes.Should().Equal(profile.PrimaryAlbumTypes, (a, b) => a.PrimaryAlbumType == b.PrimaryAlbumType && a.Allowed == b.Allowed);
StoredModel.SecondaryAlbumTypes.Should().Equal(profile.SecondaryAlbumTypes, (a, b) => a.SecondaryAlbumType == b.SecondaryAlbumType && a.Allowed == b.Allowed);
}
}
}
@@ -0,0 +1,75 @@
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Music;
using NzbDrone.Core.Profiles.Metadata;
namespace NzbDrone.Core.Test.Profiles.Metadata
{
[TestFixture]
public class MetadataProfileServiceFixture : CoreTest<MetadataProfileService>
{
[Test]
public void init_should_add_default_profiles()
{
Subject.Handle(new ApplicationStartedEvent());
Mocker.GetMock<IMetadataProfileRepository>()
.Verify(v => v.Insert(It.IsAny<MetadataProfile>()), Times.Once());
}
[Test]
//This confirms that new profiles are added only if no other profiles exists.
//We don't want to keep adding them back if a user deleted them on purpose.
public void Init_should_skip_if_any_profiles_already_exist()
{
Mocker.GetMock<IMetadataProfileRepository>()
.Setup(s => s.All())
.Returns(Builder<MetadataProfile>.CreateListOfSize(2).Build().ToList());
Subject.Handle(new ApplicationStartedEvent());
Mocker.GetMock<IMetadataProfileRepository>()
.Verify(v => v.Insert(It.IsAny<MetadataProfile>()), Times.Never());
}
[Test]
public void should_not_be_able_to_delete_profile_if_assigned_to_artist()
{
var artistList = Builder<Artist>.CreateListOfSize(3)
.Random(1)
.With(c => c.MetadataProfileId = 2)
.Build().ToList();
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
Assert.Throws<MetadataProfileInUseException>(() => Subject.Delete(2));
Mocker.GetMock<IMetadataProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());
}
[Test]
public void should_delete_profile_if_not_assigned_to_series()
{
var artistList = Builder<Artist>.CreateListOfSize(3)
.All()
.With(c => c.MetadataProfileId = 2)
.Build().ToList();
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
Subject.Delete(1);
Mocker.GetMock<IMetadataProfileRepository>().Verify(c => c.Delete(1), Times.Once());
}
}
}