Fixed: InvalidOperationException when two artists have same name

pull/672/head
Tom Andrews 5 years ago committed by ta264
parent 15425a45a3
commit c500f7b943

@ -19,6 +19,7 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
{
private ArtistRepository _artistRepo;
private ArtistMetadataRepository _artistMetadataRepo;
private int _id = 1;
private void AddArtist(string name)
{
@ -31,8 +32,9 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
.With(a => a.Id = 0)
.With(a => a.Metadata = metadata)
.With(a => a.CleanName = Parser.Parser.CleanArtistName(name))
.With(a => a.ForeignArtistId = name)
.With(a => a.ForeignArtistId = _id.ToString())
.BuildNew();
_id++;
_artistMetadataRepo.Insert(artist);
_artistRepo.Insert(artist);
@ -101,5 +103,20 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
artist.Should().NotBeNull();
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.Messaging.Events;
using Marr.Data.QGen;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Music
{
@ -43,8 +44,7 @@ namespace NzbDrone.Core.Music
{
cleanName = cleanName.ToLowerInvariant();
return Query.Where(s => s.CleanName == cleanName)
.SingleOrDefault();
return Query.Where(s => s.CleanName == cleanName).ExclusiveOrDefault();
}
public Artist GetArtistByMetadataId(int artistMetadataId)

Loading…
Cancel
Save