Fixed: Don't find album when multiple albums have the same name

pull/672/head
Tom Andrews 5 years ago committed by ta264
parent c500f7b943
commit 36f34a4113

@ -13,7 +13,6 @@ namespace NzbDrone.Core.Test.MusicTests.AlbumRepositoryTests
private Artist _artist;
private Album _album;
private Album _albumSpecial;
private Album _albumSimilar;
private AlbumRelease _release;
private AlbumRepository _albumRepo;
private ReleaseRepository _releaseRepo;
@ -48,6 +47,7 @@ namespace NzbDrone.Core.Test.MusicTests.AlbumRepositoryTests
ForeignAlbumId = "1",
CleanTitle = "anthology",
Artist = _artist,
ArtistMetadataId = _artist.ArtistMetadataId,
AlbumType = "",
AlbumReleases = new List<AlbumRelease> {_release },
};
@ -63,7 +63,7 @@ namespace NzbDrone.Core.Test.MusicTests.AlbumRepositoryTests
ForeignAlbumId = "2",
CleanTitle = "",
Artist = _artist,
ArtistId = _artist.ArtistMetadataId,
ArtistMetadataId = _artist.ArtistMetadataId,
AlbumType = "",
AlbumReleases = new List<AlbumRelease>
{
@ -77,24 +77,6 @@ namespace NzbDrone.Core.Test.MusicTests.AlbumRepositoryTests
_albumRepo.Insert(_albumSpecial);
_albumSimilar = new Album
{
Title = "ANThology2",
ForeignAlbumId = "3",
CleanTitle = "anthology2",
Artist = _artist,
ArtistId = _artist.ArtistMetadataId,
AlbumType = "",
AlbumReleases = new List<AlbumRelease>
{
new AlbumRelease
{
ForeignReleaseId = "fake id 2"
}
}
};
}
[Test]
@ -139,6 +121,26 @@ namespace NzbDrone.Core.Test.MusicTests.AlbumRepositoryTests
album.Should().BeNull();
}
[Test]
public void should_not_find_album_when_two_albums_have_same_name()
{
var albums = Builder<Album>.CreateListOfSize(2)
.All()
.With(x => x.Id = 0)
.With(x => x.Artist = _artist)
.With(x => x.ArtistMetadataId = _artist.ArtistMetadataId)
.With(x => x.Title = "Weezer")
.With(x => x.CleanTitle = "weezer")
.Build();
_albumRepo.InsertMany(albums);
var album = _albumRepo.FindByTitle(_artist.ArtistMetadataId, "Weezer");
_albumRepo.All().Should().HaveCount(4);
album.Should().BeNull();
}
[Test]
public void should_not_find_album_in_db_by_partial_releaseid()
{

@ -8,6 +8,7 @@ using System.Collections.Generic;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Qualities;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Music
{
@ -15,9 +16,7 @@ namespace NzbDrone.Core.Music
{
List<Album> GetAlbums(int artistId);
List<Album> GetAlbumsByArtistMetadataId(int artistMetadataId);
Album FindByName(string cleanTitle);
Album FindByTitle(int artistMetadataId, string title);
Album FindByArtistAndName(string artistName, string cleanTitle);
Album FindById(string foreignId);
List<Album> FindById(List<string> foreignIds);
PagingSpec<Album> AlbumsWithoutFiles(PagingSpec<Album> pagingSpec);
@ -328,13 +327,6 @@ namespace NzbDrone.Core.Music
mapper.ExecuteNonQuery(sql);
}
public Album FindByName(string cleanTitle)
{
cleanTitle = cleanTitle.ToLowerInvariant();
return Query.Where(s => s.CleanTitle == cleanTitle).SingleOrDefault();
}
public Album FindByTitle(int artistMetadataId, string title)
{
var cleanTitle = Parser.Parser.CleanArtistName(title);
@ -344,18 +336,7 @@ namespace NzbDrone.Core.Music
return Query.Where(s => s.CleanTitle == cleanTitle || s.Title == title)
.AndWhere(s => s.ArtistMetadataId == artistMetadataId)
.FirstOrDefault();
}
public Album FindByArtistAndName(string artistName, string cleanTitle)
{
var cleanArtistName = Parser.Parser.CleanArtistName(artistName);
cleanTitle = cleanTitle.ToLowerInvariant();
return Query.Join<Album, Artist>(JoinType.Inner, rg => rg.Artist, (rg, artist) => rg.ArtistMetadataId == artist.ArtistMetadataId)
.Where<Artist>(artist => artist.CleanName == cleanArtistName)
.Where<Album>(album => album.CleanTitle == cleanTitle)
.SingleOrDefault();
.ExclusiveOrDefault();
}
public Album FindAlbumByRelease(string albumReleaseId)

Loading…
Cancel
Save