New: Readarr 0.1

This commit is contained in:
ta264
2020-05-06 21:14:11 +01:00
parent 476f2d6047
commit 08496c82af
911 changed files with 14837 additions and 24442 deletions
@@ -3,12 +3,12 @@ using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.ImportLists;
using NzbDrone.Core.ImportLists.ReadarrLists;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ImportListTests
{
/*
public class ImportListServiceFixture : DbTest<ImportListFactory, ImportListDefinition>
{
private List<IImportList> _importLists;
@@ -18,7 +18,7 @@ namespace NzbDrone.Core.Test.ImportListTests
{
_importLists = new List<IImportList>();
_importLists.Add(Mocker.Resolve<ReadarrLists>());
_importLists.Add(Mocker.Resolve<GoodreadsOwnedBooks>());
Mocker.SetConstant<IEnumerable<IImportList>>(_importLists);
}
@@ -39,5 +39,5 @@ namespace NzbDrone.Core.Test.ImportListTests
AllStoredModels.Should().NotContain(c => c.Id == existingImportLists.Id);
}
}
}*/
}
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.ImportLists;
@@ -29,13 +30,22 @@ namespace NzbDrone.Core.Test.ImportListTests
.Setup(v => v.Fetch())
.Returns(_importListReports);
Mocker.GetMock<ISearchForNewArtist>()
.Setup(v => v.SearchForNewArtist(It.IsAny<string>()))
.Returns(new List<Artist>());
Mocker.GetMock<ISearchForNewAuthor>()
.Setup(v => v.SearchForNewAuthor(It.IsAny<string>()))
.Returns(new List<Author>());
Mocker.GetMock<ISearchForNewAlbum>()
.Setup(v => v.SearchForNewAlbum(It.IsAny<string>(), It.IsAny<string>()))
.Returns(new List<Album>());
Mocker.GetMock<ISearchForNewBook>()
.Setup(v => v.SearchForNewBook(It.IsAny<string>(), It.IsAny<string>()))
.Returns(new List<Book>());
Mocker.GetMock<ISearchForNewBook>()
.Setup(v => v.SearchByGoodreadsId(It.IsAny<int>()))
.Returns<int>(x => Builder<Book>
.CreateListOfSize(1)
.TheFirst(1)
.With(b => b.GoodreadsId = x)
.With(b => b.ForeignBookId = x.ToString())
.BuildList());
Mocker.GetMock<IImportListFactory>()
.Setup(v => v.Get(It.IsAny<int>()))
@@ -48,6 +58,14 @@ namespace NzbDrone.Core.Test.ImportListTests
Mocker.GetMock<IImportListExclusionService>()
.Setup(v => v.All())
.Returns(new List<ImportListExclusion>());
Mocker.GetMock<IAddAlbumService>()
.Setup(v => v.AddAlbums(It.IsAny<List<Book>>(), false))
.Returns<List<Book>, bool>((x, y) => x);
Mocker.GetMock<IAddArtistService>()
.Setup(v => v.AddArtists(It.IsAny<List<Author>>(), false))
.Returns<List<Author>, bool>((x, y) => x);
}
private void WithAlbum()
@@ -55,28 +73,28 @@ namespace NzbDrone.Core.Test.ImportListTests
_importListReports.First().Album = "Meteora";
}
private void WithArtistId()
private void WithAuthorId()
{
_importListReports.First().ArtistMusicBrainzId = "f59c5520-5f46-4d2c-b2c4-822eabf53419";
}
private void WithAlbumId()
private void WithBookId()
{
_importListReports.First().AlbumMusicBrainzId = "09474d62-17dd-3a4f-98fb-04c65f38a479";
_importListReports.First().AlbumMusicBrainzId = "101";
}
private void WithExistingArtist()
{
Mocker.GetMock<IArtistService>()
.Setup(v => v.FindById(_importListReports.First().ArtistMusicBrainzId))
.Returns(new Artist { ForeignArtistId = _importListReports.First().ArtistMusicBrainzId });
.Returns(new Author { ForeignAuthorId = _importListReports.First().ArtistMusicBrainzId });
}
private void WithExistingAlbum()
{
Mocker.GetMock<IAlbumService>()
.Setup(v => v.FindById(_importListReports.First().AlbumMusicBrainzId))
.Returns(new Album { ForeignAlbumId = _importListReports.First().AlbumMusicBrainzId });
.Returns(new Book { ForeignBookId = _importListReports.First().AlbumMusicBrainzId });
}
private void WithExcludedArtist()
@@ -100,7 +118,7 @@ namespace NzbDrone.Core.Test.ImportListTests
{
new ImportListExclusion
{
ForeignId = "09474d62-17dd-3a4f-98fb-04c65f38a479"
ForeignId = "101"
}
});
}
@@ -117,18 +135,18 @@ namespace NzbDrone.Core.Test.ImportListTests
{
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<ISearchForNewArtist>()
.Verify(v => v.SearchForNewArtist(It.IsAny<string>()), Times.Once());
Mocker.GetMock<ISearchForNewAuthor>()
.Verify(v => v.SearchForNewAuthor(It.IsAny<string>()), Times.Once());
}
[Test]
public void should_not_search_if_artist_title_and_artist_id()
{
WithArtistId();
WithAuthorId();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<ISearchForNewArtist>()
.Verify(v => v.SearchForNewArtist(It.IsAny<string>()), Times.Never());
Mocker.GetMock<ISearchForNewAuthor>()
.Verify(v => v.SearchForNewAuthor(It.IsAny<string>()), Times.Never());
}
[Test]
@@ -137,70 +155,70 @@ namespace NzbDrone.Core.Test.ImportListTests
WithAlbum();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<ISearchForNewAlbum>()
.Verify(v => v.SearchForNewAlbum(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
Mocker.GetMock<ISearchForNewBook>()
.Verify(v => v.SearchForNewBook(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
}
[Test]
public void should_not_search_if_album_title_and_album_id()
{
WithArtistId();
WithAlbumId();
WithAuthorId();
WithBookId();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<ISearchForNewAlbum>()
.Verify(v => v.SearchForNewAlbum(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
Mocker.GetMock<ISearchForNewBook>()
.Verify(v => v.SearchForNewBook(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
}
[Test]
public void should_not_search_if_all_info()
{
WithArtistId();
WithAuthorId();
WithAlbum();
WithAlbumId();
WithBookId();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<ISearchForNewArtist>()
.Verify(v => v.SearchForNewArtist(It.IsAny<string>()), Times.Never());
Mocker.GetMock<ISearchForNewAuthor>()
.Verify(v => v.SearchForNewAuthor(It.IsAny<string>()), Times.Never());
Mocker.GetMock<ISearchForNewAlbum>()
.Verify(v => v.SearchForNewAlbum(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
Mocker.GetMock<ISearchForNewBook>()
.Verify(v => v.SearchForNewBook(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
}
[Test]
public void should_not_add_if_existing_artist()
{
WithArtistId();
WithAuthorId();
WithExistingArtist();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddArtistService>()
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t => t.Count == 0)));
.Verify(v => v.AddArtists(It.Is<List<Author>>(t => t.Count == 0), false));
}
[Test]
public void should_not_add_if_existing_album()
{
WithAlbumId();
WithBookId();
WithExistingAlbum();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddArtistService>()
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t => t.Count == 0)));
.Verify(v => v.AddArtists(It.Is<List<Author>>(t => t.Count == 0), false));
}
[Test]
public void should_add_if_existing_artist_but_new_album()
{
WithAlbumId();
WithBookId();
WithExistingArtist();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddAlbumService>()
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 1)));
.Verify(v => v.AddAlbums(It.Is<List<Book>>(t => t.Count == 1), false));
}
[TestCase(ImportListMonitorType.None, false)]
@@ -208,13 +226,13 @@ namespace NzbDrone.Core.Test.ImportListTests
[TestCase(ImportListMonitorType.EntireArtist, true)]
public void should_add_if_not_existing_artist(ImportListMonitorType monitor, bool expectedArtistMonitored)
{
WithArtistId();
WithAuthorId();
WithMonitorType(monitor);
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddArtistService>()
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t => t.Count == 1 && t.First().Monitored == expectedArtistMonitored)));
.Verify(v => v.AddArtists(It.Is<List<Author>>(t => t.Count == 1 && t.First().Monitored == expectedArtistMonitored), false));
}
[TestCase(ImportListMonitorType.None, false)]
@@ -222,50 +240,50 @@ namespace NzbDrone.Core.Test.ImportListTests
[TestCase(ImportListMonitorType.EntireArtist, true)]
public void should_add_if_not_existing_album(ImportListMonitorType monitor, bool expectedAlbumMonitored)
{
WithAlbumId();
WithBookId();
WithMonitorType(monitor);
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddAlbumService>()
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 1 && t.First().Monitored == expectedAlbumMonitored)));
.Verify(v => v.AddAlbums(It.Is<List<Book>>(t => t.Count == 1 && t.First().Monitored == expectedAlbumMonitored), false));
}
[Test]
public void should_not_add_artist_if_excluded_artist()
{
WithArtistId();
WithAuthorId();
WithExcludedArtist();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddArtistService>()
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t => t.Count == 0)));
.Verify(v => v.AddArtists(It.Is<List<Author>>(t => t.Count == 0), false));
}
[Test]
public void should_not_add_album_if_excluded_album()
{
WithAlbumId();
WithBookId();
WithExcludedAlbum();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddAlbumService>()
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0)));
.Verify(v => v.AddAlbums(It.Is<List<Book>>(t => t.Count == 0), false));
}
[Test]
public void should_not_add_album_if_excluded_artist()
{
WithAlbumId();
WithArtistId();
WithBookId();
WithAuthorId();
WithExcludedArtist();
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddAlbumService>()
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0)));
.Verify(v => v.AddAlbums(It.Is<List<Book>>(t => t.Count == 0), false));
}
}
}
@@ -1,191 +0,0 @@
using System.Collections.Generic;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.ImportLists.Spotify;
using NzbDrone.Core.Test.Framework;
using SpotifyAPI.Web;
using SpotifyAPI.Web.Models;
namespace NzbDrone.Core.Test.ImportListTests
{
[TestFixture]
public class SpotifyFollowedArtistsFixture : CoreTest<SpotifyFollowedArtists>
{
// placeholder, we don't use real API
private readonly SpotifyWebAPI _api = null;
[Test]
public void should_not_throw_if_followed_is_null()
{
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetFollowedArtists(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(default(FollowedArtists));
var result = Subject.Fetch(_api);
result.Should().BeEmpty();
}
[Test]
public void should_not_throw_if_followed_artists_is_null()
{
var followed = new FollowedArtists
{
Artists = null
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetFollowedArtists(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(followed);
var result = Subject.Fetch(_api);
result.Should().BeEmpty();
}
[Test]
public void should_not_throw_if_followed_artist_items_is_null()
{
var followed = new FollowedArtists
{
Artists = new CursorPaging<FullArtist>
{
Items = null
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetFollowedArtists(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(followed);
var result = Subject.Fetch(_api);
result.Should().BeEmpty();
Subject.Fetch(_api);
}
[Test]
public void should_not_throw_if_artist_is_null()
{
var followed = new FollowedArtists
{
Artists = new CursorPaging<FullArtist>
{
Items = new List<FullArtist>
{
null
}
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetFollowedArtists(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(followed);
var result = Subject.Fetch(_api);
result.Should().BeEmpty();
Subject.Fetch(_api);
}
[Test]
public void should_parse_followed_artist()
{
var followed = new FollowedArtists
{
Artists = new CursorPaging<FullArtist>
{
Items = new List<FullArtist>
{
new FullArtist
{
Name = "artist"
}
}
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetFollowedArtists(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(followed);
var result = Subject.Fetch(_api);
result.Should().HaveCount(1);
}
[Test]
public void should_not_throw_if_get_next_page_returns_null()
{
var followed = new FollowedArtists
{
Artists = new CursorPaging<FullArtist>
{
Items = new List<FullArtist>
{
new FullArtist
{
Name = "artist"
}
},
Next = "DummyToMakeHasNextTrue"
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetFollowedArtists(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(followed);
Mocker.GetMock<ISpotifyProxy>()
.Setup(x => x.GetNextPage(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<FollowedArtists>()))
.Returns(default(FollowedArtists));
var result = Subject.Fetch(_api);
result.Should().HaveCount(1);
Mocker.GetMock<ISpotifyProxy>()
.Verify(v => v.GetNextPage(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<FollowedArtists>()),
Times.Once());
}
[TestCase(null)]
[TestCase("")]
public void should_skip_bad_artist_names(string name)
{
var followed = new FollowedArtists
{
Artists = new CursorPaging<FullArtist>
{
Items = new List<FullArtist>
{
new FullArtist
{
Name = name
}
}
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetFollowedArtists(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(followed);
var result = Subject.Fetch(_api);
result.Should().BeEmpty();
}
}
}
@@ -1,345 +0,0 @@
using System;
using System.Collections.Generic;
using System.Net;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Cloud;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.ImportLists.Spotify;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.MetadataSource.SkyHook.Resource;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ImportListTests
{
[TestFixture]
// the base import list class is abstract so use the followed artists one
public class SpotifyMappingFixture : CoreTest<SpotifyFollowedArtists>
{
[SetUp]
public void Setup()
{
Mocker.SetConstant<IReadarrCloudRequestBuilder>(new ReadarrCloudRequestBuilder());
Mocker.SetConstant<IMetadataRequestBuilder>(Mocker.Resolve<MetadataRequestBuilder>());
}
[Test]
public void map_artist_should_return_name_if_id_null()
{
var data = new SpotifyImportListItemInfo
{
Artist = "Adele"
};
Subject.MapArtistItem(data);
data.Artist.Should().Be("Adele");
data.ArtistMusicBrainzId.Should().BeNull();
data.Album.Should().BeNull();
data.AlbumMusicBrainzId.Should().BeNull();
}
[Test]
public void map_artist_should_set_id_0_if_no_match()
{
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Get<ArtistResource>(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>((x) => new HttpResponse<ArtistResource>(new HttpResponse(x, new HttpHeader(), new byte[0], HttpStatusCode.NotFound)));
var data = new SpotifyImportListItemInfo
{
Artist = "Adele",
ArtistSpotifyId = "id"
};
Subject.MapArtistItem(data);
data.ArtistMusicBrainzId.Should().Be("0");
}
[Test]
public void map_artist_should_not_update_id_if_http_throws()
{
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Get<ArtistResource>(It.IsAny<HttpRequest>()))
.Throws(new Exception("Dummy exception"));
var data = new SpotifyImportListItemInfo
{
Artist = "Adele",
ArtistSpotifyId = "id"
};
Subject.MapArtistItem(data);
data.ArtistMusicBrainzId.Should().BeNull();
ExceptionVerification.ExpectedErrors(1);
}
[Test]
public void map_artist_should_work()
{
UseRealHttp();
var data = new SpotifyImportListItemInfo
{
Artist = "Adele",
ArtistSpotifyId = "4dpARuHxo51G3z768sgnrY"
};
Subject.MapArtistItem(data);
data.Should().NotBeNull();
data.Artist.Should().Be("Adele");
data.ArtistMusicBrainzId.Should().Be("cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493");
data.Album.Should().BeNull();
data.AlbumMusicBrainzId.Should().BeNull();
}
[Test]
public void map_album_should_return_name_if_uri_null()
{
var data = new SpotifyImportListItemInfo
{
Album = "25",
Artist = "Adele"
};
Subject.MapAlbumItem(data);
data.Should().NotBeNull();
data.Artist.Should().Be("Adele");
data.ArtistMusicBrainzId.Should().BeNull();
data.Album.Should().Be("25");
data.AlbumMusicBrainzId.Should().BeNull();
}
[Test]
public void map_album_should_set_id_0_if_no_match()
{
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Get<AlbumResource>(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>((x) => new HttpResponse<AlbumResource>(new HttpResponse(x, new HttpHeader(), new byte[0], HttpStatusCode.NotFound)));
var data = new SpotifyImportListItemInfo
{
Album = "25",
AlbumSpotifyId = "id",
Artist = "Adele"
};
Subject.MapAlbumItem(data);
data.AlbumMusicBrainzId.Should().Be("0");
}
[Test]
public void map_album_should_not_update_id_if_http_throws()
{
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Get<AlbumResource>(It.IsAny<HttpRequest>()))
.Throws(new Exception("Dummy exception"));
var data = new SpotifyImportListItemInfo
{
Album = "25",
AlbumSpotifyId = "id",
Artist = "Adele"
};
Subject.MapAlbumItem(data);
data.Should().NotBeNull();
data.Artist.Should().Be("Adele");
data.ArtistMusicBrainzId.Should().BeNull();
data.Album.Should().Be("25");
data.AlbumMusicBrainzId.Should().BeNull();
ExceptionVerification.ExpectedErrors(1);
}
[Test]
public void map_album_should_work()
{
UseRealHttp();
var data = new SpotifyImportListItemInfo
{
Album = "25",
AlbumSpotifyId = "7uwTHXmFa1Ebi5flqBosig",
Artist = "Adele"
};
Subject.MapAlbumItem(data);
data.Should().NotBeNull();
data.Artist.Should().Be("Adele");
data.Album.Should().Be("25");
data.AlbumMusicBrainzId.Should().Be("5537624c-3d2f-4f5c-8099-df916082c85c");
}
[Test]
public void map_spotify_releases_should_only_map_album_id_for_album()
{
var data = new List<SpotifyImportListItemInfo>
{
new SpotifyImportListItemInfo
{
Album = "25",
AlbumSpotifyId = "7uwTHXmFa1Ebi5flqBosig",
Artist = "Adele",
ArtistSpotifyId = "4dpARuHxo51G3z768sgnrY"
}
};
var map = new List<SpotifyMap>
{
new SpotifyMap
{
SpotifyId = "7uwTHXmFa1Ebi5flqBosig",
MusicbrainzId = "5537624c-3d2f-4f5c-8099-df916082c85c"
},
new SpotifyMap
{
SpotifyId = "4dpARuHxo51G3z768sgnrY",
MusicbrainzId = "cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493"
}
};
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Post<List<SpotifyMap>>(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse<List<SpotifyMap>>(new HttpResponse(r, new HttpHeader(), map.ToJson())));
var result = Subject.MapSpotifyReleases(data);
result[0].AlbumMusicBrainzId.Should().Be("5537624c-3d2f-4f5c-8099-df916082c85c");
result[0].ArtistMusicBrainzId.Should().BeNull();
}
[Test]
public void map_spotify_releases_should_map_artist_id_for_artist()
{
var data = new List<SpotifyImportListItemInfo>
{
new SpotifyImportListItemInfo
{
Artist = "Adele",
ArtistSpotifyId = "4dpARuHxo51G3z768sgnrY"
}
};
var map = new List<SpotifyMap>
{
new SpotifyMap
{
SpotifyId = "7uwTHXmFa1Ebi5flqBosig",
MusicbrainzId = "5537624c-3d2f-4f5c-8099-df916082c85c"
},
new SpotifyMap
{
SpotifyId = "4dpARuHxo51G3z768sgnrY",
MusicbrainzId = "cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493"
}
};
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Post<List<SpotifyMap>>(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse<List<SpotifyMap>>(new HttpResponse(r, new HttpHeader(), map.ToJson())));
var result = Subject.MapSpotifyReleases(data);
result[0].ArtistMusicBrainzId.Should().Be("cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493");
}
[Test]
public void map_spotify_releases_should_drop_not_found()
{
var data = new List<SpotifyImportListItemInfo>
{
new SpotifyImportListItemInfo
{
Album = "25",
AlbumSpotifyId = "7uwTHXmFa1Ebi5flqBosig",
Artist = "Adele"
}
};
var map = new List<SpotifyMap>
{
new SpotifyMap
{
SpotifyId = "7uwTHXmFa1Ebi5flqBosig",
MusicbrainzId = "0"
}
};
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Post<List<SpotifyMap>>(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse<List<SpotifyMap>>(new HttpResponse(r, new HttpHeader(), map.ToJson())));
var result = Subject.MapSpotifyReleases(data);
result.Should().BeEmpty();
}
[Test]
public void map_spotify_releases_should_catch_exception_from_api()
{
var data = new List<SpotifyImportListItemInfo>
{
new SpotifyImportListItemInfo
{
Album = "25",
AlbumSpotifyId = "7uwTHXmFa1Ebi5flqBosig",
Artist = "Adele"
}
};
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Post<List<SpotifyMap>>(It.IsAny<HttpRequest>()))
.Throws(new Exception("Dummy exception"));
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Get<AlbumResource>(It.IsAny<HttpRequest>()))
.Throws(new Exception("Dummy exception"));
var result = Subject.MapSpotifyReleases(data);
result.Should().NotBeNull();
ExceptionVerification.ExpectedErrors(2);
}
[Test]
public void map_spotify_releases_should_cope_with_duplicate_spotify_ids()
{
var data = new List<SpotifyImportListItemInfo>
{
new SpotifyImportListItemInfo
{
Album = "25",
AlbumSpotifyId = "7uwTHXmFa1Ebi5flqBosig",
Artist = "Adele"
},
new SpotifyImportListItemInfo
{
Album = "25",
AlbumSpotifyId = "7uwTHXmFa1Ebi5flqBosig",
Artist = "Adele"
}
};
var map = new List<SpotifyMap>
{
new SpotifyMap
{
SpotifyId = "7uwTHXmFa1Ebi5flqBosig",
MusicbrainzId = "5537624c-3d2f-4f5c-8099-df916082c85c"
}
};
Mocker.GetMock<IHttpClient>()
.Setup(x => x.Post<List<SpotifyMap>>(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse<List<SpotifyMap>>(new HttpResponse(r, new HttpHeader(), map.ToJson())));
var result = Subject.MapSpotifyReleases(data);
result.Should().HaveCount(2);
result[0].AlbumMusicBrainzId.Should().Be("5537624c-3d2f-4f5c-8099-df916082c85c");
result[1].AlbumMusicBrainzId.Should().Be("5537624c-3d2f-4f5c-8099-df916082c85c");
}
}
}
@@ -1,277 +0,0 @@
using System.Collections.Generic;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.ImportLists.Spotify;
using NzbDrone.Core.Test.Framework;
using SpotifyAPI.Web;
using SpotifyAPI.Web.Models;
namespace NzbDrone.Core.Test.ImportListTests
{
[TestFixture]
public class SpotifyPlaylistFixture : CoreTest<SpotifyPlaylist>
{
// placeholder, we don't use real API
private readonly SpotifyWebAPI _api = null;
[Test]
public void should_not_throw_if_playlist_tracks_is_null()
{
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetPlaylistTracks(It.IsAny<SpotifyPlaylist>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Returns(default(Paging<PlaylistTrack>));
var result = Subject.Fetch(_api, "playlistid");
result.Should().BeEmpty();
}
[Test]
public void should_not_throw_if_playlist_tracks_items_is_null()
{
var playlistTracks = new Paging<PlaylistTrack>
{
Items = null
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetPlaylistTracks(It.IsAny<SpotifyPlaylist>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Returns(playlistTracks);
var result = Subject.Fetch(_api, "playlistid");
result.Should().BeEmpty();
}
[Test]
public void should_not_throw_if_playlist_track_is_null()
{
var playlistTracks = new Paging<PlaylistTrack>
{
Items = new List<PlaylistTrack>
{
null
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetPlaylistTracks(It.IsAny<SpotifyPlaylist>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Returns(playlistTracks);
var result = Subject.Fetch(_api, "playlistid");
result.Should().BeEmpty();
}
[Test]
public void should_use_album_artist_when_it_exists()
{
var playlistTracks = new Paging<PlaylistTrack>
{
Items = new List<PlaylistTrack>
{
new PlaylistTrack
{
Track = new FullTrack
{
Album = new SimpleAlbum
{
Name = "Album",
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = "AlbumArtist"
}
}
},
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = "TrackArtist"
}
}
}
}
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetPlaylistTracks(It.IsAny<SpotifyPlaylist>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Returns(playlistTracks);
var result = Subject.Fetch(_api, "playlistid");
result.Should().HaveCount(1);
result[0].Artist.Should().Be("AlbumArtist");
}
[Test]
public void should_fall_back_to_track_artist_if_album_artist_missing()
{
var playlistTracks = new Paging<PlaylistTrack>
{
Items = new List<PlaylistTrack>
{
new PlaylistTrack
{
Track = new FullTrack
{
Album = new SimpleAlbum
{
Name = "Album",
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = null
}
}
},
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = "TrackArtist"
}
}
}
}
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetPlaylistTracks(It.IsAny<SpotifyPlaylist>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Returns(playlistTracks);
var result = Subject.Fetch(_api, "playlistid");
result.Should().HaveCount(1);
result[0].Artist.Should().Be("TrackArtist");
}
[TestCase(null, null, "Album")]
[TestCase("AlbumArtist", null, null)]
[TestCase(null, "TrackArtist", null)]
public void should_skip_bad_artist_or_album_names(string albumArtistName, string trackArtistName, string albumName)
{
var playlistTracks = new Paging<PlaylistTrack>
{
Items = new List<PlaylistTrack>
{
new PlaylistTrack
{
Track = new FullTrack
{
Album = new SimpleAlbum
{
Name = albumName,
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = albumArtistName
}
}
},
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = trackArtistName
}
}
}
}
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetPlaylistTracks(It.IsAny<SpotifyPlaylist>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Returns(playlistTracks);
var result = Subject.Fetch(_api, "playlistid");
result.Should().BeEmpty();
}
[Test]
public void should_not_throw_if_get_next_page_returns_null()
{
var playlistTracks = new Paging<PlaylistTrack>
{
Items = new List<PlaylistTrack>
{
new PlaylistTrack
{
Track = new FullTrack
{
Album = new SimpleAlbum
{
Name = "Album",
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = null
}
}
},
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = "TrackArtist"
}
}
}
}
},
Next = "DummyToMakeHasNextTrue"
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetPlaylistTracks(It.IsAny<SpotifyPlaylist>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Returns(playlistTracks);
Mocker.GetMock<ISpotifyProxy>()
.Setup(x => x.GetNextPage(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<Paging<PlaylistTrack>>()))
.Returns(default(Paging<PlaylistTrack>));
var result = Subject.Fetch(_api, "playlistid");
result.Should().HaveCount(1);
Mocker.GetMock<ISpotifyProxy>()
.Verify(x => x.GetNextPage(It.IsAny<SpotifyPlaylist>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<Paging<PlaylistTrack>>()),
Times.Once());
}
}
}
@@ -1,187 +0,0 @@
using System.Collections.Generic;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.ImportLists.Spotify;
using NzbDrone.Core.Test.Framework;
using SpotifyAPI.Web;
using SpotifyAPI.Web.Models;
namespace NzbDrone.Core.Test.ImportListTests
{
[TestFixture]
public class SpotifySavedAlbumsFixture : CoreTest<SpotifySavedAlbums>
{
// placeholder, we don't use real API
private readonly SpotifyWebAPI _api = null;
[Test]
public void should_not_throw_if_saved_albums_is_null()
{
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetSavedAlbums(It.IsAny<SpotifySavedAlbums>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(default(Paging<SavedAlbum>));
var result = Subject.Fetch(_api);
result.Should().BeEmpty();
}
[Test]
public void should_not_throw_if_saved_album_items_is_null()
{
var savedAlbums = new Paging<SavedAlbum>
{
Items = null
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetSavedAlbums(It.IsAny<SpotifySavedAlbums>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(savedAlbums);
var result = Subject.Fetch(_api);
result.Should().BeEmpty();
}
[Test]
public void should_not_throw_if_saved_album_is_null()
{
var savedAlbums = new Paging<SavedAlbum>
{
Items = new List<SavedAlbum>
{
null
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetSavedAlbums(It.IsAny<SpotifySavedAlbums>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(savedAlbums);
var result = Subject.Fetch(_api);
result.Should().BeEmpty();
}
[TestCase("Artist", "Album")]
public void should_parse_saved_album(string artistName, string albumName)
{
var savedAlbums = new Paging<SavedAlbum>
{
Items = new List<SavedAlbum>
{
new SavedAlbum
{
Album = new FullAlbum
{
Name = albumName,
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = artistName
}
}
}
}
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetSavedAlbums(It.IsAny<SpotifySavedAlbums>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(savedAlbums);
var result = Subject.Fetch(_api);
result.Should().HaveCount(1);
}
[Test]
public void should_not_throw_if_get_next_page_returns_null()
{
var savedAlbums = new Paging<SavedAlbum>
{
Items = new List<SavedAlbum>
{
new SavedAlbum
{
Album = new FullAlbum
{
Name = "Album",
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = "Artist"
}
}
}
}
},
Next = "DummyToMakeHasNextTrue"
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetSavedAlbums(It.IsAny<SpotifySavedAlbums>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(savedAlbums);
Mocker.GetMock<ISpotifyProxy>()
.Setup(x => x.GetNextPage(It.IsAny<SpotifyFollowedArtists>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<Paging<SavedAlbum>>()))
.Returns(default(Paging<SavedAlbum>));
var result = Subject.Fetch(_api);
result.Should().HaveCount(1);
Mocker.GetMock<ISpotifyProxy>()
.Verify(x => x.GetNextPage(It.IsAny<SpotifySavedAlbums>(),
It.IsAny<SpotifyWebAPI>(),
It.IsAny<Paging<SavedAlbum>>()),
Times.Once());
}
[TestCase(null, "Album")]
[TestCase("Artist", null)]
[TestCase(null, null)]
public void should_skip_bad_artist_or_album_names(string artistName, string albumName)
{
var savedAlbums = new Paging<SavedAlbum>
{
Items = new List<SavedAlbum>
{
new SavedAlbum
{
Album = new FullAlbum
{
Name = albumName,
Artists = new List<SimpleArtist>
{
new SimpleArtist
{
Name = artistName
}
}
}
}
}
};
Mocker.GetMock<ISpotifyProxy>().
Setup(x => x.GetSavedAlbums(It.IsAny<SpotifySavedAlbums>(),
It.IsAny<SpotifyWebAPI>()))
.Returns(savedAlbums);
var result = Subject.Fetch(_api);
result.Should().BeEmpty();
}
}
}