Fixed: Artist FindById Should Find OldIds

This commit is contained in:
Qstick
2019-09-22 17:50:14 -04:00
parent 55e141c44b
commit f4e4bae465
3 changed files with 61 additions and 18 deletions
@@ -19,7 +19,6 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
{
private ArtistRepository _artistRepo;
private ArtistMetadataRepository _artistMetadataRepo;
private int _id = 1;
[SetUp]
public void Setup()
@@ -28,20 +27,25 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
_artistMetadataRepo = Mocker.Resolve<ArtistMetadataRepository>();
}
private void AddArtist(string name)
private void AddArtist(string name, string foreignId, List<string> oldIds = null)
{
if (oldIds == null)
{
oldIds = new List<string>();
}
var metadata = Builder<ArtistMetadata>.CreateNew()
.With(a => a.Id = 0)
.With(a => a.Name = name)
.With(a=> a.OldForeignArtistIds = oldIds)
.BuildNew();
var artist = Builder<Artist>.CreateNew()
.With(a => a.Id = 0)
.With(a => a.Metadata = metadata)
.With(a => a.CleanName = Parser.Parser.CleanArtistName(name))
.With(a => a.ForeignArtistId = _id.ToString())
.With(a => a.ForeignArtistId = foreignId)
.BuildNew();
_id++;
_artistMetadataRepo.Insert(metadata);
artist.ArtistMetadataId = metadata.Id;
@@ -50,8 +54,8 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
private void GivenArtists()
{
AddArtist("The Black Eyed Peas");
AddArtist("The Black Keys");
AddArtist("The Black Eyed Peas", "d5be5333-4171-427e-8e12-732087c6b78e");
AddArtist("The Black Keys", "d15721d8-56b4-453d-b506-fc915b14cba2", new List<string> { "6f2ed437-825c-4cea-bb58-bf7688c6317a" });
}
[Test]
@@ -100,14 +104,35 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
artist.Name.Should().Be(name);
}
[Test]
public void should_find_artist_in_by_id()
{
GivenArtists();
var artist = _artistRepo.FindById("d5be5333-4171-427e-8e12-732087c6b78e");
artist.Should().NotBeNull();
artist.ForeignArtistId.Should().Be("d5be5333-4171-427e-8e12-732087c6b78e");
}
[Test]
public void should_find_artist_in_by_old_id()
{
GivenArtists();
var artist = _artistRepo.FindById("6f2ed437-825c-4cea-bb58-bf7688c6317a");
artist.Should().NotBeNull();
artist.Name.Should().Be("The Black Keys");
artist.ForeignArtistId.Should().Be("d15721d8-56b4-453d-b506-fc915b14cba2");
}
[Test]
public void should_not_find_artist_if_multiple_artists_have_same_name()
{
GivenArtists();
string name = "Alice Cooper";
AddArtist(name);
AddArtist(name);
AddArtist(name, "ee58c59f-8e7f-4430-b8ca-236c4d3745ae");
AddArtist(name, "4d7928cd-7ed2-4282-8c29-c0c9f966f1bd");
_artistRepo.All().Should().HaveCount(4);