mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-21 22:04:31 -04:00
@@ -1,12 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MediaFiles
|
||||
@@ -14,10 +14,10 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
[TestFixture]
|
||||
public class MediaFileRepositoryFixture : DbTest<MediaFileRepository, TrackFile>
|
||||
{
|
||||
private Artist artist;
|
||||
private Album album;
|
||||
private List<AlbumRelease> releases;
|
||||
|
||||
private Artist _artist;
|
||||
private Album _album;
|
||||
private List<AlbumRelease> _releases;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
@@ -25,48 +25,48 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
.With(a => a.Id = 0)
|
||||
.Build();
|
||||
Db.Insert(meta);
|
||||
|
||||
artist = Builder<Artist>.CreateNew()
|
||||
|
||||
_artist = Builder<Artist>.CreateNew()
|
||||
.With(a => a.ArtistMetadataId = meta.Id)
|
||||
.With(a => a.Id = 0)
|
||||
.Build();
|
||||
Db.Insert(artist);
|
||||
Db.Insert(_artist);
|
||||
|
||||
album = Builder<Album>.CreateNew()
|
||||
_album = Builder<Album>.CreateNew()
|
||||
.With(a => a.Id = 0)
|
||||
.With(a => a.ArtistMetadataId = artist.ArtistMetadataId)
|
||||
.With(a => a.ArtistMetadataId = _artist.ArtistMetadataId)
|
||||
.Build();
|
||||
Db.Insert(album);
|
||||
|
||||
releases = Builder<AlbumRelease>.CreateListOfSize(2)
|
||||
Db.Insert(_album);
|
||||
|
||||
_releases = Builder<AlbumRelease>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(a => a.Id = 0)
|
||||
.With(a => a.AlbumId = album.Id)
|
||||
.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);
|
||||
|
||||
Db.InsertMany(_releases);
|
||||
|
||||
var files = Builder<TrackFile>.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_192))
|
||||
.TheFirst(5)
|
||||
.With(c => c.AlbumId = album.Id)
|
||||
.With(c => c.AlbumId = _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)
|
||||
.With(a => a.AlbumReleaseId = _releases[0].Id)
|
||||
.TheFirst(1)
|
||||
.With(a => a.TrackFileId = files[0].Id)
|
||||
.TheNext(1)
|
||||
@@ -77,21 +77,21 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
.With(a => a.TrackFileId = files[3].Id)
|
||||
.TheNext(1)
|
||||
.With(a => a.TrackFileId = files[4].Id)
|
||||
.With(a => a.AlbumReleaseId = releases[1].Id)
|
||||
.With(a => a.AlbumReleaseId = _releases[1].Id)
|
||||
.TheNext(5)
|
||||
.With(a => a.TrackFileId = 0)
|
||||
.Build();
|
||||
Db.InsertMany(track);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void get_files_by_artist()
|
||||
{
|
||||
VerifyData();
|
||||
var artistFiles = Subject.GetFilesByArtist(artist.Id);
|
||||
var artistFiles = Subject.GetFilesByArtist(_artist.Id);
|
||||
VerifyEagerLoaded(artistFiles);
|
||||
|
||||
artistFiles.Should().OnlyContain(c => c.Artist.Value.Id == artist.Id);
|
||||
artistFiles.Should().OnlyContain(c => c.Artist.Value.Id == _artist.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -108,8 +108,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
public void get_files_by_release()
|
||||
{
|
||||
VerifyData();
|
||||
var firstReleaseFiles = Subject.GetFilesByRelease(releases[0].Id);
|
||||
var secondReleaseFiles = Subject.GetFilesByRelease(releases[1].Id);
|
||||
var firstReleaseFiles = Subject.GetFilesByRelease(_releases[0].Id);
|
||||
var secondReleaseFiles = Subject.GetFilesByRelease(_releases[1].Id);
|
||||
VerifyEagerLoaded(firstReleaseFiles);
|
||||
VerifyEagerLoaded(secondReleaseFiles);
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
var files = Builder<TrackFile>.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_192))
|
||||
.TheFirst(1)
|
||||
.With(c => c.Path = @"C:\Test\Path2\Artist\somefile1.flac".AsOsAgnostic())
|
||||
.TheNext(1)
|
||||
@@ -169,7 +169,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
public void get_files_by_artist_should_only_return_tracks_for_monitored_releases()
|
||||
{
|
||||
VerifyData();
|
||||
var artistFiles = Subject.GetFilesByArtist(artist.Id);
|
||||
var artistFiles = Subject.GetFilesByArtist(_artist.Id);
|
||||
VerifyEagerLoaded(artistFiles);
|
||||
|
||||
artistFiles.Should().HaveCount(4);
|
||||
@@ -179,19 +179,19 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
public void get_files_by_album()
|
||||
{
|
||||
VerifyData();
|
||||
var files = Subject.GetFilesByAlbum(album.Id);
|
||||
var files = Subject.GetFilesByAlbum(_album.Id);
|
||||
VerifyEagerLoaded(files);
|
||||
|
||||
files.Should().OnlyContain(c => c.AlbumId == album.Id);
|
||||
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);
|
||||
var files = Subject.GetFilesByAlbum(_album.Id);
|
||||
VerifyEagerLoaded(files);
|
||||
|
||||
|
||||
files.Should().HaveCount(4);
|
||||
}
|
||||
|
||||
@@ -236,10 +236,10 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||
[Test]
|
||||
public void delete_files_by_album_should_work_if_join_fails()
|
||||
{
|
||||
Db.Delete(album);
|
||||
Subject.DeleteFilesByAlbum(album.Id);
|
||||
|
||||
Db.All<TrackFile>().Where(x => x.AlbumId == album.Id).Should().HaveCount(0);
|
||||
Db.Delete(_album);
|
||||
Subject.DeleteFilesByAlbum(_album.Id);
|
||||
|
||||
Db.All<TrackFile>().Where(x => x.AlbumId == _album.Id).Should().HaveCount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user