Cleanup Conflicts in Sonarr/Lidarr Pulls

Co-Authored-By: Robin Dadswell <19610103+RobinDadswell@users.noreply.github.com>
This commit is contained in:
Qstick
2021-01-24 02:22:50 -05:00
parent ffc12656ee
commit 93ba5ade9e
298 changed files with 4460 additions and 4508 deletions
@@ -19,54 +19,54 @@ using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MusicTests
{
[TestFixture]
public class RefreshArtistServiceFixture : CoreTest<RefreshAuthorService>
public class RefreshAuthorServiceFixture : CoreTest<RefreshAuthorService>
{
private Author _artist;
private Book _album1;
private Book _album2;
private List<Book> _albums;
private Author _author;
private Book _book1;
private Book _book2;
private List<Book> _books;
private List<Book> _remoteBooks;
[SetUp]
public void Setup()
{
_album1 = Builder<Book>.CreateNew()
_book1 = Builder<Book>.CreateNew()
.With(s => s.ForeignBookId = "1")
.Build();
_album2 = Builder<Book>.CreateNew()
_book2 = Builder<Book>.CreateNew()
.With(s => s.ForeignBookId = "2")
.Build();
_albums = new List<Book> { _album1, _album2 };
_books = new List<Book> { _book1, _book2 };
_remoteBooks = _albums.JsonClone();
_remoteBooks = _books.JsonClone();
_remoteBooks.ForEach(x => x.Id = 0);
var metadata = Builder<AuthorMetadata>.CreateNew().Build();
var series = Builder<Series>.CreateListOfSize(1).BuildList();
var profile = Builder<MetadataProfile>.CreateNew().Build();
_artist = Builder<Author>.CreateNew()
_author = Builder<Author>.CreateNew()
.With(a => a.Metadata = metadata)
.With(a => a.Series = series)
.With(a => a.MetadataProfile = profile)
.Build();
Mocker.GetMock<IAuthorService>(MockBehavior.Strict)
.Setup(s => s.GetAuthors(new List<int> { _artist.Id }))
.Returns(new List<Author> { _artist });
.Setup(s => s.GetAuthors(new List<int> { _author.Id }))
.Returns(new List<Author> { _author });
Mocker.GetMock<IBookService>(MockBehavior.Strict)
.Setup(s => s.InsertMany(It.IsAny<List<Book>>()));
Mocker.GetMock<IMetadataProfileService>()
.Setup(s => s.FilterBooks(It.IsAny<Author>(), It.IsAny<int>()))
.Returns(_albums);
.Returns(_books);
Mocker.GetMock<IProvideAuthorInfo>()
.Setup(s => s.GetAuthorAndBooks(It.IsAny<string>(), It.IsAny<double>()))
.Callback(() => { throw new AuthorNotFoundException(_artist.ForeignAuthorId); });
.Callback(() => { throw new AuthorNotFoundException(_author.ForeignAuthorId); });
Mocker.GetMock<IMediaFileService>()
.Setup(x => x.GetFilesByAuthor(It.IsAny<int>()))
@@ -85,28 +85,28 @@ namespace NzbDrone.Core.Test.MusicTests
.Returns(new List<RootFolder>());
}
private void GivenNewArtistInfo(Author artist)
private void GivenNewAuthorInfo(Author author)
{
Mocker.GetMock<IProvideAuthorInfo>()
.Setup(s => s.GetAuthorAndBooks(_artist.ForeignAuthorId, It.IsAny<double>()))
.Returns(artist);
.Setup(s => s.GetAuthorAndBooks(_author.ForeignAuthorId, It.IsAny<double>()))
.Returns(author);
}
private void GivenArtistFiles()
private void GivenAuthorFiles()
{
Mocker.GetMock<IMediaFileService>()
.Setup(x => x.GetFilesByAuthor(It.IsAny<int>()))
.Returns(Builder<BookFile>.CreateListOfSize(1).BuildList());
}
private void GivenAlbumsForRefresh(List<Book> albums)
private void GivenBooksForRefresh(List<Book> books)
{
Mocker.GetMock<IBookService>(MockBehavior.Strict)
.Setup(s => s.GetBooksForRefresh(It.IsAny<int>(), It.IsAny<IEnumerable<string>>()))
.Returns(albums);
.Returns(books);
}
private void AllowArtistUpdate()
private void AllowAuthorUpdate()
{
Mocker.GetMock<IAuthorService>(MockBehavior.Strict)
.Setup(x => x.UpdateAuthor(It.IsAny<Author>()))
@@ -114,50 +114,50 @@ namespace NzbDrone.Core.Test.MusicTests
}
[Test]
public void should_not_publish_artist_updated_event_if_metadata_not_updated()
public void should_not_publish_author_updated_event_if_metadata_not_updated()
{
var newArtistInfo = _artist.JsonClone();
newArtistInfo.Metadata = _artist.Metadata.Value.JsonClone();
newArtistInfo.Books = _remoteBooks;
var newAuthorInfo = _author.JsonClone();
newAuthorInfo.Metadata = _author.Metadata.Value.JsonClone();
newAuthorInfo.Books = _remoteBooks;
GivenNewArtistInfo(newArtistInfo);
GivenAlbumsForRefresh(_albums);
AllowArtistUpdate();
GivenNewAuthorInfo(newAuthorInfo);
GivenBooksForRefresh(_books);
AllowAuthorUpdate();
Subject.Execute(new RefreshAuthorCommand(_artist.Id));
Subject.Execute(new RefreshAuthorCommand(_author.Id));
VerifyEventNotPublished<AuthorUpdatedEvent>();
VerifyEventPublished<AuthorRefreshCompleteEvent>();
}
[Test]
public void should_publish_artist_updated_event_if_metadata_updated()
public void should_publish_author_updated_event_if_metadata_updated()
{
var newArtistInfo = _artist.JsonClone();
newArtistInfo.Metadata = _artist.Metadata.Value.JsonClone();
newArtistInfo.Metadata.Value.Images = new List<MediaCover.MediaCover>
var newAuthorInfo = _author.JsonClone();
newAuthorInfo.Metadata = _author.Metadata.Value.JsonClone();
newAuthorInfo.Metadata.Value.Images = new List<MediaCover.MediaCover>
{
new MediaCover.MediaCover(MediaCover.MediaCoverTypes.Logo, "dummy")
};
newArtistInfo.Books = _remoteBooks;
newAuthorInfo.Books = _remoteBooks;
GivenNewArtistInfo(newArtistInfo);
GivenAlbumsForRefresh(new List<Book>());
AllowArtistUpdate();
GivenNewAuthorInfo(newAuthorInfo);
GivenBooksForRefresh(new List<Book>());
AllowAuthorUpdate();
Subject.Execute(new RefreshAuthorCommand(_artist.Id));
Subject.Execute(new RefreshAuthorCommand(_author.Id));
VerifyEventPublished<AuthorUpdatedEvent>();
VerifyEventPublished<AuthorRefreshCompleteEvent>();
}
[Test]
public void should_log_error_and_delete_if_musicbrainz_id_not_found_and_artist_has_no_files()
public void should_log_error_and_delete_if_musicbrainz_id_not_found_and_author_has_no_files()
{
Mocker.GetMock<IAuthorService>()
.Setup(x => x.DeleteAuthor(It.IsAny<int>(), It.IsAny<bool>(), It.IsAny<bool>()));
Subject.Execute(new RefreshAuthorCommand(_artist.Id));
Subject.Execute(new RefreshAuthorCommand(_author.Id));
Mocker.GetMock<IAuthorService>()
.Verify(v => v.UpdateAuthor(It.IsAny<Author>()), Times.Never());
@@ -170,12 +170,12 @@ namespace NzbDrone.Core.Test.MusicTests
}
[Test]
public void should_log_error_but_not_delete_if_musicbrainz_id_not_found_and_artist_has_files()
public void should_log_error_but_not_delete_if_musicbrainz_id_not_found_and_author_has_files()
{
GivenArtistFiles();
GivenAlbumsForRefresh(new List<Book>());
GivenAuthorFiles();
GivenBooksForRefresh(new List<Book>());
Subject.Execute(new RefreshAuthorCommand(_artist.Id));
Subject.Execute(new RefreshAuthorCommand(_author.Id));
Mocker.GetMock<IAuthorService>()
.Verify(v => v.UpdateAuthor(It.IsAny<Author>()), Times.Never());
@@ -189,21 +189,21 @@ namespace NzbDrone.Core.Test.MusicTests
[Test]
public void should_update_if_musicbrainz_id_changed_and_no_clash()
{
var newArtistInfo = _artist.JsonClone();
newArtistInfo.Metadata = _artist.Metadata.Value.JsonClone();
newArtistInfo.Books = _remoteBooks;
newArtistInfo.ForeignAuthorId = _artist.ForeignAuthorId + 1;
newArtistInfo.Metadata.Value.Id = 100;
var newAuthorInfo = _author.JsonClone();
newAuthorInfo.Metadata = _author.Metadata.Value.JsonClone();
newAuthorInfo.Books = _remoteBooks;
newAuthorInfo.ForeignAuthorId = _author.ForeignAuthorId + 1;
newAuthorInfo.Metadata.Value.Id = 100;
GivenNewArtistInfo(newArtistInfo);
GivenNewAuthorInfo(newAuthorInfo);
var seq = new MockSequence();
Mocker.GetMock<IAuthorService>(MockBehavior.Strict)
.Setup(x => x.FindById(newArtistInfo.ForeignAuthorId))
.Setup(x => x.FindById(newAuthorInfo.ForeignAuthorId))
.Returns(default(Author));
// Make sure that the artist is updated before we refresh the albums
// Make sure that the author is updated before we refresh the books
Mocker.GetMock<IAuthorService>(MockBehavior.Strict)
.InSequence(seq)
.Setup(x => x.UpdateAuthor(It.IsAny<Author>()))
@@ -220,19 +220,19 @@ namespace NzbDrone.Core.Test.MusicTests
.Setup(x => x.UpdateAuthor(It.IsAny<Author>()))
.Returns((Author a) => a);
Subject.Execute(new RefreshAuthorCommand(_artist.Id));
Subject.Execute(new RefreshAuthorCommand(_author.Id));
Mocker.GetMock<IAuthorService>()
.Verify(v => v.UpdateAuthor(It.Is<Author>(s => s.AuthorMetadataId == 100 && s.ForeignAuthorId == newArtistInfo.ForeignAuthorId)),
.Verify(v => v.UpdateAuthor(It.Is<Author>(s => s.AuthorMetadataId == 100 && s.ForeignAuthorId == newAuthorInfo.ForeignAuthorId)),
Times.Exactly(2));
}
[Test]
public void should_merge_if_musicbrainz_id_changed_and_new_id_already_exists()
{
var existing = _artist;
var existing = _author;
var clash = _artist.JsonClone();
var clash = _author.JsonClone();
clash.Id = 100;
clash.Metadata = existing.Metadata.Value.JsonClone();
clash.Metadata.Value.Id = 101;
@@ -242,19 +242,19 @@ namespace NzbDrone.Core.Test.MusicTests
.Setup(x => x.FindById(clash.Metadata.Value.ForeignAuthorId))
.Returns(clash);
var newArtistInfo = clash.JsonClone();
newArtistInfo.Metadata = clash.Metadata.Value.JsonClone();
newArtistInfo.Books = _remoteBooks;
var newAuthorInfo = clash.JsonClone();
newAuthorInfo.Metadata = clash.Metadata.Value.JsonClone();
newAuthorInfo.Books = _remoteBooks;
GivenNewArtistInfo(newArtistInfo);
GivenNewAuthorInfo(newAuthorInfo);
var seq = new MockSequence();
// Make sure that the artist is updated before we refresh the albums
// Make sure that the author is updated before we refresh the books
Mocker.GetMock<IBookService>(MockBehavior.Strict)
.InSequence(seq)
.Setup(x => x.GetBooksByAuthor(existing.Id))
.Returns(_albums);
.Returns(_books);
Mocker.GetMock<IBookService>(MockBehavior.Strict)
.InSequence(seq)
@@ -272,7 +272,7 @@ namespace NzbDrone.Core.Test.MusicTests
Mocker.GetMock<IBookService>(MockBehavior.Strict)
.InSequence(seq)
.Setup(x => x.GetBooksForRefresh(clash.AuthorMetadataId, It.IsAny<IEnumerable<string>>()))
.Returns(_albums);
.Returns(_books);
// Update called twice for a move/merge
Mocker.GetMock<IAuthorService>(MockBehavior.Strict)
@@ -280,9 +280,9 @@ namespace NzbDrone.Core.Test.MusicTests
.Setup(x => x.UpdateAuthor(It.IsAny<Author>()))
.Returns((Author a) => a);
Subject.Execute(new RefreshAuthorCommand(_artist.Id));
Subject.Execute(new RefreshAuthorCommand(_author.Id));
// the retained artist gets updated
// the retained author gets updated
Mocker.GetMock<IAuthorService>()
.Verify(v => v.UpdateAuthor(It.Is<Author>(s => s.Id == clash.Id)), Times.Exactly(2));
@@ -291,7 +291,7 @@ namespace NzbDrone.Core.Test.MusicTests
.Verify(v => v.DeleteAuthor(existing.Id, false, false));
Mocker.GetMock<IBookService>()
.Verify(v => v.UpdateMany(It.Is<List<Book>>(x => x.Count == _albums.Count)));
.Verify(v => v.UpdateMany(It.Is<List<Book>>(x => x.Count == _books.Count)));
ExceptionVerification.ExpectedWarns(1);
}