From 5fed3670c83ad5a8de9031968f91a2537687487c Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sun, 16 Nov 2014 19:48:27 +0100 Subject: [PATCH] Drone factory would throw exception on unknown series instead of proper error. --- .../DownloadedEpisodesImportServiceFixture.cs | 15 +++++++++++++++ .../MediaFiles/DownloadedEpisodesImportService.cs | 2 +- .../MediaFiles/EpisodeImport/ImportResult.cs | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs index 3b4cb2994..84067408b 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs @@ -16,6 +16,7 @@ using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; using NzbDrone.Test.Common; +using FluentAssertions; namespace NzbDrone.Core.Test.MediaFiles { @@ -195,6 +196,20 @@ public void should_remove_unpack_from_folder_name(string prefix) .Verify(v => v.GetSeries(It.Is(s => s.StartsWith(prefix))), Times.Never()); } + [Test] + public void should_return_importresult_on_unknown_series() + { + var fileName = @"C:\folder\file.mkv".AsOsAgnostic(); + + var result = Subject.ProcessFile(new FileInfo(fileName)); + + result.Should().HaveCount(1); + result.First().ImportDecision.Should().NotBeNull(); + result.First().ImportDecision.LocalEpisode.Should().NotBeNull(); + result.First().ImportDecision.LocalEpisode.Path.Should().Be(fileName); + result.First().Result.Should().Be(ImportResultType.Rejected); + } + private void VerifyNoImport() { Mocker.GetMock().Verify(c => c.Import(It.IsAny>(), true, null), diff --git a/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs b/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs index 1d12c02ca..aa31febb9 100644 --- a/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs @@ -132,7 +132,7 @@ public List ProcessFile(FileInfo fileInfo, DownloadClientItem down if (series == null) { _logger.Debug("Unknown Series for file: {0}", fileInfo.Name); - return new List() { new ImportResult(null, String.Format("Unknown Series for file: {0}", fileInfo.Name)) }; + return new List() { new ImportResult(new ImportDecision(new LocalEpisode { Path = fileInfo.FullName }, "Unknown Series"), String.Format("Unknown Series for file: {0}", fileInfo.Name)) }; } if (_diskProvider.IsFileLocked(fileInfo.FullName)) diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportResult.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportResult.cs index ef146ed3f..6723a1e29 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportResult.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportResult.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Common; +using NzbDrone.Common.EnsureThat; namespace NzbDrone.Core.MediaFiles.EpisodeImport { @@ -27,6 +28,8 @@ public ImportResultType Result public ImportResult(ImportDecision importDecision, params String[] errors) { + Ensure.That(importDecision, () => importDecision).IsNotNull(); + ImportDecision = importDecision; Errors = errors.ToList(); }