mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-21 23:32:27 +00:00
Fixed: Ensure ImportResults is not empty when verifying imports (#2746)
This commit is contained in:
parent
d27b062d6a
commit
9ee585a472
2 changed files with 37 additions and 1 deletions
|
@ -383,6 +383,42 @@ public void should_mark_as_imported_if_the_download_can_be_tracked_using_the_sou
|
|||
AssertImported();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_mark_as_imported_if_nothing_was_imported()
|
||||
{
|
||||
_trackedDownload.RemoteAlbum.Albums = new List<Album>
|
||||
{
|
||||
CreateAlbum(1, 1)
|
||||
};
|
||||
|
||||
Mocker.GetMock<IDownloadedTracksImportService>()
|
||||
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Artist>(), It.IsAny<DownloadClientItem>()))
|
||||
.Returns(new List<ImportResult>());
|
||||
|
||||
var history = Builder<EntityHistory>.CreateListOfSize(2)
|
||||
.BuildList();
|
||||
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||
.Returns(history);
|
||||
|
||||
Mocker.GetMock<ITrackedDownloadAlreadyImported>()
|
||||
.Setup(s => s.IsImported(_trackedDownload, history))
|
||||
.Returns(true);
|
||||
|
||||
Subject.Import(_trackedDownload);
|
||||
|
||||
AssertImportPending();
|
||||
}
|
||||
|
||||
private void AssertImportPending()
|
||||
{
|
||||
Mocker.GetMock<IEventAggregator>()
|
||||
.Verify(v => v.PublishEvent(It.IsAny<DownloadCompletedEvent>()), Times.Never());
|
||||
|
||||
_trackedDownload.State.Should().Be(TrackedDownloadState.ImportPending);
|
||||
}
|
||||
|
||||
private void AssertNotImported()
|
||||
{
|
||||
Mocker.GetMock<IEventAggregator>()
|
||||
|
|
|
@ -166,7 +166,7 @@ public void Import(TrackedDownload trackedDownload)
|
|||
|
||||
public bool VerifyImport(TrackedDownload trackedDownload, List<ImportResult> importResults)
|
||||
{
|
||||
var allTracksImported = importResults.All(c => c.Result == ImportResultType.Imported) ||
|
||||
var allTracksImported = (importResults.Any() && importResults.All(c => c.Result == ImportResultType.Imported)) ||
|
||||
importResults.Count(c => c.Result == ImportResultType.Imported) >=
|
||||
Math.Max(1, trackedDownload.RemoteAlbum.Albums.Sum(x => x.AlbumReleases.Value.Where(y => y.Monitored).Sum(z => z.TrackCount)));
|
||||
|
||||
|
|
Loading…
Reference in a new issue