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
@@ -12,76 +12,43 @@ using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MediaFiles
{
[TestFixture]
public class MediaFileRepositoryFixture : DbTest<MediaFileRepository, TrackFile>
public class MediaFileRepositoryFixture : DbTest<MediaFileRepository, BookFile>
{
private Artist _artist;
private Album _album;
private List<AlbumRelease> _releases;
private Author _artist;
private Book _album;
[SetUp]
public void Setup()
{
var meta = Builder<ArtistMetadata>.CreateNew()
var meta = Builder<AuthorMetadata>.CreateNew()
.With(a => a.Id = 0)
.Build();
Db.Insert(meta);
_artist = Builder<Artist>.CreateNew()
.With(a => a.ArtistMetadataId = meta.Id)
_artist = Builder<Author>.CreateNew()
.With(a => a.AuthorMetadataId = meta.Id)
.With(a => a.Id = 0)
.Build();
Db.Insert(_artist);
_album = Builder<Album>.CreateNew()
_album = Builder<Book>.CreateNew()
.With(a => a.Id = 0)
.With(a => a.ArtistMetadataId = _artist.ArtistMetadataId)
.With(a => a.AuthorMetadataId = _artist.AuthorMetadataId)
.Build();
Db.Insert(_album);
_releases = Builder<AlbumRelease>.CreateListOfSize(2)
.All()
.With(a => a.Id = 0)
.With(a => a.AlbumId = _album.Id)
.TheFirst(1)
.With(a => a.Monitored = true)
.TheNext(1)
.With(a => a.Monitored = false)
.Build().ToList();
Db.InsertMany(_releases);
var files = Builder<TrackFile>.CreateListOfSize(10)
var files = Builder<BookFile>.CreateListOfSize(10)
.All()
.With(c => c.Id = 0)
.With(c => c.Quality = new QualityModel(Quality.MP3_192))
.With(c => c.Quality = new QualityModel(Quality.MP3_320))
.TheFirst(5)
.With(c => c.AlbumId = _album.Id)
.With(c => c.BookId = _album.Id)
.TheFirst(1)
.With(c => c.Path = @"C:\Test\Path\Artist\somefile1.flac".AsOsAgnostic())
.TheNext(1)
.With(c => c.Path = @"C:\Test\Path\Artist\somefile2.flac".AsOsAgnostic())
.BuildListOfNew();
Db.InsertMany(files);
var track = Builder<Track>.CreateListOfSize(10)
.All()
.With(a => a.Id = 0)
.TheFirst(4)
.With(a => a.AlbumReleaseId = _releases[0].Id)
.TheFirst(1)
.With(a => a.TrackFileId = files[0].Id)
.TheNext(1)
.With(a => a.TrackFileId = files[1].Id)
.TheNext(1)
.With(a => a.TrackFileId = files[2].Id)
.TheNext(1)
.With(a => a.TrackFileId = files[3].Id)
.TheNext(1)
.With(a => a.TrackFileId = files[4].Id)
.With(a => a.AlbumReleaseId = _releases[1].Id)
.TheNext(5)
.With(a => a.TrackFileId = 0)
.Build();
Db.InsertMany(track);
}
[Test]
@@ -104,19 +71,6 @@ namespace NzbDrone.Core.Test.MediaFiles
unmappedfiles.Should().HaveCount(5);
}
[Test]
public void get_files_by_release()
{
VerifyData();
var firstReleaseFiles = Subject.GetFilesByRelease(_releases[0].Id);
var secondReleaseFiles = Subject.GetFilesByRelease(_releases[1].Id);
VerifyEagerLoaded(firstReleaseFiles);
VerifyEagerLoaded(secondReleaseFiles);
firstReleaseFiles.Should().HaveCount(4);
secondReleaseFiles.Should().HaveCount(1);
}
[TestCase("C:\\Test\\Path")]
[TestCase("C:\\Test\\Path\\")]
public void get_files_by_base_path_should_cope_with_trailing_slash(string dir)
@@ -133,10 +87,10 @@ namespace NzbDrone.Core.Test.MediaFiles
{
VerifyData();
var files = Builder<TrackFile>.CreateListOfSize(2)
var files = Builder<BookFile>.CreateListOfSize(2)
.All()
.With(c => c.Id = 0)
.With(c => c.Quality = new QualityModel(Quality.MP3_192))
.With(c => c.Quality = new QualityModel(Quality.MP3_320))
.TheFirst(1)
.With(c => c.Path = @"C:\Test\Path2\Artist\somefile1.flac".AsOsAgnostic())
.TheNext(1)
@@ -155,25 +109,12 @@ namespace NzbDrone.Core.Test.MediaFiles
var file = Subject.GetFileWithPath(@"C:\Test\Path\Artist\somefile2.flac".AsOsAgnostic());
file.Should().NotBeNull();
file.Tracks.IsLoaded.Should().BeTrue();
file.Tracks.Value.Should().NotBeNull();
file.Tracks.Value.Should().NotBeEmpty();
file.Album.IsLoaded.Should().BeTrue();
file.Album.Value.Should().NotBeNull();
file.Artist.IsLoaded.Should().BeTrue();
file.Artist.Value.Should().NotBeNull();
}
[Test]
public void get_files_by_artist_should_only_return_tracks_for_monitored_releases()
{
VerifyData();
var artistFiles = Subject.GetFilesByArtist(_artist.Id);
VerifyEagerLoaded(artistFiles);
artistFiles.Should().HaveCount(4);
}
[Test]
public void get_files_by_album()
{
@@ -181,34 +122,20 @@ namespace NzbDrone.Core.Test.MediaFiles
var files = Subject.GetFilesByAlbum(_album.Id);
VerifyEagerLoaded(files);
files.Should().OnlyContain(c => c.AlbumId == _album.Id);
}
[Test]
public void get_files_by_album_should_only_return_tracks_for_monitored_releases()
{
VerifyData();
var files = Subject.GetFilesByAlbum(_album.Id);
VerifyEagerLoaded(files);
files.Should().HaveCount(4);
files.Should().OnlyContain(c => c.BookId == _album.Id);
}
private void VerifyData()
{
Db.All<Artist>().Should().HaveCount(1);
Db.All<Album>().Should().HaveCount(1);
Db.All<Track>().Should().HaveCount(10);
Db.All<TrackFile>().Should().HaveCount(10);
Db.All<Author>().Should().HaveCount(1);
Db.All<Book>().Should().HaveCount(1);
Db.All<BookFile>().Should().HaveCount(10);
}
private void VerifyEagerLoaded(List<TrackFile> files)
private void VerifyEagerLoaded(List<BookFile> files)
{
foreach (var file in files)
{
file.Tracks.IsLoaded.Should().BeTrue();
file.Tracks.Value.Should().NotBeNull();
file.Tracks.Value.Should().NotBeEmpty();
file.Album.IsLoaded.Should().BeTrue();
file.Album.Value.Should().NotBeNull();
file.Artist.IsLoaded.Should().BeTrue();
@@ -218,13 +145,10 @@ namespace NzbDrone.Core.Test.MediaFiles
}
}
private void VerifyUnmapped(List<TrackFile> files)
private void VerifyUnmapped(List<BookFile> files)
{
foreach (var file in files)
{
file.Tracks.IsLoaded.Should().BeFalse();
file.Tracks.Value.Should().NotBeNull();
file.Tracks.Value.Should().BeEmpty();
file.Album.IsLoaded.Should().BeFalse();
file.Album.Value.Should().BeNull();
file.Artist.IsLoaded.Should().BeFalse();
@@ -238,7 +162,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Db.Delete(_album);
Subject.DeleteFilesByAlbum(_album.Id);
Db.All<TrackFile>().Where(x => x.AlbumId == _album.Id).Should().HaveCount(0);
Db.All<BookFile>().Where(x => x.BookId == _album.Id).Should().HaveCount(0);
}
}
}