diff --git a/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceFixture.cs index e99ff5968..4818c4748 100644 --- a/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceFixture.cs @@ -24,10 +24,17 @@ namespace NzbDrone.Core.Test.Download public class CompletedDownloadServiceFixture : CoreTest { private TrackedDownload _trackedDownload; + private Episode _episode1; + private Episode _episode2; + private Episode _episode3; [SetUp] public void Setup() { + _episode1 = new Episode { Id = 1, SeasonNumber = 1, EpisodeNumber = 1 }; + _episode2 = new Episode { Id = 2, SeasonNumber = 1, EpisodeNumber = 2 }; + _episode3 = new Episode { Id = 2, SeasonNumber = 1, EpisodeNumber = 3 }; + var completed = Builder.CreateNew() .With(h => h.Status = DownloadItemStatus.Completed) .With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic())) @@ -66,7 +73,9 @@ namespace NzbDrone.Core.Test.Download return new RemoteEpisode { Series = new Series(), - Episodes = new List { new Episode { Id = 1 } } + Episodes = new List { + _episode1 + } }; } @@ -84,7 +93,7 @@ namespace NzbDrone.Core.Test.Download .Setup(v => v.ProcessPath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new List { - new ImportResult(new ImportDecision(new LocalEpisode() { Path = @"C:\TestPath\Droned.S01E01.mkv" })) + new ImportResult(new ImportDecision(new LocalEpisode() { Path = @"C:\TestPath\Droned.S01E01.mkv", Episodes = { _episode1 } })) }); } @@ -170,11 +179,30 @@ namespace NzbDrone.Core.Test.Download { new ImportResult( new ImportDecision( - new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv"})), + new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv", Episodes = { _episode1 }})), new ImportResult( new ImportDecision( - new LocalEpisode {Path = @"C:\TestPath\Droned.S01E02.mkv"})) + new LocalEpisode {Path = @"C:\TestPath\Droned.S01E02.mkv", Episodes = { _episode2 }})) + }); + + Subject.Process(_trackedDownload); + + AssertCompletedDownload(); + } + + [Test] + public void should_mark_as_imported_if_all_multi_episodes_were_imported() + { + _trackedDownload.RemoteEpisode.Episodes.Add(new Episode { Id = 2 }); + + Mocker.GetMock() + .Setup(v => v.ProcessPath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(new List + { + new ImportResult( + new ImportDecision( + new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01E02.mkv", Episodes = { _episode1, _episode2 }})) }); Subject.Process(_trackedDownload); @@ -191,11 +219,11 @@ namespace NzbDrone.Core.Test.Download { new ImportResult( new ImportDecision( - new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv"}, new Rejection("Rejected!")), "Test Failure"), + new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv", Episodes = { _episode1 }}, new Rejection("Rejected!")), "Test Failure"), new ImportResult( new ImportDecision( - new LocalEpisode {Path = @"C:\TestPath\Droned.S01E02.mkv"},new Rejection("Rejected!")), "Test Failure") + new LocalEpisode {Path = @"C:\TestPath\Droned.S01E02.mkv", Episodes = { _episode2 }},new Rejection("Rejected!")), "Test Failure") }); Subject.Process(_trackedDownload); @@ -215,11 +243,11 @@ namespace NzbDrone.Core.Test.Download { new ImportResult( new ImportDecision( - new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv"}, new Rejection("Rejected!")), "Test Failure"), + new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv", Episodes = { _episode1 }}, new Rejection("Rejected!")), "Test Failure"), new ImportResult( new ImportDecision( - new LocalEpisode {Path = @"C:\TestPath\Droned.S01E02.mkv"},new Rejection("Rejected!")), "Test Failure") + new LocalEpisode {Path = @"C:\TestPath\Droned.S01E02.mkv", Episodes = { _episode2 }},new Rejection("Rejected!")), "Test Failure") }); _trackedDownload.RemoteEpisode.Episodes.Clear(); @@ -236,8 +264,8 @@ namespace NzbDrone.Core.Test.Download .Setup(v => v.ProcessPath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new List { - 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") + new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv", Episodes = { _episode1 }}),"Test Failure"), + new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E02.mkv", Episodes = { _episode2 }}),"Test Failure") }); @@ -260,8 +288,8 @@ namespace NzbDrone.Core.Test.Download .Setup(v => v.ProcessPath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new List { - 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", Episodes = { _episode1 }})), + new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E02.mkv", Episodes = { _episode2 }}),"Test Failure") }); Subject.Process(_trackedDownload); @@ -274,18 +302,18 @@ namespace NzbDrone.Core.Test.Download { _trackedDownload.RemoteEpisode.Episodes = new List { - new Episode(), - new Episode(), - new Episode() + _episode1, + _episode2, + _episode3 }; Mocker.GetMock() .Setup(v => v.ProcessPath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new List { - 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") + new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv", Episodes = { _episode1 }})), + new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E02.mkv", Episodes = { _episode2 }}),"Test Failure"), + new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E03.mkv", Episodes = { _episode3 }}),"Test Failure") }); @@ -303,7 +331,7 @@ namespace NzbDrone.Core.Test.Download .Setup(v => v.ProcessPath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new List { - new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv"})) + new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv", Episodes = { _episode1 }})) }); Mocker.GetMock() @@ -324,7 +352,7 @@ namespace NzbDrone.Core.Test.Download .Setup(v => v.ProcessPath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new List { - new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv"})) + new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv", Episodes = { _episode1 }})) }); Mocker.GetMock() @@ -359,7 +387,7 @@ namespace NzbDrone.Core.Test.Download .Setup(v => v.ProcessPath(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(new List { - new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv"})) + new ImportResult(new ImportDecision(new LocalEpisode {Path = @"C:\TestPath\Droned.S01E01.mkv", Episodes = { _episode1 }})) }); Subject.Process(_trackedDownload, true); diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index 0daf23be4..c35d27a82 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -111,7 +111,9 @@ namespace NzbDrone.Core.Download return; } - if (importResults.Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, trackedDownload.RemoteEpisode.Episodes.Count)) + var importedEpisodes = importResults.Where(c => c.Result == ImportResultType.Imported).SelectMany(c => c.ImportDecision.LocalEpisode.Episodes).ToList(); + + if (importedEpisodes.Count() >= Math.Max(1, trackedDownload.RemoteEpisode.Episodes.Count)) { trackedDownload.State = TrackedDownloadStage.Imported; _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));