mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
Fixed: MediaFileRepository was ignoring AlbumRelease monitored flag (#689)
This commit is contained in:
parent
b557f620d9
commit
6e4b1ba1fe
2 changed files with 41 additions and 15 deletions
|
@ -35,23 +35,31 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
.Build();
|
.Build();
|
||||||
Db.Insert(album);
|
Db.Insert(album);
|
||||||
|
|
||||||
var release = Builder<AlbumRelease>.CreateNew()
|
var releases = Builder<AlbumRelease>.CreateListOfSize(2)
|
||||||
|
.All()
|
||||||
.With(a => a.Id = 0)
|
.With(a => a.Id = 0)
|
||||||
.With(a => a.AlbumId = album.Id)
|
.With(a => a.AlbumId = album.Id)
|
||||||
|
.TheFirst(1)
|
||||||
.With(a => a.Monitored = true)
|
.With(a => a.Monitored = true)
|
||||||
|
.TheNext(1)
|
||||||
|
.With(a => a.Monitored = false)
|
||||||
.Build();
|
.Build();
|
||||||
Db.Insert(release);
|
Db.InsertMany(releases);
|
||||||
|
|
||||||
var files = Builder<TrackFile>.CreateListOfSize(10)
|
var files = Builder<TrackFile>.CreateListOfSize(10)
|
||||||
.All()
|
.All()
|
||||||
.With(c => c.Id = 0)
|
.With(c => c.Id = 0)
|
||||||
.With(c => c.Quality =new QualityModel(Quality.MP3_192))
|
.With(c => c.Quality =new QualityModel(Quality.MP3_192))
|
||||||
.TheFirst(4)
|
.TheFirst(5)
|
||||||
.With(c => c.AlbumId = album.Id)
|
.With(c => c.AlbumId = album.Id)
|
||||||
.BuildListOfNew();
|
.BuildListOfNew();
|
||||||
Db.InsertMany(files);
|
Db.InsertMany(files);
|
||||||
|
|
||||||
var track = Builder<Track>.CreateListOfSize(10)
|
var track = Builder<Track>.CreateListOfSize(10)
|
||||||
|
.All()
|
||||||
|
.With(a => a.Id = 0)
|
||||||
|
.TheFirst(4)
|
||||||
|
.With(a => a.AlbumReleaseId = releases[0].Id)
|
||||||
.TheFirst(1)
|
.TheFirst(1)
|
||||||
.With(a => a.TrackFileId = files[0].Id)
|
.With(a => a.TrackFileId = files[0].Id)
|
||||||
.TheNext(1)
|
.TheNext(1)
|
||||||
|
@ -60,11 +68,11 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
.With(a => a.TrackFileId = files[2].Id)
|
.With(a => a.TrackFileId = files[2].Id)
|
||||||
.TheNext(1)
|
.TheNext(1)
|
||||||
.With(a => a.TrackFileId = files[3].Id)
|
.With(a => a.TrackFileId = files[3].Id)
|
||||||
.TheNext(6)
|
.TheNext(1)
|
||||||
|
.With(a => a.TrackFileId = files[4].Id)
|
||||||
|
.With(a => a.AlbumReleaseId = releases[1].Id)
|
||||||
|
.TheNext(5)
|
||||||
.With(a => a.TrackFileId = 0)
|
.With(a => a.TrackFileId = 0)
|
||||||
.All()
|
|
||||||
.With(a => a.Id = 0)
|
|
||||||
.With(a => a.AlbumReleaseId = release.Id)
|
|
||||||
.Build();
|
.Build();
|
||||||
Db.InsertMany(track);
|
Db.InsertMany(track);
|
||||||
}
|
}
|
||||||
|
@ -76,10 +84,19 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
var artistFiles = Subject.GetFilesByArtist(artist.Id);
|
var artistFiles = Subject.GetFilesByArtist(artist.Id);
|
||||||
VerifyEagerLoaded(artistFiles);
|
VerifyEagerLoaded(artistFiles);
|
||||||
|
|
||||||
artistFiles.Should().HaveCount(4);
|
|
||||||
artistFiles.Should().OnlyContain(c => c.Artist.Value.Id == artist.Id);
|
artistFiles.Should().OnlyContain(c => c.Artist.Value.Id == artist.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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]
|
[Test]
|
||||||
public void get_files_by_album()
|
public void get_files_by_album()
|
||||||
{
|
{
|
||||||
|
@ -87,8 +104,8 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
var files = Subject.GetFilesByAlbum(album.Id);
|
var files = Subject.GetFilesByAlbum(album.Id);
|
||||||
VerifyEagerLoaded(files);
|
VerifyEagerLoaded(files);
|
||||||
|
|
||||||
files.Should().HaveCount(4);
|
|
||||||
files.Should().OnlyContain(c => c.AlbumId == album.Id);
|
files.Should().OnlyContain(c => c.AlbumId == album.Id);
|
||||||
|
files.Should().HaveCount(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -98,11 +115,21 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
var files = Subject.GetFilesWithRelativePath(artist.Id, "RelativePath2");
|
var files = Subject.GetFilesWithRelativePath(artist.Id, "RelativePath2");
|
||||||
VerifyEagerLoaded(files);
|
VerifyEagerLoaded(files);
|
||||||
|
|
||||||
files.Should().HaveCount(1);
|
|
||||||
files.Should().OnlyContain(c => c.AlbumId == album.Id);
|
files.Should().OnlyContain(c => c.AlbumId == album.Id);
|
||||||
files.Should().OnlyContain(c => c.RelativePath == "RelativePath2");
|
files.Should().OnlyContain(c => c.RelativePath == "RelativePath2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void get_files_by_relative_path_should_only_contain_monitored_releases()
|
||||||
|
{
|
||||||
|
VerifyData();
|
||||||
|
|
||||||
|
// file 5 is linked to an unmonitored release
|
||||||
|
var files = Subject.GetFilesWithRelativePath(artist.Id, "RelativePath5");
|
||||||
|
|
||||||
|
files.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private void VerifyData()
|
private void VerifyData()
|
||||||
{
|
{
|
||||||
Db.All<Artist>().Should().HaveCount(1);
|
Db.All<Artist>().Should().HaveCount(1);
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
public List<TrackFile> GetFilesByArtist(int artistId)
|
public List<TrackFile> GetFilesByArtist(int artistId)
|
||||||
{
|
{
|
||||||
return Query
|
return Query
|
||||||
.Join<Album, AlbumRelease>(JoinType.Inner, a => a.AlbumReleases, (a, r) => a.Id == r.AlbumId)
|
.Join<Track, AlbumRelease>(JoinType.Inner, t => t.AlbumRelease, (t, r) => t.AlbumReleaseId == r.Id)
|
||||||
.Where<AlbumRelease>(r => r.Monitored == true)
|
.Where<AlbumRelease>(r => r.Monitored == true)
|
||||||
.AndWhere(t => t.Artist.Value.Id == artistId)
|
.AndWhere(t => t.Artist.Value.Id == artistId)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
@ -58,10 +58,9 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
public List<TrackFile> GetFilesWithRelativePath(int artistId, string relativePath)
|
public List<TrackFile> GetFilesWithRelativePath(int artistId, string relativePath)
|
||||||
{
|
{
|
||||||
return Query
|
return Query
|
||||||
.Join<Album, AlbumRelease>(JoinType.Inner, a => a.AlbumReleases, (a, r) => a.Id == r.AlbumId)
|
.Join<Track, AlbumRelease>(JoinType.Inner, t => t.AlbumRelease, (t, r) => t.AlbumReleaseId == r.Id)
|
||||||
.Where<AlbumRelease>(r => r.Monitored == true)
|
.Where<AlbumRelease>(r => r.Monitored == true)
|
||||||
.AndWhere(t => t.Artist.Value.Id == artistId)
|
.AndWhere(t => t.Artist.Value.Id == artistId && t.RelativePath == relativePath)
|
||||||
.AndWhere(t => t.RelativePath == relativePath)
|
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue