From 487ad01a0eed6f14a5d7f08a61d7c79ddc1a3ff6 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 9 Jun 2013 00:14:38 -0700 Subject: [PATCH] only publish import event if an episode is actually imported. --- .../DropFolderImportServiceFixture.cs | 27 ++++++++++++++++++- .../DownloadedEpisodesImportService.cs | 5 ++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/DropFolderImportServiceFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/DropFolderImportServiceFixture.cs index 1ad44dfd4..488e73003 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/DropFolderImportServiceFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/DropFolderImportServiceFixture.cs @@ -6,9 +6,9 @@ using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Tv; -using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests @@ -95,6 +95,18 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests Mocker.GetMock().Verify(c => c.MoveEpisodeFile(_fakeEpisodeFile, true), Times.Once()); } + [Test] + public void should_trigger_import_event_on_import() + { + Mocker.GetMock().Setup(c => c.ImportFile(It.IsAny(), It.IsAny())) + .Returns(_fakeEpisodeFile); + + Subject.ProcessDownloadedEpisodesFolder(); + + VerifyEventPublished(); + + } + [Test] public void should_not_attempt_move_if_nothing_is_imported() { @@ -106,6 +118,19 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests Mocker.GetMock().Verify(c => c.MoveEpisodeFile(It.IsAny(), It.IsAny()), Times.Never()); } + + [Test] + public void should_not_publish_import_event_if_nothing_is_imported() + { + Mocker.GetMock().Setup(c => c.ImportFile(It.IsAny(), It.IsAny())) + .Returns(null); + + Subject.ProcessDownloadedEpisodesFolder(); + + + VerifyEventNotPublished(); + } + [Test] public void should_skip_if_folder_is_in_use_by_another_process() { diff --git a/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs b/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs index 6b956f0db..42e6c54fd 100644 --- a/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs +++ b/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs @@ -117,7 +117,7 @@ namespace NzbDrone.Core.MediaFiles } } - public void ProcessVideoFile(string videoFile, Series series) + private void ProcessVideoFile(string videoFile, Series series) { var lastWrite = _diskProvider.GetLastFileWrite(videoFile); @@ -138,9 +138,8 @@ namespace NzbDrone.Core.MediaFiles if (episodeFile != null) { _episodeFileMover.MoveEpisodeFile(episodeFile, true); + _messageAggregator.PublishEvent(new EpisodeImportedEvent(episodeFile)); } - - _messageAggregator.PublishEvent(new EpisodeImportedEvent(episodeFile)); } public void Execute(DownloadedEpisodesScanCommand message)