2017-09-29 02:02:08 +00:00
|
|
|
using System;
|
2015-01-09 01:43:51 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
2015-08-12 18:45:44 +00:00
|
|
|
using NzbDrone.Core.Exceptions;
|
2015-01-09 01:43:51 +00:00
|
|
|
using NzbDrone.Core.MetadataSource.SkyHook;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2017-09-29 02:02:08 +00:00
|
|
|
using NzbDrone.Core.Music;
|
2015-01-09 01:43:51 +00:00
|
|
|
using NzbDrone.Test.Common.Categories;
|
2017-12-29 03:47:19 +00:00
|
|
|
using Moq;
|
|
|
|
using NzbDrone.Core.Profiles.Metadata;
|
2015-01-09 01:43:51 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
[IntegrationTest]
|
|
|
|
public class SkyHookProxyFixture : CoreTest<SkyHookProxy>
|
|
|
|
{
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
UseRealHttp();
|
2017-12-29 03:47:19 +00:00
|
|
|
|
|
|
|
var _metadataProfile = new MetadataProfile
|
|
|
|
{
|
|
|
|
PrimaryAlbumTypes = new List<ProfilePrimaryAlbumTypeItem>
|
|
|
|
{
|
|
|
|
new ProfilePrimaryAlbumTypeItem
|
|
|
|
{
|
|
|
|
PrimaryAlbumType = PrimaryAlbumType.Album,
|
|
|
|
Allowed = true
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
SecondaryAlbumTypes = new List<ProfileSecondaryAlbumTypeItem>
|
|
|
|
{
|
|
|
|
new ProfileSecondaryAlbumTypeItem()
|
|
|
|
{
|
|
|
|
SecondaryAlbumType = SecondaryAlbumType.Studio,
|
|
|
|
Allowed = true
|
|
|
|
}
|
|
|
|
},
|
2018-12-15 00:02:43 +00:00
|
|
|
ReleaseStatuses = new List<ProfileReleaseStatusItem>
|
|
|
|
{
|
|
|
|
new ProfileReleaseStatusItem
|
|
|
|
{
|
|
|
|
ReleaseStatus = ReleaseStatus.Official,
|
|
|
|
Allowed = true
|
|
|
|
}
|
|
|
|
}
|
2017-12-29 03:47:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Mocker.GetMock<IMetadataProfileService>()
|
|
|
|
.Setup(s => s.Get(It.IsAny<int>()))
|
|
|
|
.Returns(_metadataProfile);
|
2018-01-28 06:27:33 +00:00
|
|
|
|
|
|
|
Mocker.GetMock<IMetadataProfileService>()
|
|
|
|
.Setup(s => s.Exists(It.IsAny<int>()))
|
|
|
|
.Returns(true);
|
2015-01-09 01:43:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 02:02:08 +00:00
|
|
|
[TestCase("f59c5520-5f46-4d2c-b2c4-822eabf53419", "Linkin Park")]
|
|
|
|
[TestCase("66c662b6-6e2f-4930-8610-912e24c63ed1", "AC/DC")]
|
|
|
|
public void should_be_able_to_get_artist_detail(string mbId, string name)
|
2015-01-09 01:43:51 +00:00
|
|
|
{
|
2017-12-29 03:47:19 +00:00
|
|
|
var details = Subject.GetArtistInfo(mbId, 1);
|
2015-01-09 01:43:51 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
ValidateArtist(details);
|
|
|
|
ValidateAlbums(details.Albums.Value);
|
2015-01-09 01:43:51 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
details.Name.Should().Be(name);
|
2015-01-09 01:43:51 +00:00
|
|
|
}
|
2018-01-28 06:27:33 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
[TestCase("12fa3845-7c62-36e5-a8da-8be137155a72", "Hysteria")]
|
|
|
|
public void should_be_able_to_get_album_detail(string mbId, string name)
|
2018-01-28 06:27:33 +00:00
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
var details = Subject.GetAlbumInfo(mbId);
|
2018-01-28 06:27:33 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
ValidateAlbums(new List<Album> {details.Item2});
|
2018-01-28 06:27:33 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
details.Item2.Title.Should().Be(name);
|
2018-01-28 06:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase("12fa3845-7c62-36e5-a8da-8be137155a72", "3c186b52-ca73-46a3-a8e6-04559bfbb581",1, 13, "Hysteria")]
|
|
|
|
[TestCase("12fa3845-7c62-36e5-a8da-8be137155a72", "dee9ca6f-4f84-4359-82a9-b75a37ffc316",2, 27,"Hysteria")]
|
|
|
|
public void should_be_able_to_get_album_detail_with_release(string mbId, string release, int mediaCount, int trackCount, string name)
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
var details = Subject.GetAlbumInfo(mbId);
|
2018-01-28 06:27:33 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
ValidateAlbums(new List<Album> { details.Item2 });
|
2018-01-28 06:27:33 +00:00
|
|
|
|
2018-12-15 00:02:43 +00:00
|
|
|
details.Item2.AlbumReleases.Value.Single(r => r.ForeignReleaseId == release).Media.Count.Should().Be(mediaCount);
|
|
|
|
details.Item2.AlbumReleases.Value.Single(r => r.ForeignReleaseId == release).Tracks.Value.Count.Should().Be(trackCount);
|
|
|
|
details.Item2.Title.Should().Be(name);
|
2018-01-28 06:27:33 +00:00
|
|
|
}
|
2015-01-09 01:43:51 +00:00
|
|
|
|
|
|
|
[Test]
|
2017-09-29 02:02:08 +00:00
|
|
|
public void getting_details_of_invalid_artist()
|
2015-01-09 01:43:51 +00:00
|
|
|
{
|
2018-01-28 06:27:33 +00:00
|
|
|
Assert.Throws<ArtistNotFoundException>(() => Subject.GetArtistInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1", 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void getting_details_of_invalid_guid_for_artist()
|
|
|
|
{
|
|
|
|
Assert.Throws<BadRequestException>(() => Subject.GetArtistInfo("66c66aaa-6e2f-4930-aaaaaa", 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void getting_details_of_invalid_album()
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
Assert.Throws<AlbumNotFoundException>(() => Subject.GetAlbumInfo("66c66aaa-6e2f-4930-8610-912e24c63ed1"));
|
2018-01-28 06:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void getting_details_of_invalid_guid_for_album()
|
|
|
|
{
|
2018-12-15 00:02:43 +00:00
|
|
|
Assert.Throws<BadRequestException>(() => Subject.GetAlbumInfo("66c66aaa-6e2f-4930-aaaaaa"));
|
2015-01-09 01:43:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 02:02:08 +00:00
|
|
|
private void ValidateArtist(Artist artist)
|
2015-01-09 01:43:51 +00:00
|
|
|
{
|
2017-09-29 02:02:08 +00:00
|
|
|
artist.Should().NotBeNull();
|
|
|
|
artist.Name.Should().NotBeNullOrWhiteSpace();
|
2017-10-08 20:07:54 +00:00
|
|
|
artist.CleanName.Should().Be(Parser.Parser.CleanArtistName(artist.Name));
|
2017-09-29 02:02:08 +00:00
|
|
|
artist.SortName.Should().Be(Parser.Parser.NormalizeTitle(artist.Name));
|
2018-12-15 00:02:43 +00:00
|
|
|
artist.Metadata.Value.Overview.Should().NotBeNullOrWhiteSpace();
|
|
|
|
artist.Metadata.Value.Images.Should().NotBeEmpty();
|
2017-09-29 02:02:08 +00:00
|
|
|
artist.ForeignArtistId.Should().NotBeNullOrWhiteSpace();
|
2015-01-09 01:43:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 02:02:08 +00:00
|
|
|
private void ValidateAlbums(List<Album> albums)
|
2015-01-09 01:43:51 +00:00
|
|
|
{
|
2017-09-29 02:02:08 +00:00
|
|
|
albums.Should().NotBeEmpty();
|
2015-01-09 01:43:51 +00:00
|
|
|
|
2018-01-28 06:27:33 +00:00
|
|
|
foreach (var album in albums)
|
2015-01-09 01:43:51 +00:00
|
|
|
{
|
2018-01-28 06:27:33 +00:00
|
|
|
ValidateAlbum(album);
|
2015-01-09 01:43:51 +00:00
|
|
|
|
2017-09-29 02:02:08 +00:00
|
|
|
//if atleast one album has title it means parse it working.
|
|
|
|
albums.Should().Contain(c => !string.IsNullOrWhiteSpace(c.Title));
|
2015-01-09 01:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-29 02:02:08 +00:00
|
|
|
private void ValidateAlbum(Album album)
|
2015-01-09 01:43:51 +00:00
|
|
|
{
|
2017-09-29 02:02:08 +00:00
|
|
|
album.Should().NotBeNull();
|
|
|
|
|
|
|
|
album.Title.Should().NotBeNullOrWhiteSpace();
|
|
|
|
album.AlbumType.Should().NotBeNullOrWhiteSpace();
|
2015-01-09 01:43:51 +00:00
|
|
|
|
2017-09-29 02:02:08 +00:00
|
|
|
album.Should().NotBeNull();
|
2015-01-09 01:43:51 +00:00
|
|
|
|
2017-09-29 02:02:08 +00:00
|
|
|
if (album.ReleaseDate.HasValue)
|
2015-01-09 01:43:51 +00:00
|
|
|
{
|
2017-09-29 02:02:08 +00:00
|
|
|
album.ReleaseDate.Value.Kind.Should().Be(DateTimeKind.Utc);
|
2015-01-09 01:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|