Fixed: Edge case where import fails due to DB relationship mismatch

Signed-off-by: Robin Dadswell <robin@dadswell.email>
This commit is contained in:
Qstick
2020-09-06 22:40:17 -04:00
committed by nitsua
parent 2d28359627
commit ec0fc6f3e1
2 changed files with 14 additions and 15 deletions

View File

@@ -96,17 +96,8 @@ public void should_be_reject_if_file_size_is_the_same()
[Test]
public void should_be_accepted_if_file_cannot_be_fetched()
{
_localTrack.Book = (Book)Builder<Book>.CreateListOfSize(1)
.TheFirst(1)
.With(e => e.Id = 1)
.With(e => e.BookFiles = new LazyLoaded<List<BookFile>>(
new List<BookFile>
{
new BookFile
{
Path = null
}
}))
_localTrack.Book = Builder<Book>.CreateNew()
.With(e => e.BookFiles = new LazyLoaded<List<BookFile>>((List<BookFile>)null))
.Build();
Subject.IsSatisfiedBy(_localTrack, null).Accepted.Should().BeTrue();

View File

@@ -15,9 +15,9 @@ public SameFileSpecification(Logger logger)
_logger = logger;
}
public Decision IsSatisfiedBy(LocalBook item, DownloadClientItem downloadClientItem)
public Decision IsSatisfiedBy(LocalBook localBook, DownloadClientItem downloadClientItem)
{
var bookFiles = item.Book?.BookFiles?.Value;
var bookFiles = localBook.Book?.BookFiles?.Value;
if (bookFiles == null || !bookFiles.Any())
{
@@ -27,9 +27,17 @@ public Decision IsSatisfiedBy(LocalBook item, DownloadClientItem downloadClientI
foreach (var bookFile in bookFiles)
{
if (bookFile.Size == item.Size)
if (bookFile == null)
{
_logger.Debug("'{0}' Has the same filesize as existing file", item.Path);
var book = localBook.Book;
_logger.Trace("Unable to get book file details from the DB. BookId: {0} BookFileId: {1}", book.Id, bookFile.Id);
return Decision.Accept();
}
if (bookFile.Size == localBook.Size)
{
_logger.Debug("'{0}' Has the same filesize as existing file", localBook.Path);
return Decision.Reject("Has the same filesize as existing file");
}
}