only publish import event if an episode is actually imported.

This commit is contained in:
kay.one 2013-06-09 00:14:38 -07:00
parent baab8cd838
commit 487ad01a0e
2 changed files with 28 additions and 4 deletions

View File

@ -6,9 +6,9 @@ using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
@ -95,6 +95,18 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(_fakeEpisodeFile, true), Times.Once()); Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(_fakeEpisodeFile, true), Times.Once());
} }
[Test]
public void should_trigger_import_event_on_import()
{
Mocker.GetMock<IDiskScanService>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
.Returns(_fakeEpisodeFile);
Subject.ProcessDownloadedEpisodesFolder();
VerifyEventPublished<EpisodeImportedEvent>();
}
[Test] [Test]
public void should_not_attempt_move_if_nothing_is_imported() public void should_not_attempt_move_if_nothing_is_imported()
{ {
@ -106,6 +118,19 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<bool>()), Times.Never()); Mocker.GetMock<IMoveEpisodeFiles>().Verify(c => c.MoveEpisodeFile(It.IsAny<EpisodeFile>(), It.IsAny<bool>()), Times.Never());
} }
[Test]
public void should_not_publish_import_event_if_nothing_is_imported()
{
Mocker.GetMock<IDiskScanService>().Setup(c => c.ImportFile(It.IsAny<Series>(), It.IsAny<string>()))
.Returns<EpisodeFile>(null);
Subject.ProcessDownloadedEpisodesFolder();
VerifyEventNotPublished<EpisodeImportedEvent>();
}
[Test] [Test]
public void should_skip_if_folder_is_in_use_by_another_process() public void should_skip_if_folder_is_in_use_by_another_process()
{ {

View File

@ -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); var lastWrite = _diskProvider.GetLastFileWrite(videoFile);
@ -138,9 +138,8 @@ namespace NzbDrone.Core.MediaFiles
if (episodeFile != null) if (episodeFile != null)
{ {
_episodeFileMover.MoveEpisodeFile(episodeFile, true); _episodeFileMover.MoveEpisodeFile(episodeFile, true);
_messageAggregator.PublishEvent(new EpisodeImportedEvent(episodeFile));
} }
_messageAggregator.PublishEvent(new EpisodeImportedEvent(episodeFile));
} }
public void Execute(DownloadedEpisodesScanCommand message) public void Execute(DownloadedEpisodesScanCommand message)