mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 13:10:13 -07:00
Fixed: InvalidOperationException when two artists have same name
This commit is contained in:
parent
15425a45a3
commit
c500f7b943
2 changed files with 20 additions and 3 deletions
|
@ -19,6 +19,7 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
|
||||||
{
|
{
|
||||||
private ArtistRepository _artistRepo;
|
private ArtistRepository _artistRepo;
|
||||||
private ArtistMetadataRepository _artistMetadataRepo;
|
private ArtistMetadataRepository _artistMetadataRepo;
|
||||||
|
private int _id = 1;
|
||||||
|
|
||||||
private void AddArtist(string name)
|
private void AddArtist(string name)
|
||||||
{
|
{
|
||||||
|
@ -31,8 +32,9 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
|
||||||
.With(a => a.Id = 0)
|
.With(a => a.Id = 0)
|
||||||
.With(a => a.Metadata = metadata)
|
.With(a => a.Metadata = metadata)
|
||||||
.With(a => a.CleanName = Parser.Parser.CleanArtistName(name))
|
.With(a => a.CleanName = Parser.Parser.CleanArtistName(name))
|
||||||
.With(a => a.ForeignArtistId = name)
|
.With(a => a.ForeignArtistId = _id.ToString())
|
||||||
.BuildNew();
|
.BuildNew();
|
||||||
|
_id++;
|
||||||
|
|
||||||
_artistMetadataRepo.Insert(artist);
|
_artistMetadataRepo.Insert(artist);
|
||||||
_artistRepo.Insert(artist);
|
_artistRepo.Insert(artist);
|
||||||
|
@ -101,5 +103,20 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
|
||||||
artist.Should().NotBeNull();
|
artist.Should().NotBeNull();
|
||||||
artist.Name.Should().Be(name);
|
artist.Name.Should().Be(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_find_artist_if_multiple_artists_have_same_name()
|
||||||
|
{
|
||||||
|
GivenArtists();
|
||||||
|
|
||||||
|
string name = "Alice Cooper";
|
||||||
|
AddArtist(name);
|
||||||
|
AddArtist(name);
|
||||||
|
|
||||||
|
_artistRepo.All().Should().HaveCount(4);
|
||||||
|
|
||||||
|
var artist = _artistRepo.FindByName(Parser.Parser.CleanArtistName(name));
|
||||||
|
artist.Should().BeNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using Marr.Data.QGen;
|
using Marr.Data.QGen;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Music
|
namespace NzbDrone.Core.Music
|
||||||
{
|
{
|
||||||
|
@ -43,8 +44,7 @@ namespace NzbDrone.Core.Music
|
||||||
{
|
{
|
||||||
cleanName = cleanName.ToLowerInvariant();
|
cleanName = cleanName.ToLowerInvariant();
|
||||||
|
|
||||||
return Query.Where(s => s.CleanName == cleanName)
|
return Query.Where(s => s.CleanName == cleanName).ExclusiveOrDefault();
|
||||||
.SingleOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Artist GetArtistByMetadataId(int artistMetadataId)
|
public Artist GetArtistByMetadataId(int artistMetadataId)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue