Fix: consider download completed if all remote episodes are imported

This commit is contained in:
Keivan Beigi 2014-12-22 11:25:23 -08:00
parent 2193e34537
commit 4ac9fd939a
2 changed files with 40 additions and 6 deletions

View File

@ -181,8 +181,14 @@ namespace NzbDrone.Core.Test.Download
} }
[Test] [Test]
public void should_not_mark_as_imported_if_some_files_were_skipped() public void should_mark_as_imported_if_all_episodes_were_imported_but_extra_files_were_not()
{ {
_trackedDownload.RemoteEpisode.Episodes = new List<Episode>
{
new Episode()
};
Mocker.GetMock<IDownloadedEpisodesImportService>() Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<DownloadClientItem>())) .Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult> .Returns(new List<ImportResult>
@ -192,6 +198,31 @@ namespace NzbDrone.Core.Test.Download
}); });
Subject.Process(_trackedDownload);
AssertCompletedDownload();
}
[Test]
public void should_mark_as_failed_if_some_of_episodes_were_not_imported()
{
_trackedDownload.RemoteEpisode.Episodes = new List<Episode>
{
new Episode(),
new Episode(),
new Episode()
};
Mocker.GetMock<IDownloadedEpisodesImportService>()
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv"})),
new ImportResult(new ImportDecision(new LocalEpisode{Path = @"C:\TestPath\Droned.S01E01.mkv"}),"Test Failure"),
new ImportResult(new ImportDecision(new LocalEpisode{Path = @"C:\TestPath\Droned.S01E01.mkv"}),"Test Failure")
});
Subject.Process(_trackedDownload); Subject.Process(_trackedDownload);
AssertNoCompletedDownload(); AssertNoCompletedDownload();

View File

@ -79,6 +79,13 @@ namespace NzbDrone.Core.Download
return; return;
} }
if (importResults.Count(c => c.Result == ImportResultType.Imported) >= trackedDownload.RemoteEpisode.Episodes.Count)
{
trackedDownload.State = TrackedDownloadStage.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
return;
}
if (importResults.Any(c => c.Result != ImportResultType.Imported)) if (importResults.Any(c => c.Result != ImportResultType.Imported))
{ {
var statusMessages = importResults var statusMessages = importResults
@ -87,12 +94,8 @@ namespace NzbDrone.Core.Download
.ToArray(); .ToArray();
trackedDownload.Warn(statusMessages); trackedDownload.Warn(statusMessages);
return;
} }
trackedDownload.State = TrackedDownloadStage.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
} }
} }
} }